34 views (last 30 days)
carson yeoh on 24 Jun 2020
Answered: Bjorn Gustavsson on 24 Jun 2020
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power.
Check that the matrix is square and the power is a
scalar. To perform elementwise matrix powers, use '.^'.
I got this when I try to use the equation
Please help me convert them into a function of theta that i can plot as a (theta,x) to test from degree 0 to 360(0 to 2pi). KSSV on 24 Jun 2020
The error is clear....if you have a matrix, A if you want to find the power each element of A, use element by element power
A2 = A.^2
You attach the code, you tried..so you can get help.
carson yeoh on 24 Jun 2020
abc = (r*(wab^2)*(L^2-r^2).*sin(theta))./((L*L-r*r.*sin(theta).*sin(theta))^(3/2));

Bjorn Gustavsson on 24 Jun 2020
When you get such an error, your first action would be to look at the sizes of the variables you use:
whos r wab L r theta
Next you'll have think about whether you want matrix-power or elementwise power (same with products - matrix-product or element-wise product). From your equation it seems as if you want elementwise operations, but we cannot know this with absolute certainty. In that case you'll have to modify your expression to something like this:
abc = (r.*(wab.^2)*(L.^2-r.^2).*sin(theta))./((L.*L-r.*r.*sin(theta).*sin(theta)).^(3/2));
HTH