Solving a first-order ODE given an input vector

2 ビュー (過去 30 日間)
Laurel Regibeau-Rockett
Laurel Regibeau-Rockett 2020 年 3 月 26 日
編集済み: Pavitra Vaishali 2023 年 3 月 29 日
I am trying to solve the following ODE:
The purpose of this is to generate a timeseries y(t) given an input timeseries z(t) that I have already created. y(t) should be a vector of the same dimensions as z(t). However, I am not sure how to go about this using Matlab. I have tried using ode45 with the vector z(t) and the scalar k added as inputs:
odefun= @(t, y, z, h) z-h*y;
[~, y_sim]=ode45(@(t, y) odefun(t, y, z_sim, k), 1:20000, 0); %Set first value of y to zero
However, this returns the following error:
Error using odearguments (line 93)
@(T,Y)ODEFUN(T,Y, Z_SIM, K) must return a column vector.
How might I go about doing this?
  1 件のコメント
Pavitra Vaishali
Pavitra Vaishali 2023 年 3 月 29 日
編集済み: Pavitra Vaishali 2023 年 3 月 29 日
Hey were you able to find the solution. If so, please help me too I am facing similar problem. Only change is I have a matrix instead of single value at time.
Meaning for each time stamp I will get a matrix.

サインインしてコメントする。

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 3 月 26 日
編集済み: Ameer Hamza 2020 年 3 月 26 日
This is actually equivalent to solving an ODE with time-varying term. See the example here: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3l43b which deals exactly the same problem. You first need to define the value of z inside odefun as a function of t.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by