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!