HP Forums
Difference between fsolve and nSolve? [CAS] - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Difference between fsolve and nSolve? [CAS] (/thread-3561.html)



Difference between fsolve and nSolve? [CAS] - mandresve - 04-05-2015 08:26 PM

Hi to everyone...

Recently I had a conflict understanding the fsolve and nSolve functions in my Prime.

I wonder what is the difference between them? in the catalog's description, the explanation for both functions appears exactly the same. When I solve a function for x (or whatever numeric constant/var), sometimes it works better with nSolve than fsolve, of course, entering the required parameters for each command to its solution.

I will be very grateful if someone give me examples of cases in which I can or cannot use fsolve and in which types of equations is best to use nSolve.

Thank you very much.

Edit:
If I specify the range of solution that I hope to get (within the fsolve command) I finally get the same response that gives me nSolve, for example using the range 0 to infinity. What is the idea of having two commands? Isn't supposed that if I miss optional fsolve arguments the command must evaluate the expression in any interval? (obviously the guess/interval and the solution method are optional within fsolve). According to my understanding, XCAS documentation shows that fsolve and nSolve commands do exactly the same.


RE: Difference between fsolve and nSolve? [CAS] - John Colvin - 04-06-2015 07:25 PM

(04-05-2015 08:26 PM)mandresve Wrote:  Hi to everyone...

Recently I had a conflict understanding the fsolve and nSolve functions in my Prime.

I wonder what is the difference between them? in the catalog's description, the explanation for both functions appears exactly the same. When I solve a function for x (or whatever numeric constant/var), sometimes it works better with nSolve than fsolve, of course, entering the required parameters for each command to its solution.

I will be very grateful if someone give me examples of cases in which I can or cannot use fsolve and in which types of equations is best to use nSolve.

Thank you very much.

Edit:
If I specify the range of solution that I hope to get (within the fsolve command) I finally get the same response that gives me nSolve, for example using the range 0 to infinity. What is the idea of having two commands? Isn't supposed that if I miss optional fsolve arguments the command must evaluate the expression in any interval? (obviously the guess/interval and the solution method are optional within fsolve). According to my understanding, XCAS documentation shows that fsolve and nSolve commands do exactly the same.

According to the Prime Help, fsolve() takes an optional 4th argument that specifies an iterative algorithm for solving the equation. Otherwise both nsolve and fsolve appear to do the same thing.


RE: Difference between fsolve and nSolve? [CAS] - mandresve - 04-07-2015 03:07 AM

(04-06-2015 07:25 PM)John Colvin Wrote:  According to the Prime Help, fsolve() takes an optional 4th argument that specifies an iterative algorithm for solving the equation. Otherwise both nsolve and fsolve appear to do the same thing.

Thanks John, I totally agree with you. the problem is that even though both commands "do the same", it's sometimes better to use a command over the other, or vice versa, leading to a confusion for me. Did you look at the example I gave in the attached image? I don't know why fsolve not solve the equation in any interval unless I specify optional arguments.


RE: Difference between fsolve and nSolve? [CAS] - parisse - 04-07-2015 06:01 AM

fsolve is the native Giac/Xcas command, nSolve was just added for TI compatibility. fsolve is recommended because nSolve does not quote it's arguments and limited to Newton method, while fsolve can do bisection, polynomial recognition etc.


RE: Difference between fsolve and nSolve? [CAS] - Angus - 04-07-2015 08:20 AM

It doesn't explain though why fsolve finds no sollution if the optional parameters are left out. I think the op wondered why you have to add an expactation interval with fsolve. Am I right?


RE: Difference between fsolve and nSolve? [CAS] - parisse - 04-07-2015 10:49 AM

By default fsolve without guess does the change of variable x=tan(t), then bisection on -1.57..1.57. If the solution is outside this interval it can not be reached, therefore nothing is returned.
nSolve calls Newton with default initial guess to 0, in this case it seems to be convergent.
It is important to understand that one should always give an initial guess or interval to a numeric solver. An algorithm can not always guess for you, the user is in the best position to provide an initial guess (with the help of a plot or because you know the interesting range of values of your parameters).


RE: Difference between fsolve and nSolve? [CAS] - Angus - 04-07-2015 11:22 AM

Thank you. Good explanation.
Providing initial guesses means more keystrokes which is inconvenient with a keyboard like the prime... Maybe a function to add a default interval to fsolve calls would be worth a thoght. However - verifying the results remains important. You could surely impress some students by showing the limitations of a tool liek the prime. Others could be more baffled.


edit:

Just one more question about the possible methods. In the help they are not specified in detail. e.g. 1==bisect, 2==Newton or so. Can you give information on that? Thanks!!


RE: Difference between fsolve and nSolve? [CAS] - parisse - 04-07-2015 01:02 PM

The following methods are recognized by Xcas
bisection_solver
newton_solver
falsepos_solver
secant_solver
steffension_solver
brent_solver
but they are not relevant for the Prime (only the two first are implemented), and the method is choosed by the guess format (one number=Newton, interval=bisection)


RE: Difference between fsolve and nSolve? [CAS] - mandresve - 04-08-2015 02:19 AM

Oh, I'm so grateful to all of you for these valuable answers. I learned a lot about this in these few days have passed. Thousand thanks. Now everything is very clear to me.


RE: Difference between fsolve and nSolve? [CAS] - leprechaun - 04-08-2015 10:57 AM

Do I understand correctly that the last optional argument given in the help is ignored in the prime and only an implied information? You can add a last optional argument like parisse listed. Is it ignored?
Maybe we could rewrite the info? Anyway thanks good Support!