フィルターのクリア

Can I call another ode45 inside the function file of an ode45 ?

6 ビュー (過去 30 日間)
Anil
Anil 2024 年 2 月 1 日
編集済み: Anil 2024 年 2 月 19 日
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 件のコメント
Torsten
Torsten 2024 年 2 月 19 日
編集済み: Torsten 2024 年 2 月 19 日
You should state your problem mathematically without code.
My guess is that you don't need two calls to ode45 with 36 and 4 unknowns, respectively, but only one call with 40 unknowns.
Anil
Anil 2024 年 2 月 19 日
Dear @Torsten, Thanks for that. That looks much simpler than the earlier complex version. I did that but the only doubt was different equations making me confsued and I went for the two ODE45. Thank you very much @Stephen23 and @Torsten for your help.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by