Defining ODE function as function file
이전 댓글 표시
Hi everybody
I wrote a code of first order ODE but it doesn't work, how could I fix it? Could you help me please? Additionally I need to draw a graph of these three value in one graph. The code is given below.
Also I get Errors:
Error using ConcentrationsofXYZ>ConcC
Too many input arguments.
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ConcentrationsofXYZ (line 17)
[t,Z] = ode45(@ConcC,tspan,X0,Y0,Z0);
clear all;
clc;
close all;
X0=1;
tspan = [0 24];
[t,X] = ode45(@ConcA,tspan,X0);
X0=1;
Y0=4;
tspan = [0 24];
[t,Y] = ode45(@ConcB,tspan,X0,Y0);
X0=1;
Y0=4;
Z0=6;
tspan = [0 24];
[t,Z] = ode45(@ConcC,tspan,X0,Y0,Z0);
function X=ConcA(t,X)
k1=1.26;
X0=1;
X=X0*exp(-k1*t);
end
function Y=ConcB(t,Y)
k1=1.26;
k2=0.74;
X0=1;
Y0=4;
Y=Y0*exp(-k2*t)+((X0*k1)/(k2-k1)*(exp(-k1*t)-exp(-k2*t)));
end
function Z=ConcC(t,Z)
k1=1.26;
k2=0.74;
k3=0.22;
X0=1;
Y0=4;
Z0=6;
Z=Z0*exp(-k3*t)+((Y0*k2)/(k3-k2)*(exp(-k2*t)-exp(-k3*t)))+X0*k1*k2*((exp(-k1*t))/((k2-k1)*(k3-k1))-(exp(-k2*t))/((k2-k1)*(k3-k2))-(exp(-k3*t))/((k3-k1)*(k3-k2)));
end
채택된 답변
추가 답변 (1개)
Bjorn Gustavsson
2020년 11월 23일
0 개 추천
The way you've coded ConcA it should solve an ODE that looks like this:
That might very well be the ODE you need to solve, but if that's the case why not straight integrate it by hand. It seems more likely that If you have an ODE that looks something like this:
But that is something you have to make clear.
HTH
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!