MATLAB Answers

If you follow this code, you will see a graph, but when you hit enter, line 45 keeps saying "'l' is an unrecognizable function or variable." But even though for I= 2:k is given, what is the problem?? ?

1 view (last 30 days)
SUNGJIN KIM
SUNGJIN KIM on 1 Nov 2020
Edited: Walter Roberson on 1 Nov 2020
Hf_fig = figure;
phi = 0: 15: 90;
heel = pi*phi/180;
B = 6.480;
T = [ 1.729 1.575 1.163 0.600 -0.012 -0.693 -1.354 ];
w = [ 0 1.122 1.979 2.595 2.945 2.874 2.539 ];
KB = [ 1.272 1.121 0.711 0.107 -0.625 -1.393 -2.108 ];
KM = [ 4.596 3.711 2.857 1.830 0.479 -0.869 -1.471 ];
set(Hf_fig, 'NumberTitle', 'off',...
'Name', 'B and M curves');
clf
x = -T.* sin(heel); y = T.*cos(heel) ; k = length(heel);
Bcenter(1,:) = [0 KB(1)];
M = zeros(2,k);
M(:,1) = [0 KB(1)];
f = max((B/0.8), (B^2/(12*T(1))+T(1)/2));
plot(Bcenter(:, 1), M(:, 2), 'b-')
axis([ -f/2 f/2 -T(1)/2 (f-T(1)/2) ])
axis('square')
P1 = [ 0.000; 0.50 ]; P2 = [ 0.240; 0.50 ];
P3 = [ 0.240; 0.58]; P4 = [ 1.100; 1.00 ]; P5 = [ 1.787; 1.25 ];
P6 = [ 2.460; 1.50 ]; P7 = [ 2.902; 1.75 ]; P8 = [ 3.100; 2.00 ];
P9 = [ 3.176; 2.25 ]; P10 = [ 3.200; 2.50 ]; P11 = [ 3.218; 2.75 ];
P12 = [ 3.230; 3.00 ]; P13 = [ 3.230; 3.36 ]; P14 = [ 2.099; 3.425 ];
P15 = [ 0.000; 3.489 ];
starb = [ P1 P2 P3 P4 P5 P6 P7 P8 P9 P10 P11 P12 P14 P15 ];
port = [ -starb(1, :); starb(2, :) ];
port = fliplr(port);
hold on
text(-B/1.8, T(1)+0.25, 'W_0')
text( B/1.8, T(1)+0.25, 'L_0')
text(-B/13, KB(1), 'B') , text(0, KM(1)+0.3, 'M')
xl = x(1) - B/1.5; yl = y(1); xr = x(1) + B/(1.8-1/10);
yr = y(1);
plot([ xl xr ], [ yl yr ])
plot(0, KB(1), 'r*')
plot(0, KM(1), 'ko')
plot([ 0 0 ], [ KB(1) KM(1) ], 'c-.')
pause
for I = 2:k
xl = x(l) - B*cos(heel(l))/(1.5+l/1.7);
yl = y(l) - B*sin(heel(l))/(1.5+l/1.7);
xr = x(l) + B*cos(heel(l))/(1.8-l/10);
yr = y(l) + B*sin(heel(l))/(1.8-l/10);
plot([ xl xr ], [ yl yr ])
if l ~= 1
string = [ num2str(phi(l)) '^o' ];
text(xl, yl, string)
text(xr, yr, string)
end
Bcenter(:, l) = rotate(heel(l))*[ w(l); KB(l) ];
plot(Bcenter(1, l), Bcenter(2, l), 'r*')
M(:, l) = rotate(heel(l))*[ w(l); KM(l) ];
plot(M(1, l), M(2, l), 'ko')
plot([ Bcenter(1, l), M(1, l) ], [ Bcenter(2, l), M(2, l) ],...
'k--')
pause(1)
end
pause
Bx = 0: Bcenter(1, k)/50: Bcenter(1, k); % interpolation axis
By = spline(Bcenter(1, :), Bcenter(2, :), Bx);
plot(Bx, By, 'm-')
Mx = 0: M(1, k)/50: M(1, k);
My = spline(M(1, :), M(2, :), Mx);
plot(Mx, My, 'y-') , text(-B/1.5, 1.4*KM(1),...
'The M-curve is the evolute of the B-curve')
hold off
function r = rotate(phi)
r = [ cos(phi) -sin(phi); sin(phi) cos(phi) ];
end
  1 Comment
Walter Roberson
Walter Roberson on 1 Nov 2020
Does your font permit you to distinguish between capital-i and lower case L?
It is recommended that you do not use variable names that are easily mistaken, being cautious on using I, l, 1, O, 0

Sign in to comment.

Answers (1)

Mara
Mara on 1 Nov 2020
Your loop variable is a an upper case i, but in your loop you use a lower case l, which look identical in some fonts.

Community Treasure Hunt

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

Start Hunting!