Effacer les filtres
Effacer les filtres

Solving differential equations using ODE15s

8 vues (au cours des 30 derniers jours)
KayLynn
KayLynn le 8 Fév 2014
Modifié(e) : Mischa Kim le 9 Fév 2014
Trying to solve four differential equations. Have the following code:
function dy(t,y,k)
%Define initial values of k1, k2,k3,S,P,E and C
k1=.005;
k2=.005;
k3=0.1;
S=100;
P=0;
E=10;
C=0;
y1=k_2 C+k_3 C-k_1 E*S;
y2=k_2 C+K_1 ES;
y3=k_1 E*S-(k_2+k_3)*C;
y4=k_3 C;
y0=[0,0]
[t,y,k]=ode45(t,y,k)
Not sure what syntax I am missing....I get this error:
Error: File: ode15s.m Line: 11 Column: 8 Unexpected MATLAB expression.

Réponses (3)

Azzi Abdelmalek
Azzi Abdelmalek le 8 Fév 2014
Modifié(e) : Azzi Abdelmalek le 8 Fév 2014
I think what you are doing is not correct. Read the documentation,there are many examples there

Jan
Jan le 9 Fév 2014
1. This is not valid Matlab syntax:
y1 = k_2 C+k_3 C-k_1 E*S;
Without an explanation, what this line should achieve, we cannot guess the intention.
2. Neither k1, k2, k3 nor y0 to y4 are used anywhere.
3. The call of the integrator [t,y,k]=ode45(t,y,k) must not appear inside the function to be integrated. So move this line out of the function and type it in the command window or inside another M-file.

Mischa Kim
Mischa Kim le 9 Fév 2014
Modifié(e) : Mischa Kim le 9 Fév 2014
Agreed. Check out the code below. You will have to adapt it since I could not quite read some of the equations.
function myEOM()
[T, Y] = ode45(@EOM, [0 12],[1 2 3 4]);
plot(T, Y(:,1))
end
function dy = EOM(t,y)
%Define initial values of k1, k2,k3,S,P,E and C
k1 = 0.005;
k2 = 0.005;
k3 = 0.1;
S = 100;
P = 0;
E = 10;
C = 0;
y1 = k2 + C + k3*C -k1*E*S;
y2 = k2 + C + k1*E*S;
y3 = k1 + E*S - (k2 + k3)*C;
y4 = k3 + C;
dy = [y1; y2; y3; y4];
end
Essentially, you are working with two different functions. One that contains the ode call, the other one defining the DE. To call the DE function
[T, Y] = ode45(@EOM, [0 12],[1 2 3 4]);
you need to define the time interval ( [0 12] ) and the initial conditions for the yi, here, [1 2 3 4] .
Finally, if you want to use ode15s you need to make the ode call accordingly. Currently you are using ode45.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by