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 ^_^
1 个评论
Torsten
2018-5-14
E = @(z) setEpsilon3(y0,h,f,z);
should work.
采纳的回答
更多回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!