Filter löschen
Filter löschen

Plotting a function defined by a system of ODEs

3 Ansichten (letzte 30 Tage)
Cris19
Cris19 am 7 Jun. 2018
Kommentiert: Cris19 am 7 Jun. 2018
I am trying to solve with MATLAB the first order ODEs system,
$$\left\{
\begin{array}{l}
x_{1}^{\prime }=-\frac{1}{t+1}x_{1}+x_{2} \\
x_{2}^{\prime }=-(1+e^{-2t})x_{1}-\frac{1}{t+1}x_{2}+\frac{e^{-3t}}{t+1}x_{3}
\\
x_{3}^{\prime }=-\frac{1}{t+1}x_{3}+x_{4} \\
x_{4}^{\prime }=e^{-3t}\left( t+1\right) x_{1}-\left( 1+e^{-2t}\right) x_{3}-%
\frac{1}{t+1}x_{4}-\frac{1}{t+1}x_{3}^{2}%
\end{array}%
\right. $$
I've defined the function:
function dzdt=odefun(t,z)
dzdt=zeros(4,1);
dzdt(1)=-(1/(t+1))*z(1)+z(2);
dzdt(2)=-(1+exp(-2*t))*z(1)-(1/(t+1))*z(2)+(exp(-3*t))/(t+1)*z(3);
dzdt(3)=z(4)-(1/(t+1))*z(3);
dzdt(4)=(exp(-3*t))*(t+1)*z(1)-(1+exp(-2*t))*z(3)-(1/(t+1))*z(4)-(1/(t+1))*z(3)^2;
end
The time interval is [0,100] and the initial conditions are z0 = [0.01 0.01 0.01 0.01].
With the ode45 solver, I've used the commands:
>> tspan = [0 100];
>> z0 = [0.01 0.01 0.01 0.01];
>> [t,z] = ode45(@(t,z) odefun(t,z), tspan, z0);
>> plot(t,z(:,1),'r')
and I've obtained easily the graph of z(1)=x_1.
But I want to plot the function f(t)=(t+1)*x_1(t), t\in [0,100], where x_1=z(1) is the first unknown of the system. How could I do this ?

Akzeptierte Antwort

Torsten
Torsten am 7 Jun. 2018
tspan = [0 100];
z0 = [0.01 0.01 0.01 0.01];
[t,z] = ode45(@(t,z) odefun(t,z), tspan, z0);
z1 = (t+1).*z(:,1);
plot(t,z1)
Best wishes
Torsten.

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