y1=60;y2=200;y3=120;y4=150;
x1=linspace(0,2*pi,50);
A=2*y1*y2*sin(x1);
B=2*y2*(y1*cos(x1)-y4);
C=y1^2+y2^2+y4^2-2*y1*y4*cos(x1)-y3^2;
D=2*y1*y3*sin(x1);
E=2*y3*(y1*cos(x1)-y4);
F=y2^2-y1^2-y3^2-y4^2+2*y1*y4*cos(x1);
for i=1:50
x(i)=2*atan((A+sqrt(A(i)^2+B(i)^2-C(i)^2))/(B(i)-C(i)));
y(i)=2*atan((D+sqrt(D(i)^2+E(i)^2-F(i)^2))/(B-C))
end
??? end
|
Error: Illegal use of reserved keyword "end".
应该怎样使用end,我最后想输出plot(x1,x(i)),plot(x1,y(i))
你的程序中的错误不是由end造成的,for end的用法就是这样用
问题出在你的x(i)和y(i)的赋值是有问题的,A,B,C,D都是向量,而你x(i)=2*atan((A+sqrt(A(i)^2+B(i)^2-C(i)^2))/(B(i)-C(i)));中把一个向量A和A(i)做运算这肯定是不对的,程序我给你改好了,你测试一下,有问题再讨论
y1=60;y2=200;y3=120;y4=150;
x1=linspace(0,2*pi,50);
A=2*y1*y2*sin(x1);
B=2*y2*(y1*cos(x1)-y4);
C=y1^2+y2^2+y4^2-2*y1*y4*cos(x1)-y3^2;
D=2*y1*y3*sin(x1);
E=2*y3*(y1*cos(x1)-y4);
F=y2^2-y1^2-y3^2-y4^2+2*y1*y4*cos(x1);
for i=1:50
x(i)=2*atan((A(i)+sqrt(A(i)^2+B(i)^2-C(i)^2))/(B(i)-C(i)));
y(i)=2*atan((D(i)+sqrt(D(i)^2+E(i)^2-F(i)^2))/(B(i)-C(i)))
subplot(1, 2, 1)
plot([x1(i),x(i)])
subplot(1, 2, 2)
plot([x1(i),y(i)])
end
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息