Solving differential equations using ODE15s
11 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(3 个)
Azzi Abdelmalek
2014-2-8
编辑:Azzi Abdelmalek
2014-2-8
I think what you are doing is not correct. Read the documentation,there are many examples there
0 个评论
Jan
2014-2-9
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.
0 个评论
Mischa Kim
2014-2-9
编辑:Mischa Kim
2014-2-9
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!