フィルターのクリア

Plotting a function defined by a system of ODEs

3 ビュー (過去 30 日間)
Cris19
Cris19 2018 年 6 月 7 日
コメント済み: Cris19 2018 年 6 月 7 日
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 ?

採用された回答

Torsten
Torsten 2018 年 6 月 7 日
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.
  1 件のコメント
Cris19
Cris19 2018 年 6 月 7 日
Thank you, Torsten! Best wishes, Cris

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by