フィルターのクリア

How to add variable to ode45 method?

2 ビュー (過去 30 日間)
I G
I G 2018 年 5 月 7 日
回答済み: Torsten 2018 年 5 月 7 日
I am solving system of two ODEs with ode45 method, and code is working for constant cross section, that means constant radius R:
function f=fun(z,p)
R=2; sig=1; beta=1;
f(1)=-32*beta/(R^4*p(1));
f(2)=(-(2-sig)*8*f(1)/(sig*R)-f(1)*p(2))/p(1);
[zv,pv]=ode45('fun',[1 0],[1; 0])
But I need to implement solution where R=2-z, z is longitudinal coordinate, it is there already in first row of function. I wrote z=0:0.001:1; and R=2-z, like this:
function f=fun(z,p)
z=0:0.001:1;
R=2-z; sig=1; beta=1;
f(1)=-32*beta/(R^4*p(1));
f(2)=(-(2-sig)*8*f(1)/(sig*R)-f(1)*p(2))/p(1);
[zv,pv]=ode45('fun',[1 0],[1; 0])
But I got errors matrix dimensions must agree, what should I do to correct this? On the other side z need to be equal to zv, do I need to call z=0:0.001:1; different?

採用された回答

Torsten
Torsten 2018 年 5 月 7 日
The actual longitudinal coordinate z is transferred to your function "fun" by ODE45:
function f=fun( *z*,p)
You cannot reset this value by
z=0:0.001:1;
and I don't see any reason to do so. Thus just delete the line
z=0:0.001:1;
Best wishes
Torsten.

その他の回答 (0 件)

カテゴリ

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