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);

Antworten (2)

madhan ravi
madhan ravi am 9 Okt. 2018
Bearbeitet: madhan ravi am 9 Okt. 2018

0 Stimmen

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 Kommentare

bob bobsson
bob bobsson am 9 Okt. 2018
All I get is a straight line. for gy. for but the other plots seems to be giving a correct line.
madhan ravi
madhan ravi am 9 Okt. 2018
Bearbeitet: madhan ravi am 9 Okt. 2018
did you try my code first? see the attached screenshot , I got all the graphs

Melden Sie sich an, um zu kommentieren.

Walter Roberson
Walter Roberson am 9 Okt. 2018

0 Stimmen

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 Kommentare

bob bobsson
bob bobsson am 9 Okt. 2018
I do not completely follow I just end up with it not properly working.
Walter Roberson
Walter Roberson am 9 Okt. 2018
Your gy is the constant 26 for all x values.

Melden Sie sich an, um zu kommentieren.

Produkte

Tags

Gefragt:

am 9 Okt. 2018

Bearbeitet:

am 16 Okt. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by