我正在尝试使用涉及ode45的代码,在将要求解的等式中的代码中,我必须从向量中引入单个值,该值将根据等式求解的时间而改变,我的意思是如果它是x = x(0)那么u1(1)和u2(t),当x = x(1)那么u1(2),u2(2)......这是我的代码:
function [sal] = scobe1
clear
clc
global a;
a=1;
assignin('base','a',a)
tspan = [0; 180];
x0 = [80; 0];
[t,x] = ode45(@f,tspan,x0);
sal=[t,x]
figure
subplot(2,1,1)
plot(t,x(:,1),'k-');
subplot(2,1,2)
plot(t,x(:,2),'b-');
function dxdt = f(t,x)
global a s1 u1 u2 newData;
newData=importdata('datosnoembarazo.mat');
assignin('base','newData',newData);
u1=getfield(newData,'glucosa4dias');
assignin('base','u1',u1);
u2=getfield(newData,'insulina4dias');
assignin('base','u2',u2);
u1=getfield(newData,'glucosa4dias');
assignin('base','u1',u1);
u2=getfield(newData,'insulina4dias');
assignin('base','u2',u2);
if (a<=s1)
dxdt = [
(-4.9e-2-x(2))*x(1) + (4.42 + u1(a)) %(1) IN HERE u1 IS THE VECTOR'S NAME
-9.1e-2*x(2) + u2(a) %(2) IN HERE u2 IS THE VECTOR'S NAME
];
a=a+1
assignin('base','a',a);
else return
end
问题是它向我发送了这个错误:我不知道代码有什么问题,或者我还能做些什么才能阅读它,你能帮助我吗?感谢
Error in scobe1>f (line 36)
global a s1 s2 u1 u2 newData;
Error using feval
Output argument "dxdt" (and maybe others) not assigned during call to
"C:\Users\AnnieA\Dropbox\Tesis (A. Olay)\GUI Examples\Resumen de Modelos\scobe1.m>f".
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in scobe1 (line 25)
[t,x] = ode45(@f,tspan,x0);