Struggling with ode45 MATLAB function

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by