changing values of RHS with each time step in ODE
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Wan Ji
2021년 8월 18일
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
Wan Ji
2021년 8월 24일
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
2021년 8월 18일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Special Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!