Newton's method
|
12-27-2017, 03:41 AM
(This post was last modified: 12-27-2017 04:20 AM by Namir.)
Post: #1
|
|||
|
|||
Newton's method
This is a version of Newton's method for the HP Prime where you specify a string representing f(x), along with the initial guess for the root, and the tolerance value. Thus you can solve for different functions without having to hard code these functions in the RPL code. Here is the source code:
Code: EXPORT NEWTON(sfx, x, toler) Examples of using function NEWTON are: NEWTON("exp(x)-3*x^2",4,0.0000001) NEWTON("ln(100)-x",4,0.0000001) The code convert the string of the expression into lowercase to make sure it uses variable x in lowercase, to match the lowercase parameter x. Also, the code controls the number of iterations not to exceed 99. You can insert several function declarations with the above code and then pass a string containing the call to a particular function. For example, if we insert the following code before NEWTON: Code: EXPORT fx1(x) Then you can make the following calls: NEWTON("fx1(x),4,0.0000001) NEWTON("fx2(x)",4,0.0000001) Which give the same results as before. This approach allows you to insert a catalogue of functions you frequently work and then invoke the solution for their roots by specifying the function's name instead of its expression. In the case the function requires more than a single statement to calculate the result, then this approach is definitely the one to choose! If you comment out the statement that converts parameter sfx to lower case, then you can specify the Functions App's F0 through F9. Make sure that you use formats like "F1(x)" with the lowercase x. Enjoy! Namir |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Newton's method - Namir - 12-27-2017 03:41 AM
RE: Newton's method - Mark Power - 01-01-2018, 03:49 PM
|
User(s) browsing this thread: 1 Guest(s)