How do I define an anonymous function with a function as an argument?
Show older comments
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 ^_^
1 Comment
Torsten
on 14 May 2018
E = @(z) setEpsilon3(y0,h,f,z);
should work.
Accepted Answer
More Answers (1)
Benjamin Liu
on 14 May 2018
0 votes
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!