Simulink Integrator block with end/ final condition

for the Integrator block, if the initial condition x(t0)=x0 is not available, but the final condition x(t_f)=k is given, where t_f is the finial time. How can i set the simulation?
I know in Matlab ode45, the time span can be set as decreasing, such as [t_f, t0], where t_f > t0, then the final condition can be set as the initial conditon.

Réponses (1)

Tao Wang
Tao Wang le 9 Juin 2023

0 votes

利用interp1命令降时变参数进行插值,然后再带入ODE45求解。详见ODE45帮助文件中的 ODE with Time-Dependent Terms
Use the "interp1" to interpolation the time varying parameters, then follow the ODE45, see the help doctuments as below (cited from Matlab "help ode45")
ODE with Time-Dependent Terms
Consider the following ODE with time-dependent parameters
The initial condition is . The function f(t) is defined by the n-by-1 vector f evaluated at times ft. The function g(t) is defined by the m-by-1 vector g evaluated at times gt.
Create the vectors f and g.
ft = linspace(0,5,25);
f = ft.^2 - ft - 3;
gt = linspace(1,6,25);
g = 3*sin(gt-0.25);
Write a function named myode that interpolates f and g to obtain the value of the time-dependent terms at the specified time. Save the function in your current folder to run the rest of the example.
The myode function accepts extra input arguments to evaluate the ODE at each time step, but ode45 only uses the first two input arguments t and y.
function dydt = myode(t,y,ft,f,gt,g)
f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t
g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t
dydt = -f.*y + g; % Evaluate ODE at time t
Solve the equation over the time interval [1 5] using ode45. Specify the function using a function handle so that ode45 uses only the first two input arguments of myode. Also, loosen the error thresholds using odeset.
tspan = [1 5];
ic = 1;
opts = odeset('RelTol',1e-2,'AbsTol',1e-4);
[t,y] = ode45(@(t,y) myode(t,y,ft,f,gt,g), tspan, ic, opts);
Plot the solution, y, as a function of the time points, t.
plot(t,y)

Catégories

En savoir plus sur General Applications dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by