using function handle in fsolve
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marrie
le 11 Déc 2013
Réponse apportée : Walter Roberson
le 11 Déc 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 commentaires
Réponse acceptée
Walter Roberson
le 11 Déc 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!