Can I call another ode45 inside the function file of an ode45 ?
17 次查看(过去 30 天)
显示 更早的评论
I have an ode45 function file with equations from a matrix, but few variable in these equations are time dependent and are solutions of other few time dependent coupled equations. Can I use ode45 here to find the solution of these time dependet variables for each time step? I tried to put at the end of the function file (after and before end both ways). But that shows error.
I am giving structure of the function and main file here
%function file
function dvdt=outfun(t,vec)
dvdt=zeros(36,1);
y0=[ 1; 2; 3; 4;]
%alpha and beta are time dependent nonlieanr coupled equations.
[T0 z]= ode45('infun',t0,y0)% can it be t instead of t0?
for ii=1:length(T0)
alpha=z(ii,1);
beta=z(ii,3);
g3r=g*real(alpha)%
g3im=g*imag(alpha)%
g4r=g*real(beta)%
g4im=g*imag(beta)%
a=[.....]%matrix
v=vec;%Initial conditions in the matrix form
N=[n1 n2 n3 n4 n5 n6];
dvrdt= a*v + diag(N) ;% some matrix equations
dvdt(1)=dvrdt(1,1);%equations
....
...
dvdt(36)=dvrdt(6,6);
end
function dydt=infun(t,y)
dydt=zeros(4,1);
dydt(1)= .....;%alpha
dydt(2)=.....;%conj(alpha)
dydt(3)=......;%beta
dydt(4)=......;%conj(beta)
end
end
%main file
tsapn=0:0.01:10
x=[];
%initial condition
vv=[v11_0, v21_0,v31_0,v41_0,v51_0,v61_0,...
.
.
.
v16_0, v26_0,v36_0,v46_0,v56_0,v66_0];
[T, V]=ode45(@outfun,tspan,vv);% calling
[mm,n]=size(V);
for ii=1:mm
v1=reshape(V(ii,:),6,6);
a=max(eig(v1))
x=[x; T(ii) a]
.
.
.
.
end
Any suggestions please, thanks. Edit: just modified function names
6 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!