What is the role of [] in ode?

3 ビュー (過去 30 日間)
채원 이
채원 이 2022 年 4 月 4 日
編集済み: Stephen23 2022 年 5 月 4 日
Example1)
[t x] = ode45(@fun, tspan, c0,...)
I'm not sure what exactly is [t x] above. As I understand it, does ode represent t,x in [] by unpacking it? Is it exactly solving for x for t?
Example2)
[t x] = ode45(@fun,tspan,c0,...)
[t y] = ode45(@fun,tspan, c0,...)
Does having two odes as above mean solving for x and y? If a function is a function related to x and y (z=x+y), does ode represent the x and y values ​​for t?
  1 件のコメント
Stephen23
Stephen23 2022 年 4 月 6 日
編集済み: Stephen23 2022 年 5 月 4 日
"I'm not sure what exactly is [t x] above."
How to call functions with multiple output arguments:
"As I understand it, does ode represent t,x in [] by unpacking it?"
No, MATLAB does not have any concept of output "unpacking". MATLAB functions can return multple outputs: in the example you show, the function ODE45 two outputs. The names of the variables assigned to those outputs are irrelevant.

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

回答 (1 件)

Sam Chak
Sam Chak 2022 年 4 月 4 日
If the system is
,
then you can solve the ODEs as follows:
kp = 1;
kd = 2;
F = @(t, x) [x(2); ...
- kp*x(1) - kd*x(2)];
[t, x] = ode45(F, [0 10], [1, 0]);
plot(t, x)
The solver assigns the solution in the time-vector, t and the array.
  11 件のコメント
Walter Roberson
Walter Roberson 2022 年 4 月 11 日
Change
dydt(1) = D.*d2Cdz2(i) - u*dCdz(i) + F*(-y(1)-y(2));
to
dydt(i) = D.*d2Cdz2(i) - u*dCdz(i) + F*(-y(i-1)-y(i));
채원 이
채원 이 2022 年 5 月 4 日
Among the replies above, why is q(y1,y2) = - y(1) - y(2);

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by