What is the Purpose of Using Arrays in Complex Expressions?

AI Thread Summary
The discussion focuses on the use of arrays in complex mathematical expressions, particularly in the context of homework problems involving matrix operations. The user demonstrates how to replicate arrays using the `repmat` function and encounters issues with matrix dimension compatibility when performing arithmetic operations. The solution involves using element-wise operations by adding a period before arithmetic symbols to ensure proper matrix calculations. The final expression for `fDP` is provided, showing successful computation after correcting the initial errors. Understanding the importance of element-wise operations is crucial for working with arrays in complex expressions.
gfd43tg
Gold Member
Messages
947
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
 
Back
Top