LimpyNuts All American 16859 Posts user info edit post |
I have 2 smooth functions f1 and f2. I want to solve the system of equations:
f1(x1,x2) = 0 f2(x1,x2) = 0
I have a rough idea for the value of x1. The functions are undefined when x1 or x2 < 0. The value of x2 is known to be close to 0.
I need to solve 1200 versions of this problem (for variations in f1 and f2 -- i'm not looking for 1200 roots of the same problem). For each of those problems I need to find 100 roots.
What's the best way to go about this? I tried using the Newton-Raphson method but most of the time one of 2 thinig happens: 1) divergence, 2) the estimate of x2 goes negative. Since my initial guesses are known to be close to the root I'm finding, it does converge sometimes (about 1/3 of the time).
What are some other numerical methods for solving this kind of problem (links would help)? 4/8/2006 11:24:38 PM |
humandrive All American 18286 Posts user info edit post |
http://www4.ncsu.edu/~doster/NE400/Computing/Brent.pdf
Pretty much the same thing as newton
[Edited on April 8, 2006 at 11:29 PM. Reason : I'm assuming you've used that before] 4/8/2006 11:28:08 PM |
clalias All American 1580 Posts user info edit post |
MATLAB
open the help window and type 'fsolve'
and if the loop is going to slow you can compile it.
[Edited on April 8, 2006 at 11:34 PM. Reason : fsolve]
[Edited on April 8, 2006 at 11:36 PM. Reason : compile] 4/8/2006 11:32:51 PM |
LimpyNuts All American 16859 Posts user info edit post |
^^aahhahahahhaahahahaaahahhaah funny kevin. thanks for the laugh, but i'm solving a nonlinear system of equations (multiple degrees of freedom). that's for a single equation.
^MATLAB and Maple have crossed my mind, but I don't know how to code each of them. Also, the program I'm writing is several hundred lines long and if I wanted to swith to Maple or MATLAB I'd have to recode the whole thing...
[Edited on April 8, 2006 at 11:46 PM. Reason : ] 4/8/2006 11:44:21 PM |
clalias All American 1580 Posts user info edit post |
You can call matlab from c/c++ code (might be as simple as adding a library-depending on the function)
by the way Matlab >>> Maple for numerical problems
If you need a robust nonlinear equation solver it would take a while to code that yourself. Probably be very much quicker to learn how to call Matlab or just recode in matlab.
matlab code is easy to pick up quickly.
Here goes some links for ya. http://www.mathworks.com/support/tech-notes/1600/1622.html http://www.mathworks.com/access/helpdesk/help/toolbox/optim/
The second one is to the documentation for the Optimization toolbox, that's where the function 'fsolve' is located. Click on "Alphabetical List" of the functions and search for it.
[Edited on April 8, 2006 at 11:48 PM. Reason : .]
[Edited on April 9, 2006 at 12:00 AM. Reason : .] 4/8/2006 11:47:17 PM |
sNuwPack All American 6519 Posts user info edit post |
yea dude, i say go with matlab over maple also 4/9/2006 3:46:57 AM |
clalias All American 1580 Posts user info edit post |
Wait, I just remembered, if you are coding in c++ just use the gsl library. Here is the specific library you want to use.
http://www.gnu.org/software/gsl/manual/gsl-ref_34.html#SEC457
and a link to the main page http://www.gnu.org/software/gsl/
If you are coding in FORTRAN look for the MINPACK Library http://www.utoronto.ca/cat/services/services_other/fortranB.html
Matlab still might be better though--you can set options on the type of solver etc... I would just recode in matlab or learn to call matlab/add matlab library if the gsl library is not an option(e.g. doesn't work for you or you're limited to visual studio etc...)
If you have any specific matlab questions I can try to help.
[Edited on April 9, 2006 at 1:24 PM. Reason : MINPACK] 4/9/2006 1:20:43 PM |
LimpyNuts All American 16859 Posts user info edit post |
It's in Visual Basic. The gsl library says it uses Newtonian iterations, which is what I'm doing (though I'm sure their methods are better than I am because I don't understand any of the methods to increase the radius of convergence).
I'll look into MATLAB I guess. 4/9/2006 2:27:36 PM |