Problem with Legend command.

1 回表示 (過去 30 日間)
Asir Tushar
Asir Tushar 2017 年 12 月 15 日
コメント済み: Walter Roberson 2017 年 12 月 16 日
syms x
f=log(x);
hold on
T1=taylor(f,'Expansionpoint',2,'order',1)
T2=taylor(f,'Expansionpoint',2,'order',2)
T3=taylor(f,'Expansionpoint',2,'order',3)
T4=taylor(f,'Expansionpoint',2,'order',4)
x=-5:.1:5;
xx=subs(x);
yy1=subs(T1);
plot(xx,yy1,'m');
yy2=subs(T2);
plot(xx,yy2,'r');
yy3=subs(T3);
plot(xx,yy3,'c');
yy4=subs(T4);
plot(xx,yy4,'b');
legend('po(x)','p1(x)','p2(x)','p3(x)')
xlabel('x');
ylabel('y');
grid on
The problem is very silly and i think i am missing something elementary.Why the legend command not giving different colors to the p0,p1,p2,p3 in the image.Any help will be appreciated.

回答 (1 件)

Star Strider
Star Strider 2017 年 12 月 15 日
編集済み: Star Strider 2017 年 12 月 15 日
The problem is the first plot call.
Change it to:
fplot(yy1,[-5 5],'m');
and everything else works.
EDIT
Also, the ‘xx’ assignment is not necessary. Simply delete it and use ‘x’ instead in the rest, or use fplot for the rest, as with the first one.
  2 件のコメント
Asir Tushar
Asir Tushar 2017 年 12 月 16 日
syms x
f=log(x);
hold on
T1=taylor(f,'Expansionpoint',2,'order',1)
T2=taylor(f,'Expansionpoint',2,'order',2)
T3=taylor(f,'Expansionpoint',2,'order',3)
T4=taylor(f,'Expansionpoint',2,'order',4)
x=-5:.1:5;
yy1=subs(T1);
fplot(yy1,[-5 5],'m');
yy2=subs(T2);
fplot(yy2,[-5 5],'r');
yy3=subs(T3);
fplot(yy3,[-5 5],'c');
yy4=subs(T4);
fplot(yy4,[-5 5],'b');
legend('po(x)','p1(x)','p2(x)','p3(x)')
xlabel('x');
ylabel('y');
grid on
i changed it just like you said. but this error pops out. what i am doing wrong this time ?
Error using fcnchk (line 107)
If FUN is a MATLAB object, it must have an feval method.
Error in fplot (line 61)
fun = fcnchk(fun);
Error in taylor (line 13)
fplot(yy1,[-5 5],'m');
Walter Roberson
Walter Roberson 2017 年 12 月 16 日
The first couple of versions that had fplot did not support symbolic variables. You might be using an older release. If so then instead of passing yy to fplot, call matlabFunction on yy and pass the result to fplot

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by