Plotting the ODE without an analytical solution

3 次查看(过去 30 天)
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'})

采纳的回答

Steven Lord
Steven Lord 2020-5-25
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];

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by