필터 지우기
필터 지우기

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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by