问一下大家为啥出错了,是哪一步出了问题吗。

1 view (last 30 days)
>> x=-pi:pi/100:pi;
y1=cos(1.*(1./cos(x)));
y2=cos(2.*(1./cos(x)));
y3=cos(3.*(1./cos(x)));
y4=cos(4.*(1./cos(x)));
y5=cos(5.*(1./cos(x)));
plot(x,y1,x,y2,x,y3,x,y4,x,y5);
legend('m=1','m=2','m=3','m=4','m=5');
title('Chebyshev');
xlabel('X'),ylabel('Y');
>> grid;
>> x=linspace(-1,1);
>> y=[];
>> for m=1:5
y=[y,cos(m*acos(x))];
end
>> plot(x,y);
Error using plot
Vectors must be the same lengths.
>> legend('m=1','m=2','m=3','m=4','m=5')
>>

Accepted Answer

皇家国际注册开户【微8785092】
仅供参考
x=-pi:pi/100:pi;
y1=cos(1.*(1./cos(x)));
y2=cos(2.*(1./cos(x)));
y3=cos(3.*(1./cos(x)));
y4=cos(4.*(1./cos(x)));
y5=cos(5.*(1./cos(x)));
plot(x,y1,x,y2,x,y3,x,y4,x,y5);
legend('m=1','m=2','m=3','m=4','m=5');
title('Chebyshev');
xlabel('X'),ylabel('Y');
grid;
x=linspace(-1,1);
for m=1:5
    y(m,:)=cos(m*acos(x));
end
plot(x,y);
legend('m=1','m=2','m=3','m=4','m=5')

More Answers (0)

Categories

Find more on 外部语言接口 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!