Newton's Method
|
01-17-2014, 09:45 PM
Post: #1
|
|||
|
|||
Newton's Method
Newton's Method computes the root of a function \( f(x) \) using linear approximations of \( f(x) \) via tangent lines. The formula is
\[ x_{new} = x_{old} - \frac{f(x_{old})}{f'(x_{old})} \] We use F1 to store the formula for \( f(X) \) (note the capital letter for \( X \) ), and F0 to set up a formula for the right hand side. CAS computations currently do not recognize local variables. And global variables are generally evaluated during parsing in a program, since the programs run in the Home view. This causes some issues with passing values and expressions to CAS commands. In the Home view, a symbolic expression is surrounded by single-quotes. So in the first example, we create a symbolic expression and "insert" other symbolic expressions (such as the derivative of a function) by using strings. In the later examples, we pass a single string to the CAS command, which parses the string as if typed from the CAS command line. Since the CAS recognizes functional algebra, we create a formula for F0 by simply operating on the functions themselves (the term id is the identity function \( id(x)=x \)) and completely ignore the dummy variables. Since our desired formula is \[ F0(x):= x - \frac{F1(x)}{F1'(x)} \] then the equivalent function using functional algebra is \[ F0 := id - \frac{F1}{F1'} \] Style 1: Initial attempt as a solution to a specific problem. The function is pre-stored into F1 in the Function App. The user then runs the command NEWT() from the command line, or from the program catalog, or from the [Toolbox] menu (press the "User" menu option). Code:
Syle 2: Creating a user interface The INPUT() command is used to allow the user to enter their formula, rather than having it already pre-stored in F1. Code:
Style 3: Function-like command This style uses functional notation to send inputs to the command NEWT3(). Due to how variables are initialized, this command must be run from the command line. Otherwise, the built-in input screen will prompt for the arguments, and only accept real-valued inputs, and an algebraic expression cannot be entered for f. Usage: NEWT3("X^2-5", 2.1, .0001, 100); Code:
Style 4: Mix of Style 1 and 3 Usage: Place formula into F1 in the Function App, and run the program NEWT3 either from the command line, the program catalog, or the [Toolbox] interface. Code:
REMARKS: A more user-friendly program would actually preserve the existing formula for F0, if it exists, and restore it so that the user does not lose their previously stored formulas after running our program. To do this, one could implement: Code:
The error trap is to account for the possibility that there may be no pre-existing F0 formula. We restore the user's old F0 formula by simply using: Code:
Fortunately, this works even if oldfunc is an empty string. Graph 3D | QPI | SolveSys |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Newton's Method - Han - 01-17-2014 09:45 PM
RE: Newton's Method - FrankiD - 03-29-2014, 06:29 PM
RE: Newton's Method - Han - 03-30-2014, 01:47 AM
RE: Newton's Method - FrankiD - 03-30-2014, 02:45 AM
RE: Newton's Method - Han - 03-30-2014, 02:08 PM
RE: Newton's Method - FrankiD - 03-30-2014, 06:25 PM
RE: Newton's Method - Han - 04-07-2014, 07:47 PM
RE: Newton's Method - Snorre - 01-10-2015, 09:52 PM
RE: Newton's Method - Han - 01-10-2015, 11:01 PM
RE: Newton's Method - Gene222 - 09-11-2023, 11:29 PM
|
User(s) browsing this thread: 1 Guest(s)