ODE Solver with array value parameter
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Teo Protoulis
il 20 Ott 2019
Commentato: Dihan Zou
il 11 Apr 2020
I need to solve the following differential equations:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243678/image.png)
where x1 and x2 are the states of the system and y is the input of the system and it is represented by a 1002x1 vector. How is it possible to solve this system of differential equations?
3 Commenti
Star Strider
il 21 Ott 2019
What you describe is not the correct approach, in part because MATLAB uses adaptive ODE solvers, not fixed-step ODE solvers.
Risposta accettata
Star Strider
il 21 Ott 2019
Try this example:
yv = randn(1002,1); % Create ‘y’
tv = 0:numel(yv)-1; % Create Corresponding Time Vector
Eqns = @(t,x,tv,yv) [x(2)-interp1(tv(:), yv(:), t); -3*x(2)-2*x(1)+3*interp1(tv(:), yv(:), t)];
tspan = linspace(0, 10, 50);
ic = [0; 1]; % Use The Correct Initial Conditions
[T, X] = ode45(@(t,x)Eqns(t,x,tv,yv), tspan, ic);
figure
plot(T, X)
grid
Provide your own vectors for ‘y’ (that I call ‘yv’ here) and the time vector (‘tv’ here) that corresponds to it.
Make other appropriate changes to reflect the actual values you intend to use.
3 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!