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 ^_^

 採用された回答

Stephen23
Stephen23 2018 年 5 月 14 日
編集済み: Stephen23 2018 年 5 月 14 日

0 投票

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?

その他の回答 (1 件)

Benjamin Liu
Benjamin Liu 2018 年 5 月 14 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeNumerical Integration and Differential Equations についてさらに検索

質問済み:

2018 年 5 月 14 日

回答済み:

2018 年 5 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by