フィルターのクリア

Error: Too many functions when plotting series

9 ビュー (過去 30 日間)
Jordi van Selm
Jordi van Selm 2022 年 12 月 4 日
回答済み: Walter Roberson 2022 年 12 月 4 日
x=[0:pi/100:2*pi];
figure;
syms k;
syms f(x);
S1 = symsum((1/k)*sin(k*x),k,1,Inf);
S2 = symsum((1/(2*k-1))*sin((2*k-1)*x),k,1,Inf);
fplot(x,S1,x,S2);
Error using fplot
Too many functions.
xlabel('x')
ylabel('y')
I get this error when I'm trying to plot two series, what did I do wrong?
And how to properly apply the domain from 0 to 2pi ?

採用された回答

Walter Roberson
Walter Roberson 2022 年 12 月 4 日
x=[0:pi/100:2*pi];
That creates a numeric x in steps of
syms f(x);
That is equivalent to
syms x
f = symfun('f(x)', x)
which has the side effect of overwriting x with a symbolic variable.
fplot(x,S1,x,S2);
fplot does not accept x, y pairs at all. If you want to plot multiple functions, put the functions into a vector, as the first parameter. The second parameter, if provided, must be the lower and upper bound to plot over.
fplot([S1, S2], [lower_bound, upper_bound])
Note that at this point, x is the symbolic x, since you overwrote the numeric x with symbolic x.
You should be using
xrange = [0, 2*pi];
syms k;
syms f(x);
S1 = symsum((1/k)*sin(k*x),k,1,Inf);
S2 = symsum((1/(2*k-1))*sin((2*k-1)*x),k,1,Inf);
fplot([S1,S2], xrange);
xlabel('x')
ylabel('y')
OR you can subs() particular numeric x values into S1 and S2 and use plot()

その他の回答 (1 件)

Rik
Rik 2022 年 12 月 4 日
I suspect this will do what you want:
fplot(x,S1);
hold on
fplot(x,S2)
hold off

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by