Filter löschen
Filter löschen

Struggling with ode45 MATLAB function

1 Ansicht (letzte 30 Tage)
Felix Lauwaert
Felix Lauwaert am 7 Aug. 2015
Beantwortet: Walter Roberson am 7 Aug. 2015
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.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 7 Aug. 2015
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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by