I have a system of equations...
dF(a,b,c)/da = 0;
dF(a,b,c)/db = 0;
dF(a,b,c)/dc = 0;
where a
, b
, c
are unknown variable constants and dF/d*
are anonymous functions of the variables. I have to solve for a
, b
and c
in an optimization problem. When the system reduces to just one equation, I use Matlab's fzero
to solve for the variable and it works. For example
var_a = fzero(@(a) dF(a)/da,0);
After noticing that fzero
and fsolve
give dramatically different answers for some cases I did some searching. From what I gather , fzero
only works for a single equation of a single variable? So moving to a system of equations, I'd like to choose the most appropriate method. I've used Matlab's solve
in the past, but I believe that is for symbolic expressions only? What is the best method for solving a linear system of anonymous functions, which all equal zero?
I tried the following, and got back results
vars = fsolve(@(V)[dF(V)/da;dF(V)/db;dF(V)/dc],zeros(1,3));
where vars
contains all 3 variables, but after reading the examples in the previous link , Fsolve
couldn't exactly find the zeros for x^2 and x^3. The solution vector in the system I presented above is all zeros and the functions are polynomials. Putting this all together, I'm wondering if fsolve
isn't the best choice?
Can I build a system of calls to fzero
? Something along the lines of
vars = [fzero(@(a) dF(a,b,c)/da,0);
fzero(@(b) dF(a,b,c)/db,0);
fzero(@(c) dF(a,b,c)/dc,0)];
which I don't think would work (how would each dF/d*
get the other 2 variable inputs?) or would it?
Any thoughts?
You can numerically solve to minimize any function using 'lsqnonlin'. To adopt this for a system of equations, simply turn them into a single function with a vector input. Something like this:
fToMinimize = @(abc) ...
(dF(ABC(1),ABC(2),ABC(3))/da)^2 +...
(dF(ABC(1),ABC(2),ABC(3))/db)^2 +...
(dF(ABC(1),ABC(2),ABC(3))/dc)^2 ;
abcSolved = lsqnonlin(fToMinimize, [0 0 0])
If you have a guess for the values of a, b, and c, you can (and should) use those instead of the [0 0 0] vector. There are also many options within the lsqnonlin function to adjust behavior. For example how close to the best answer you want to get. If the functions are well behaved, you should be able to tighten the tolerance down a lot, if you are looking for a near exact answer.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.