changing values of RHS with each time step in ODE
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have a set of values for the force term "F" (in the equation my"+cy'+ky=F) saved in an excel file which i have recalled using:
F=xlsread('l&d.xlsx','O1:O300');
My main code looks something like:
y0=initial conditions
[tsol ysol]=ode15s('beam_function',[1:dt:T],y0);
plot(tsol,ysol);
whereas, my function code looks something like:
function [dy]=beam_function(t,y)
dy=[y(1:u-1);
inv(M)*(F-K*y-C*y)]
The problem is that i want to recall each value of F at different time steps but i dont know how to do that, can anyone guide me?
0 commentaires
Réponses (2)
Wan Ji
le 18 Août 2021
Is F time dependent ? If so, just write a function named Force
function F = Force(t)
t_array = []; % This is t array from xls file
f_array = []; % This is F array from xls file
F = interp1(t_array,f_array,t);
end
And the odefun becomes
function [dy]=beam_function(t,y)
dy=[y(1:u-1);
inv(M)*(Force(t)-K*y-C*y)];
end
9 commentaires
Wan Ji
le 24 Août 2021
Use
F = interp1(t_array,f_array,t);
is only for obtaining the force as time given. t_array and f_array is from your excel, whilst I didnot even see its format.
Steven Lord
le 18 Août 2021
Use the "ODE with Time-Dependent Terms" example on the documentation page for the ode45 function as a model. The f and g variables in that example correspond to the data from your spreadsheet, with ft and gt being the times associated with that data. Then inside the myode function in the example you would interpolate your spreadsheet data.
Passing the data that you read from the spreadsheet in as additional parameters rather than reading it in every time the ODE solver calls your ODE function will save time (potentially a lot of time if reading the data takes a while or the ODE solver needs to call your ODE function many times.)
8 commentaires
Voir également
Catégories
En savoir plus sur Dialog Boxes dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!