Author Topic: an alternative to the "solve(" command  (Read 5269 times)

0 Members and 2 Guests are viewing this topic.

Offline rthprog

  • LV2 Member (Next: 40)
  • **
  • Posts: 29
  • Rating: +5/-0
    • View Profile
an alternative to the "solve(" command
« on: March 12, 2010, 12:19:34 pm »
The "solve(" command is a pretty efficient way to find the root of an unknown equation. Unfortunately, it only works if you have a good guess; otherwise, you'll be plagued by "Bad guess" errors which may cause your program to crash. To guarantee that your user doesn't encounter such an error, create a routine that uses Newton's method to perform the same function as the "solve(" command, except with safeguards for bad guesses.

Here's a routine that, given an equation (in terms of X) stored to Y1, and a guess stored to "G", will solve for "X" when the equation in Y1 = 0. Essentially, it does the same thing as "solve(Y1,X,G"

   
Code: [Select]
:DelVar R
    :G
    :Repeat Ans=X and R
    :Ans→X
    :R+1→R
    :nDeriv(Y1,X,X
    :If Ans
    :X-Y1/Ans
    :If R>50
    :X
    :End
    :Ans→X
    :If not(Y1
    :X

http://rthprogcode.blogspot.com/2010/03/tibasic-alternative-to-solve-command.html

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: an alternative to the "solve(" command
« Reply #1 on: March 12, 2010, 05:51:12 pm »
Mhmm interesting ^^ altough I never really used solve( myself, because back wehn I had math classes (graduated in 2003), we did little usage of calcs anymore. We used Y= menu like 3 times in an entire school year x.x

Hopefully this might be useful for some people,  though