필터 지우기
필터 지우기

Struggling with ode45 MATLAB function

조회 수: 1 (최근 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 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