问题
I'm working with an ODE model the one I have to put a vector in a variable and then solve it, but I have some parameters which depends on some of the equations of the model, like auxiliar functions/equations but I get this error:
Error using Hovorka2004_Prueba>fun
Too many output arguments.
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); %
ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0,
tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Error in Hovorka2004_Prueba (line 8)
[t,x]=ode45(@fun,tspan,x0);
This is what I have so far:
function [t,x]=Hovorka2004_Prueba
tspan=[0;100];
x0 = [0.1249; 0.0941; 0; 0;0; 0.7665;0.9519; 0.8473];
global out1
[t,x]=ode45(@fun,tspan,x0);
out1=[t,x]
assignin('base','out1',out1);
figure
subplot(2,1,1)
plot(t,x(:,1));
subplot(2,1,2)
plot(t,x(:,5));
end
function fun(t,x)
uu1 = importdata('datossinmodi.mat');
ufun = @(t) interp1(1:length(uu1), uu1, t, 'nearest', 0);
% Begining of the parameters
% Constants:
F01= 0.0097;
EGP0= 0.0161;
k12=0.066;
DG=0;
AG=0.8;
tmaxG=40;
VG= 0.16;
tmaxI=55;
Ke=0.138;
VI=0.12;
Ka1=0.006;
Ka2=0.06;
Ka3=0.03;
Kb1= 51.2e-4*Ka1;
Kb2= 8.2e-4*Ka2;
Kb3= 520e-4*Ka3;
% Auxiliar Functions/Equations:
G=x(1)/VG;
if G>=4.5
F01_C=F01;
else
F01_C=F01*G/4.5;
end
if G>=9
FR=0.003*(G-9)*VG;
else
FR=0;
end
UI=x(4)/tmaxI;
UG=(DG*AG*t*exp(-t/tmaxG))/(tmaxG)^2;
% Model:
f = @(t,x) [
-((F01_C/VG*G)*x(1))+ x(6)*x(1) + k12*x(2) - FR + UG + EGP0*(1-x(8)); %(1)
x(6)*x(1)-(k12+x(7))*x(2); %(2)
ufun(t)-(x(3)/tmaxI); %(3) IN HERE ufun(t) IS WHERE I AM TRYING TO PUT THE VECTOR
(x(3)/tmaxI)-(x(4)/tmaxI); %(4)
UI/VI - Ke*x(5); %(5)
-Ka1*x(6)+ Kb1*x(5); %(6)
-Ka2*x(7)+ Kb2*x(5); %(7)
-Ka3*x(8)+ Kb3*x(5); %(8)
];
end
How can I make it work? What's wrong with it?
Thanks a lot for your help (:
EDIT: I tried function dx=fun (t,x)
but it keeps sending an error:
>> Hovorka2004_Prueba
Error in Hovorka2004_Prueba>fun (line 21)
uu1 = importdata('datossinmodi.mat');
Error using feval
Output argument "dx" (and maybe
others) not assigned during call to
"C:\Users\AnnieA\Dropbox\Tesis (A.
Olay)\MATLAB Simulations\Lectura de
Vectores\Hovorka2004_Prueba.m>fun".
Error in odearguments (line 88)
f0 = feval(ode,t0,y0,args{:}); %
ODE15I sets args{1} to yp0.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0,
tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Error in Hovorka2004_Prueba (line 8)
[t,x]=ode45(@fun,tspan,x0);
Also with function f=fun(t,x)
but it sends this
>> Hovorka2004_Prueba
Error using odearguments (line 93)
FUN returns a vector of length 1,
but the length of initial conditions
vector is 8. The vector returned by
FUN and the initial conditions
vector must have the same number of
elements.
Error in ode45 (line 114)
[neq, tspan, ntspan, next, t0,
tfinal, tdir, y0, f0, odeArgs,
odeFcn, ...
Error in Hovorka2004_Prueba (line 8)
[t,x]=ode45(@fun,tspan,x0);
来源:https://stackoverflow.com/questions/33987704/how-to-interpolate-a-vector-and-work-with-variables-ode45