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
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}