No line when trying to plot Matlab
古いコメントを表示
I wanna plot a function in the interval 1-10 using the plot command but I don't get a line inside the box.
Anyone can see what the problem is with the code?
syms x
y = 1 + exp(x).*sin(5*x);
dy = diff(y)
ddy = diff(dy)
x = 0:.004:10;
gy = ddy - 2*dy + 26*y;
plot(x,gy);
回答 (2 件)
madhan ravi
2018 年 10 月 9 日
編集済み: madhan ravi
2018 年 10 月 9 日
syms x
y = 1 + exp(x).*sin(5*x);
dy = diff(y)
ddy = diff(dy)
gy = ddy - 2*dy + 26*y;
fplot(y,[1 10]) % interval 1-10
hold on
fplot(dy,[1 10])
fplot(ddy,[1 10])
fplot(gy,[1 10])
legend('y','dy','ddy','gy')
Remark: Use fplot when using symbolic variable/s
2 件のコメント
bob bobsson
2018 年 10 月 9 日
madhan ravi
2018 年 10 月 9 日
編集済み: madhan ravi
2018 年 10 月 9 日
did you try my code first? see the attached screenshot , I got all the graphs
Walter Roberson
2018 年 10 月 9 日
plot(x, subs(gy));
Consider: if your code had
X = 0
Y = X+3
X = 7
Would you expect the value of Y to suddenly become 10 instead of 3? No! Because you know that the value of the variable X as of the time of execution is copied.
When you
syms X
Then that is
X = sym('X')
Which assigns specific value to the variable, namely s reference to a symbolic variable. When you use X to construct y then that value is retrieved and used, creating further symbolic expressions. If you then assign a numeric value to X then just like the numeric case that does not go back and change things that used the value of the variable X: they continue to be symbolic expressions referring to a symbolic X rather than to the MATLAB X. So the gy you construct has no connection to the numeric X unless you use subs() to force a connection.
2 件のコメント
bob bobsson
2018 年 10 月 9 日
Walter Roberson
2018 年 10 月 9 日
Your gy is the constant 26 for all x values.
カテゴリ
ヘルプ センター および File Exchange で Common Operations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!