0

I would like to use the ode23 solver for systems. My system has three equations and the first one depends on an variable 'z' which is declared in the code above. Here“s the sample code:

clc; clear;
z=1;

function Fv=funsys(t,Y,z); 
Fv(1,1)=2*Y(1)+Y(2)+5*Y(3)+exp(-2*t) + z; 
Fv(2,1)=-3*Y(1)-2*Y(2)-8*Y(3)+2*exp(-2*t)-cos(3*t);
Fv(3,1)=3*Y(1)+3*Y(2)+2*Y(3)+cos(3*t); 
end

[tv,Yv]=ode23('funsys',[0 pi/2],[1;-1;0]); 

The get the error that the variable 'z' is not declared. So, is there any possibility to solve this? (The function 'funsys' needs to be dependent on 'z')

WinterMensch
  • 643
  • 1
  • 7
  • 17

1 Answers1

1

Yes, have a look at Pass Extra Parameters to ODE Function in the documentation:

you can pass in extra parameters by defining them outside the function and passing them in when you specify the function handle

In your case, it would look something like this:

[tv,Yv]=ode23(@(t,y) funsys(t,y,z),[0 pi/2],[1;-1;0]); 
am304
  • 13,758
  • 2
  • 22
  • 40