In this program, it says that I have a parse error at line line 16, disp("L'angle est aigu") but I don't understand where it is coming from.
function w = prog1(u,v);
n = length(u);
m = length(v);
if n != m
disp('Produit scalaire impossible.');
else
v = v / norm(v);
ps = 0;
for i = 1:n
ps = ps + u(i)*v(i);
endfor
disp(["Le produit scalaire est :",num2str(ps)])
angle = acosd(ps/(norm(v)*norm(u)))
disp(["L'angle, en degré, entre les deux vecteurs est :",num2str(angle)])
if angle < 90:
disp("L'angle est aigu")
elseif angle == 90:
disp("L'angle est droit")
else :
disp("L'angle est obtu")
endif
w = ps *v;
endif
endfunction
I tried end, endif, and I believe it is where it should be but it still doens't work. Help me !
The syntax error in your program does not appear to be related to the single quotes in your
dispstatements. It is because of the unnecessary:at the end of yourif,elseif, andelsestatements. Remove those, and your function should work:If the single quote inside the double quoted string was an issue, you could use the
\'escape sequence, but it does not seem to be an issue here. E.g., changing:disp("L'angle est aigu")to
disp("L\'angle est aigu")in all of the
displines, you get the same output: