using function handle in fsolve

2 ビュー (過去 30 日間)
Marrie
Marrie 2013 年 12 月 11 日
回答済み: Walter Roberson 2013 年 12 月 11 日
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.

採用された回答

Walter Roberson
Walter Roberson 2013 年 12 月 11 日
@(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 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by