Solve a Diff.equation in another Diff.Equation using ODE
Afficher commentaires plus anciens
Hello everyone,
I am a novice in programming so please bear with me.
I am currently trying to solve a diff. equation using the ODE45. However, the function that my programm calls for contains a diff.equation itself and is using an ODE23s to solve that one.
I need the ODE45 to use only 1 column of the ODE23s matrix to finish its own process and then hand over both matrices to the script. Simply coupling them does not seem to work.
% Script:
% --- Bunch of Information cutted ---
n = input('...'); % Number of finite elements
tfin = input('...');
tpan = [0 tfin];
tic
[t,x]=ode45('Function_1',tspan,x0);
toc
% Function_1
% --- Bunch of information cutted ---
xdot(1)=(vs*y1(2)-(ls+d)*x(1))/md;
for i=2:nf-1
xdot(i) = (ls*(x(i-1)-x(i))+vs*(y1(i+1)-y1(i)))/m;
y1(i) = a1(i)*x(i)/(1+(a1(i)-1)*x(i));
end
xdot(nf)=(f*xf0+ls*x(nf-1)-lr*x(nf)+vr*y1(nf+1)-vs*y1(nf))/m;
y1(nf) = a1(nf)*x(nf)/(1+(a1(nf)-1)*x(nf));
for i=nf+1:n-1
xdot(i)= (lr*(x(i-1)-x(i))+vr*(y1(i+1)-y1(i)))/m;
y1(i) = a1(i)*x(i)/(1+(a1(i)-1)*x(i));
end
% --- Bunch of information cutted ---
tic
[t,u] = ode23s('Function_2',tspan,t0);
toc
% NOW DO THE FOLLOWING:
% use u(:,n) to calculate xdot(n)
% combine xdot and u to one matrix
% hand over the matrix to script
Can i even expect u and xdot to have the same number of rows just because tspan is the same? I figured the amount of steps taken is depending on the tolerances achieved...
I could probably describe the situation better but I didnt mean to copy a hundred lines of code right from the get go.
Any ideas appreciated.
Best regards
1 commentaire
Torsten
le 14 Mar 2022
With the code you posted we can't help you, sorry.
But you can clip your .m-files to your request by using the attachments button under "Insert" in the editor.
Réponses (0)
Catégories
En savoir plus sur Ordinary Differential Equations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!