我正在尝试使用涉及 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);