using function handle in fsolve
2 views (last 30 days)
Show older comments
Marrie
on 11 Dec 2013
Answered: Walter Roberson
on 11 Dec 2013
Hi all,
I have computed the function vector and its Jacobian, and use matlabFunction to create a .m file to store the function and Jacobian. Here is my code:
currdir = [pwd filesep];
filename = [currdir, 'objfun.m'];
matlabFunction(fvec, J, 'file', filename, 'vars', {x, phi});
phi=zeros(N,1);
for i=1:1:STEP
[x,fval,exitflag] = fsolve(@(x,phi)objfun,x0,options);
phi(1:N)=x(1:N);
end
where fvec and J have been computed analytically and objfun.m is created successfully. The only problem is I have a global vector phi in objfun.m that needs to update after each step i. I got the error:
Error using objfun (line 8)
Not enough input arguments.
Error in @(x,phi)objfun
I did not see any inconsistency of dimensions in x and phi. Could anybody give some suggestions? Thank you.
0 Comments
Accepted Answer
Walter Roberson
on 11 Dec 2013
@(x,phi)objfun means "this is an anonymous function with two dummy arguments, "x" and "phi". When this anonymous function is invoked, it should invoke "objfun" with no arguments."
Remember,
z = objfun
is the same thing as
z = objfun()
Perhaps what you want is instead,
@(x) objfun(x, phi)
0 Comments
More Answers (0)
See Also
Categories
Find more on Whos 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!