lambr0 and zeta0 outputting 1x1 answer when I want them to output 1x7 answer, any suggestions?

1 view (last 30 days)
x = [-0.4:0.05:0.4]
x = 1×17
-0.4000 -0.3500 -0.3000 -0.2500 -0.2000 -0.1500 -0.1000 -0.0500 0 0.0500 0.1000 0.1500 0.2000 0.2500 0.3000 0.3500 0.4000
r3 = 0.750
r3 = 0.7500
r4 = 1.031
r4 = 1.0310
a0 = 14.04
a0 = 14.0400
L0 = sqrt((r3^2)+(r4^2)-(2*r3*r4*cosd(90+14.04)))
L0 = 1.4144
del0 = acosd(((r3^2)+(L0^2)-(r4^2))/(2*r3*L0))
del0 = 45.0023
lamb0 = acosd(((r4^2)+(L0^2)-(r3^2))/(2*r4*L0))
lamb0 = 30.9577
L = sqrt((x.^2)+(L0^2)-(2*x*L0*cosd(del0)))
L = 1×17
1.7207 1.6802 1.6403 1.6010 1.5623 1.5242 1.4868 1.4502 1.4144 1.3795 1.3456 1.3127 1.2809 1.2502 1.2209 1.1929 1.1664
lambr0 = acosd(((r4^2)+(L.^2)-(r3^2))/(2*r4.*L))
lambr0 = 28.4908
zeta0 = acosd(((L.^2)+(L0^2)-(x.^2))/(2*L0.*L))
zeta0 = 6.9428

Answers (1)

Steven Lord
Steven Lord on 12 Sep 2023
In addition to using element-wise power (the .^ operator) and element-wise multiplication (the .* operator) you need to use the element-wise division operator ./ instead of the array operator.
x = [-0.4:0.05:0.4];
r3 = 0.750;
r4 = 1.031;
a0 = 14.04;
L0 = sqrt((r3^2)+(r4^2)-(2*r3*r4*cosd(90+14.04)));
del0 = acosd(((r3^2)+(L0^2)-(r4^2))/(2*r3*L0));
lamb0 = acosd(((r4^2)+(L0^2)-(r3^2))/(2*r4*L0));
L = sqrt((x.^2)+(L0^2)-(2*x*L0*cosd(del0)));
lambr0 = acosd(((r4^2)+(L.^2)-(r3^2))./(2*r4.*L)); % Note ./ instead of /
zeta0 = acosd(((L.^2)+(L0^2)-(x.^2))./(2*L0.*L)); % Ditto
whos lambr0 zeta0
Name Size Bytes Class Attributes lambr0 1x17 136 double zeta0 1x17 136 double
I suspect you had a typo in the title of your post where you said you expected a 1-by-7 answer, since x is 1-by-17 and therefore lambr0 and zeta0 should both be 1-by-17 as well.
I didn't add the dot before the / in the equations for del0 or lamb0 because all the variables used there are scalars. In that case, / and ./ behave the same.
x = [1./2, 1/2]
x = 1×2
0.5000 0.5000

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!