Struggling with ode45 MATLAB function

2 ビュー (過去 30 日間)
Felix Lauwaert
Felix Lauwaert 2015 年 8 月 7 日
回答済み: Walter Roberson 2015 年 8 月 7 日
Hello everybody,
I'm trying to introduce my function into ode45 to solve it but it messages me "Not enough input arguments". I allready know how to folve the problem the ugly way, but it's not my will to have an ugly function because it's part of a larger group of functions working together. I'll explain it with an example:
fun= @(t,x) = [ x(3) , x(4) , x(1)*sin(x4-u) , x(1)/(x(2)-u)*cos(x5-u) ]
As you see, I have a function with 4 ODEs so I only have to give ode45 4 initial conditions for x(1) to x(4). BUT I have a constant 'u' inside fun and I don't want to define fun in the function where I call ode45 because I'll have to use different 'u' values in my group of functions. If it's possible, I don't want to use global variables.
Thanks for your help.

採用された回答

Walter Roberson
Walter Roberson 2015 年 8 月 7 日
fun= @(t,x, u) = [ x(3) , x(4) , x(1)*sin(x4-u) , x(1)/(x(2)-u)*cos(x5-u) ]
then when you need to specialize for a particular u,
funu = @(t,x) fun(t,x,specific_u)
and then pass funu into ode45

その他の回答 (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