Hazhir aliahmadi
Hazhir aliahmadi

Reputation: 1

How to solve and plot a nonlinear differential equation system?

I have a nonlinear system whose time domain response I want to find according to the initial conditions, and plot that in MATLAB, but I don't know how.

My system is

d/  ⌈x⌉ _ ⌈-x+y*x^2 ⌉
/dt ⌊y⌋ ‾ ⌊   -y    ⌋

The initial condition, [x0;y0], is [2;1].

Regards,

Upvotes: 0

Views: 399

Answers (1)

Robin Tournemenne
Robin Tournemenne

Reputation: 104

I solved your problem using the ode45 function. For example I would write in a file called Main.m:

close all
[tcont,Xcont]=ode45(@eqStac,[0 2.5],[2 ;1],[]);
plot(tcont,Xcont(:,1),'*r');
hold on
plot(tcont,Xcont(:,2),'*');

and then I have to create a function computing your system in the file eqStac.m:

function xpoint=eqStac(t,x)
xpoint(1)=-x(1)+x(2)*x(1)^2;
xpoint(2)=-x(2);
xpoint=xpoint(:);
end

In the end you would have this plot:

x in red and y in blue: x in red and y in blue

I remarked that your system is diverging at about 4.8 seconds.

Upvotes: 1

Related Questions