Post Reply 
Bug in fsolve()?
09-09-2015, 09:28 AM
Post: #1
Bug in fsolve()?
Hello, I got my new HP Prime yesterday. It is my first graphing calculaor and I love it. But I think I found a bug in tha CAS using fsolve().
I posted this issue on another forum yet, but it seems there aren't that much active users. So I found this place here.
I wanted to look for the limits of the calculator and typed in some pointless stuff.
What I endet up was:
fsolve(SIN(x)=0.05*x+1,x,(-50)..50)
= -39.5 -38.9 -33.8.........
This line seems to work fine and it shows me all the intersections.

If I enter this line there are some missing.
fsolve(SIN(x)=0.05*x+1,x,(-200)..100)
= -33.8........

But if I keep increaseing the range some of the missing intersections do appear again.
fsolve(SIN(x)=0.05*x+1,x,(-200)..200)
= -39.5 -38.9 -33.8.......

So some results seem to disappear. The calculator does not set any limits to the range.
Might this could be fixed pretty easily. I guss using the programming feature it would be possible to write a programm which splits the entered range in small parts and does the fsolve() function for with those parts. Maybe it should check how many results there are in one of those parts and make even smaller parts if there are too much. I already tried to do something like this but somehow I did not got the fsolve() function running. Are all of the CAS features supported in the programming editor?
Is there a certain way how to enter them?

Hopefully someone can help me out. I am used to program microcontrollers in assembler or C. So I hope my idea isn't totally unrealistic but I have no experience in HP PPL yet. Sorry if my english skills are not that perfect. It is not my native language.

Greetings
Find all posts by this user
Quote this message in a reply
09-09-2015, 03:32 PM
Post: #2
RE: Bug in fsolve()?
Clearly, no positive roots exist for this function, and no negative roots less than -40 or so, so why keep expanding the search bracket?

fsolve() works fine with limits specified as -50 and 0.

No matter what algorithm you choose, numerical root finding depends to a high degree on your starting guesses.
Find all posts by this user
Quote this message in a reply
09-09-2015, 03:42 PM
Post: #3
RE: Bug in fsolve()?
Hello,

*Note that what I'm going to write is not perfect or exact - I've tried to simplify for easier understanding.*

This is not a bug, but rather a limit on mathematics and numerical algorithms in general. If you could create an algorithm that could absolutely find roots or points of intersections between multiple functions *exactly* and ensure that every single one was found without exception - you'd probably win a Nobel prize.

The issue is that as a human we can easily look at something and say "I see 10 solutions when I plot this or think about it critically". For a computer though, that is exceptionally difficult in a generic way. While there are certain cases for which there *is* a way to ensure you capture every solution or root, there is in essence an infinite number of other possibilities for which it is not possible.

What is happening with the fsolve command is:
1. It looks at your input and determines if it does know a mathematical algorithm that can exactly find every root/solution.
2. If it is not one of those, it looks at the range you've specified and tries to determine how to subdivide to begin looking for results.
3. Using those subdivisions, it tries to find the roots closest to the input.

I think you can spot a problem now which explains why you see different results. When you've specified a range that is well outside the location where the results lie, a large number of the "intervals" it is using as guesses fall outside that location. It ends up not being able to find those. The computer which cannot *think* just blindly follows the directions and must have stopping points else it would attempt to run infinitely.

Why not just make more guesses though? Well, that would be one solution. The problem is that numbers and math is infinitely dense. No matter how many more "starting points" you used, I would be able to create another example for which the result was not found. It becomes a balance of time/power in how long you should continue looking. The solution is smarter algorithms...unfortunately one that will function perfectly for all situations hasn't been created yet.

Other calculators will handle this in a different way. For example, they might pop up a warning that says "Hey, more solutions might exist". Or they might only give you 1 result.

Basically, you can't assume that *ANY* math software is magic bullet that will always give you the result perfectly. Human brains are amazing things and we need to make sure to keep ours turned on and thinking! :-)

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
09-10-2015, 07:12 PM
Post: #4
RE: Bug in fsolve()?
Hello,
thank you both for your great explanation. Well I think I got the problem now.

(09-09-2015 03:42 PM)Tim Wessman Wrote:  Other calculators will handle this in a different way. For example, they might pop up a warning that says "Hey, more solutions might exist".

This ist an idea I would appreciate. A warning like this would make some things a bit easier to understand.

Greetings
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)