Opaque functions and fsolve / numerical methods

04072021, 08:34 PM
Post: #1




Opaque functions and fsolve / numerical methods
Suppose I have an opaque f(x) on the reals. By "opaque" I mean, we don't peek at the function definition, we rely on evaluating it at specific reals. For the sake of example here is a definition to (not) peek at
Code: EXPORT OPAQUE(I) BEGIN Code:
Unsurprisingly, we cannot symbolically solve equations like OPAQUE(x)==9. But perhaps surprising, we cannot solve numerically either: Code:
The latter might be because of another annoyance, the function cannot be evaluated with subst: Code:
I suppose I can solve this graphically, but is there a more practical way to use the numerical methods than with fsolve? My theory is it's trying to pass some CAS type into function input and see if it can exploit the definition of OPAQUE somehow. However, since the function doesn't have a CAS "definition" the nonreal input is a "Bad argument type". But it's a mystery how to force the real input from a numerical solver... 

04072021, 10:59 PM
(This post was last modified: 04072021 11:18 PM by roadrunner.)
Post: #2




RE: Opaque functions and fsolve / numerical methods
If you make it a CAS function:
#cas opaque(i):= BEGIN IFTE(i>3,i,i*3+6/5); END; #end then in CAS fsolve((opaque(x)) = 9,x) returns: [2.6,9.] 

04082021, 04:54 AM
Post: #3




RE: Opaque functions and fsolve / numerical methods
How did you figure that out? I can't find a reference to "CAS functions" in the manual nor to the "#cas" statement (...directive?) I was able to turn up a few forum threads but mostly discussing syntax and not really any differences in the programming model or why to prefer one vs the other.
I also found FNROOT, which seems like a noncas version of fsolve. I guess it makes some sense to use like functions with like, but I'm fuzzy on how cas/noncas actually differ in their programming model or typesystem. My intuition was that a numerical solver would want to operate on numbers and not symbolic representations, but it seems for fsolve this is not the case... 

04082021, 12:03 PM
(This post was last modified: 04082021 12:21 PM by roadrunner.)
Post: #4




RE: Opaque functions and fsolve / numerical methods
(04082021 04:54 AM)compaqdrew Wrote: How did you figure that out? I guess just from reading this forum for the last gillion years or so. fsolve uses bisection and i believe it does do numerical solutions; i think CAS just solves the equation differently and sends that to fsolve. Maybe the prime gurus can chime in on that one. Because bisection usually doesn't like discontinuities I was surprised fsolve found both solutions separated by one. In general you will probably have to give it a range to search in that avoids discontinuities. road 

« Next Oldest  Next Newest »

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