Post Reply 
Difference between fsolve and nSolve? [CAS]
04-05-2015, 08:26 PM (This post was last modified: 04-07-2015 03:09 AM by mandresve.)
Post: #1
Difference between fsolve and nSolve? [CAS]
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.


Attached File(s) Thumbnail(s)
       

Success is the ability to go from one failure to the next without any loss of enthusiasm.
View PNG/JPG in your Prime
Visit this user's website Find all posts by this user
Quote this message in a reply
04-06-2015, 07:25 PM
Post: #2
RE: Difference between fsolve and nSolve? [CAS]
(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.
Find all posts by this user
Quote this message in a reply
04-07-2015, 03:07 AM (This post was last modified: 04-07-2015 03:08 AM by mandresve.)
Post: #3
RE: Difference between fsolve and nSolve? [CAS]
(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.

Success is the ability to go from one failure to the next without any loss of enthusiasm.
View PNG/JPG in your Prime
Visit this user's website Find all posts by this user
Quote this message in a reply
04-07-2015, 06:01 AM
Post: #4
RE: Difference between fsolve and nSolve? [CAS]
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.
Find all posts by this user
Quote this message in a reply
04-07-2015, 08:20 AM
Post: #5
RE: Difference between fsolve and nSolve? [CAS]
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?
Find all posts by this user
Quote this message in a reply
04-07-2015, 10:49 AM
Post: #6
RE: Difference between fsolve and nSolve? [CAS]
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).
Find all posts by this user
Quote this message in a reply
04-07-2015, 11:22 AM (This post was last modified: 04-07-2015 11:34 AM by Angus.)
Post: #7
RE: Difference between fsolve and nSolve? [CAS]
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!!
Find all posts by this user
Quote this message in a reply
04-07-2015, 01:02 PM
Post: #8
RE: Difference between fsolve and nSolve? [CAS]
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)
Find all posts by this user
Quote this message in a reply
04-08-2015, 02:19 AM
Post: #9
RE: Difference between fsolve and nSolve? [CAS]
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.

Success is the ability to go from one failure to the next without any loss of enthusiasm.
View PNG/JPG in your Prime
Visit this user's website Find all posts by this user
Quote this message in a reply
04-08-2015, 10:57 AM
Post: #10
RE: Difference between fsolve and nSolve? [CAS]
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!
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: