Writing differential equation for plot

9 Ansichten (letzte 30 Tage)
vaibhav gupta
vaibhav gupta am 5 Dez. 2020
Kommentiert: vaibhav gupta am 6 Dez. 2020
Can anyone help me how to write differential below equation for plot
d2x/dt2 = -sign(x + dx/dt)
I tried in below way and it is failing
ode = diff(x,t,2) == -sign(x + diff(x,t));

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 5 Dez. 2020
Try this
syms x(t)
d1x = diff(x);
d2x = diff(x,2);
ode = d2x == -sign(x + d1x);
cond = [x(0)==1 d1x(0)==0]
sol = dsolve(ode, cond)
This requires the Symbolic Math toolbox.
  5 Kommentare
Ameer Hamza
Ameer Hamza am 6 Dez. 2020
fplot() is used when you want to plot a function handle or s symbolic function. On the other hand, plot() requires x, y data points. To use the plot() function here, you will need to define an x vector and calculate the y-values yourself. fplot() take cares of all these calculations
syms x(t)
d1x = diff(x);
d2x = diff(x,2);
ode = d2x == -sign(x + d1x);
cond = [x(0)==1 d1x(0)==0];
sol = dsolve(ode, cond);
xv = linspace(-5, 5);
yv = subs(sol, t, xv);
plot(xv, yv);
vaibhav gupta
vaibhav gupta am 6 Dez. 2020
Thank you for explaining difference. If i want to use ode45 function, how can i do that?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by