What is the Purpose of Using Arrays in Complex Expressions?

Click For Summary
SUMMARY

The discussion focuses on the use of arrays in complex mathematical expressions within MATLAB. Specifically, it addresses the implementation of the repmat function to replicate arrays and the importance of element-wise operations, denoted by the period (.) before arithmetic operators. The user encountered issues with matrix dimension compatibility while attempting to compute a function involving exponential and trigonometric operations on the replicated arrays. The final corrected expression for fDP demonstrates successful execution with the proper use of element-wise operators.

PREREQUISITES
  • Understanding of MATLAB syntax and functions, particularly repmat
  • Knowledge of matrix operations and dimensions in MATLAB
  • Familiarity with element-wise operations in MATLAB, using the period (.) notation
  • Basic comprehension of exponential and trigonometric functions in mathematical expressions
NEXT STEPS
  • Explore advanced MATLAB array manipulation techniques
  • Learn about element-wise operations in MATLAB
  • Study the use of the exp and cos functions in MATLAB
  • Investigate matrix dimension compatibility and error handling in MATLAB
USEFUL FOR

Students and professionals working with MATLAB, particularly those involved in mathematical modeling, data analysis, or engineering applications requiring complex expressions and array manipulations.

gfd43tg
Gold Member
Messages
949
Reaction score
48

Homework Statement


I am working on problem 4 in the PDF attachment now, but I will show my code for 2 and 3 since they are related to 4. The values for 2 and 3 were given in the editor.

Homework Equations


The Attempt at a Solution



2.
Code:
P = [1.6, 4, 2.9, -8];
N = 3;
PextDown = repmat(P,3,1);
EDU>> PextDown

PextDown =

    1.6000    4.0000    2.9000   -8.0000
    1.6000    4.0000    2.9000   -8.0000
    1.6000    4.0000    2.9000   -8.0000

3.
Code:
D = [7.2;-3.1;1.3];
M = 4;
DextAcross = repmat(D,1,4);
EDU>> DextAcross

DextAcross =

    7.2000    7.2000    7.2000    7.2000
   -3.1000   -3.1000   -3.1000   -3.1000
    1.3000    1.3000    1.3000    1.3000

4.
What the heck are they trying to get me to do with this e^(complex stuff) using these arrays?? I don't really even comprehend the question to start this thing. My current thought is that they want something like this
Code:
fDP =(1/(1+DextAcross.^2+PextDown.^2))+exp(-abs(DextAcross)*cos(DextAcross*PextDown));
Error using  / 
Matrix dimensions must agree.
 

Attachments

Last edited:
Physics news on Phys.org
It turns out that you need to put a period (.) before arithmetic operations involving either 2 matrices or a matrix and a scalar.

Code:
fDP = (1./(1+DextAcross.^2+PextDown.^2))+exp(-abs(DextAcross).*cos(DextAcross.*PextDown));

fDP =

    0.0452  506.7186   24.4058    0.0366
    0.5437    0.0846   16.6889    0.0668
    2.0751    0.5974    2.9525    2.0886
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 8 ·
Replies
8
Views
4K
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
11K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
4K