4 views (last 30 days)

I have this exercise:

dx/dt = −x(1 − y), t0 = 0, x(t0) = 0.5,

dy/dt = y(1 − x), t0 = 0, y(t0) = 2

These equations are also known as Lotka-Volterra or predator-prey equations modeling evolution of species as a function of time t. In the equations above variable x stands for the number of predators, and y is the number of prey.

Let [0, 40] be the interval of integration.

Please implement explicit Euler integration scheme with ∆ = 0.001, ∆ = 0.002, and

∆ = 0.005 . Plot the values of x(t), y(t) for t ∈ [0, 40]

I have written this but i am getting an error. (I have divided dy/dt with dx/dt to find dy/dx)

Could someone help me ?

t0=0; %this is the left boundary of the integration interval [0,40]

t1=40 %this is the right boundary of the integration interval [0,40]

y(t0)=2; %this is the initial value of y at t0

x(t0)=0.5; %this is the initial value of x at t0

Delta=0.001; %definition of Delta

x=x0:Delta:x1; %setting up a grid of points in [0,2]

y=y0*ones(1,length(x)); %creating an array for y

if (length(x)>1)

for i=1:length(x)-1

y(i+1)=(y(i)+Delta*(y(i)*(1-x)/((-x)*(1-y(i)))));

end;

plot(x,y); % Finished! Let’s plot the estimates y_k of the solution y(x_k) now

else

disp('Please change the value of Delta');

end;

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

Start Hunting!
## 4 Comments

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800488

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800488

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800507

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800507

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800530

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800530

## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800573

⋮## Direct link to this comment

https://in.mathworks.com/matlabcentral/answers/506831-explicit-euler-integration-plot-x-t-and-y-t#comment_800573

Sign in to comment.