changing values of RHS with each time step in ODE

1 view (last 30 days)
Bhanu Pratap Akherya
Bhanu Pratap Akherya on 18 Aug 2021
Commented: Wan Ji on 24 Aug 2021
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?

Answers (2)

Wan Ji
Wan Ji on 18 Aug 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 Comments
Wan Ji
Wan Ji on 24 Aug 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.

Sign in to comment.


Steven Lord
Steven Lord on 18 Aug 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 Comments
Bhanu Pratap Akherya
Bhanu Pratap Akherya on 20 Aug 2021
in the excel sheet i have bunch of numbers that have been taken from a cfd software.

Sign in to comment.

Categories

Tags

Community Treasure Hunt

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

Start Hunting!