Plotting the ODE without an analytical solution

3 visualizzazioni (ultimi 30 giorni)
How do I plot the equation
d^2(x)/dt^2=0.002cos(x-t)-sin(x)
where x(0)=0.2 and x'(0)=0 for t=0:100?
I asked the question before, but the graph that was plotted was starting from x(0)=0
the answer I got before was
dfun = @(t, x) [x(2); 0.002*cos(x(1)-t)-sin(x(1))];
time = [0 100];
ic = [0; 0];
[t, x] = ode15s(dfun, time, ic);
plot(t, x);
legend({'x', 'xdot'})

Risposta accettata

Steven Lord
Steven Lord il 25 Mag 2020
If your initial conditions are supposed to be: "where x(0)=0.2 and x'(0)=0 for t=0:100?" why are you specifying them as x(0) = 0 and x'(0) = 0?
ic = [0; 0];
Instead specify your desired initial conditions.
ic = [0.2; 0];

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by