How do I define an anonymous function with a function as an argument?

Currently I have a .m file which contains the following: Where y0 is a column vector of size 3, h is a constant f is a function handle and z is the unknown variable I have defined the following similarly to how equations are defined on the fsolve page for MATLAB. https://au.mathworks.com/help/optim/ug/fsolve.html For solving a 2d system of non-linear equations.
function E = setEpsilon3(y0,h,f,z)
E(1) = y0 + h*((1/4)*f(h*(1/2 - sqrt(3)/6),z(1)) + (1/4 - sqrt(3)/6)*f(h*(1/2 - sqrt(3)/6),z(2))) - z(1);
E(2) = y0 + h*((1/4 + sqrt(3)/6)*f(h*(1/2 + sqrt(3)/6),z(1)) + (1/4)*f(h*(1/2 + sqrt(3)/6),z(2))) - z(2);
Outside of the function I'm trying to define the set of equations as an anonymous function with respect to z but it keeps running an error "Unbalanced or unexpected parenthesis or bracket" When I define it as E = @(z) [setEpsilon3(y0,h,f,z)];
I was wondering if there was a specific way to define an anonymous function via this way, as I cannot do E = @setEpsilon3 in the fashion that the MATLAB example does.
Thank you ^_^

 Accepted Answer

Assuming that y0, h, and f are defined in the local workspace:
E = @(z) setEpsilon3(y0,h,f,z);
What were you trying to concatenate with the square brackets?

More Answers (1)

Thank you! The function does seem to be working now, I have some other errors to deal with but this one is solved. The square brackets was just one of the methods I had ended up trying after multiple attempts at different expressions.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!