Writing a differential equation for iteration using for loop.

9 views (last 30 days)
I have a differential equation:
p=@(t,x,y) (a-x^2-y^2)*x-omega*y;
Why for iteration we write this equation as ?
for i=2:50000
x(i)=x(i-1)+((a-x(i-1)^2-y(i-1)^2)*x(i-1)-omega*y(i-1))*dt;
end

Accepted Answer

Alan Stevens
Alan Stevens on 12 Nov 2020
Edited: Alan Stevens on 12 Nov 2020
This is known as simple Euler integration. It arises from
% dx/dt = (a - x^2 - y^2)*x - omega*y
% Let dx/dt be approximated by (x(t+dt) - x(t))/dt
% and the right hand side by (a - x(t)^2 - y(t)^2)*x(t) - omega*y(t)
% so (x(t+dt) - x(t))/dt = (a - x(t)^2 - y(t)^2)*x(t) - omega*y(t) approximately
% Multiply both sides by dt to get
% x(t+dt) - x(t) = ((a - x(t)^2 - y(t)^2)*x(t) - omega*y(t))*dt
% Add x(t) to both sides to get
% x(t+dt) = x(t) + ((a - x(t)^2 - y(t)^2)*x(t) - omega*y(t))*dt

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!