From: Ben Spivey on
Hello Jeffy,

Have you learned how to return non-optimization variables from an fsolve function since this post? I have had the same question as you for months now and have not found a solution. I did not see how output functions can solve this issue as they only solve the issue of passing parameters into a function, which you acknowledged Matlab fsolve can do.

Thank you,

Ben

"Jeffy Soo" <jeffycbsoo(a)gmail.com> wrote in message <h21tsp$g1a$1(a)fred.mathworks.com>...
> Hi everyone,
>
> I would like to know if it is possible (and if so, how) to pass variables back from an fsolve function, in addition to the optimized ones. To elaborate, if the following is a common line for calling the fsolve function:
> x = fsolve(x0,options,p1,p2,&#8230;,pn)
> where p1,p2,&#8230;,pn are the additional variables passed to fsolve, I am looking to achieve something like this,
> [x,q1,q2,&#8230;,qn] = fsolve(x0,options,p1,p2,&#8230;,pn)
> where the output variables are x (the optimized vector) and q1,q2,&#8230;,qn, which are additional variables calculated in the fsolve function that I require also. A possible solution is to simply use global variables between the two m-files, but since the variables qi are not constants, I prefer not to global them (MATLAB also issues a warning).
>
> MATLAB understand [x,q1,q2] as [x,fval,exitflag], which is not what I&#8217;m looking for. Any more elements in the vector than that gives an error.
>
> I would be able to save much computation time, if this can be done. Thanks all.
>
> Jeffy