Matlab: Why in passing additional arguments in ode45 i need to pass `(t,y)` as well?

后端 未结 1 742
误落风尘
误落风尘 2021-01-26 06:02

In MATLAB: How do I pass a parameter to a function?,

it is said that if i want to pass the parameter u, i need to use anonymous function:

u          


        
相关标签:
1条回答
  • 2021-01-26 06:41

    Simply appending @ to the front of a function creates a function handle not an anonymous function. This function handle implicitly forwards all input arguments onto the function.

    What you need is a function handle to an anonymous function (since it accepts inputs and performs an action or calls another function). In this case, it does not implicitly pass inputs therefore you need to explicitly receive input arguments and then use them (or not) within the anonymous function.

    @(t, y)ypdiff(t, y, u)
    

    The only exception to this rule is that some graphics objects will accept a cell array in place of a callback function which accept a function handle as the first element and any additional parameters as the second, but this is not the case for ode45.

    {@ypdiff, u}
    
    0 讨论(0)
提交回复
热议问题