Hello, everyone,
I'm trying to work with a code that involves ode45, in the one in the equation that will be solved I have to introduce a single value from a vector that will change depending on the time the equation is solved, I mean if it is x=x(0) then u1(1) and u2(t), when x=x(1) then u1(2), u2(2)… This is my code:
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
The problem is that it sends me this error: And I don't know what is wrong with the code, or what else can I do in order for it to read it, can you please help me? Thanks
Error in scobe1>f (line 36) global a s1 s2 u1 u2 newData;Error using fevalOutput 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);
Best Answer