Filter löschen
Filter löschen

How to solve coupled first order ODE using something other than ODE45?

1 Ansicht (letzte 30 Tage)
I have 6 coupled equations:
  1. m1'=-m1+a/(1+p3)^n+a0
  2. m2'=-m2+a/(1+p1)^n+a0
  3. m3'=-m3+a/(1+p2)^n+a0
  4. p1'=-b(p1-m1)
  5. p2'=-b(p2-m2)
  6. p3'=-b(p3-m3)
{a, a0, b and n are parameters. m1' is showing derivative of m1 with respect to t (time).}
I know these equations can easily be solved using ODE45 but I want to solve them using something more basic like Euler method. I can solve uncoupled ODEs using Euler method but for coupled equation I am little confused. Someone please give me or give me some ideas and hints to solve these equations. Thank you.

Antworten (1)

John D'Errico
John D'Errico am 22 Apr. 2017
Bearbeitet: John D'Errico am 22 Apr. 2017
What is the problem? If you understand how to solve an ODE using Euler's method, all you need to do is use the current value of your variables to predict ahead. If you have two or more variables, it still works the same. WTP?
Thus, if you have
y' = f(t,y)
then you predict ahead at time step t(k) to step t(k+1) as:
y(k+1) = y(k) + f(t(k),y(k))*dt
If you have multiple coupled equations, then each of them is still of the same form. Euler's method is about as simple as you can make it. It is not very good, since it is just Euler's method! But then, you are the one who wants to use it instead of something better. (This is rarely a good idea, unless you know enough to fully understand the problems and how to recognize them, as well as to know if you can afford to use a poor method. If you can't figure out how to code Euler's method, then you don't understand the issues.)
  2 Kommentare
Luqman Saleem
Luqman Saleem am 22 Apr. 2017
Bearbeitet: Luqman Saleem am 22 Apr. 2017
Thanks. I was too stupid to ask this question. I have written following code but it's not giving me expected results (all the variables (m1,m2,m3,p1,p2,p3) are expected to oscillate but this code is showing that most of them are just becoming zero after some repetition in for loop). where am I going wrong? Thanks again.
dt=0.1; %step
N=10; %total size
gridd=0:dt:N; %diving them
%---------allocating memeory to variables----
m1=zeros(1,length(gridd));
m2=zeros(1,length(gridd));
m3=zeros(1,length(gridd));
p1=zeros(1,length(gridd));
p2=zeros(1,length(gridd));
p3=zeros(1,length(gridd));
%---------intial conditions-------
m1(1)=0;
m2(1)=0;
m3(1)=0;
p1(1)=5;
p2(1)=2;
p3(1)=3;
%-----------parameters--------
a=1000;
a0=1;
n=1.75;
b=5;
%------euler method------
for i=1:length(gridd)-1
m1(i+1)=(-m1(i)+a/(1-p3(i)^n)+a0)*dt+m1(i);
m2(i+1)=(-m2(i)+a/(1-p1(i)^n)+a0)*dt+m2(i);
m2(i+1)=(-m2(i)+a/(1-p2(i)^n)+a0)*dt+m3(i);
p1(i+1)=(-b*(p1(i)-m1(i))*dt)+p1(i);
p2(i+1)=(-b*(p2(i)-m2(i))*dt)+p2(i);
p3(i+1)=(-b*(p3(i)-m3(i))*dt)+p3(i);
end
shireesha myadari
shireesha myadari am 25 Feb. 2021
I am not understanding ,how to make coupling between the given equations.
Thanks in advance.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by