ODE Solver with array value parameter

조회 수: 6 (최근 30일)
Teo Protoulis
Teo Protoulis 2019년 10월 20일
댓글: Dihan Zou 2020년 4월 11일
I need to solve the following differential equations:
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
Teo Protoulis
Teo Protoulis 2019년 10월 21일
I am trying to solve it using Matlab ode45(@ode, timespan, [0 0]) solver. My problem is that I can't find out how to pass each value of the vector y to the ode solver function . I mean take the first value y(1) of vector y and use for the step with initial values [0 0] for [x1 x2] , then the second value y(2) of vector y for the updated values of [x1 x2] and do this for all values of vector y.
Star Strider
Star Strider 2019년 10월 21일
What you describe is not the correct approach, in part because MATLAB uses adaptive ODE solvers, not fixed-step ODE solvers.
See my Answer for the correct approach.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2019년 10월 21일
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
Star Strider
Star Strider 2019년 10월 21일
As always, my pleasure!
I very much appreciate your compliment!
Dihan Zou
Dihan Zou 2020년 4월 11일
Amazingly talented method. Thank you both!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by