Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a self-contained program to apply Newton\'s method to the equation x3 + 2x

ID: 1892007 • Letter: W

Question

Write a self-contained program to apply Newton's method to the equation x3 + 2x2 + 10x = 2, starting with x0 = 2. Evaluate the appropriate f(x) and f'(x) using nested multiplication (recall that we call Newton's method with nested multiplication Horner's method). The simplest way to do this will be to implement the algorithm described in the table with columns of bn and cn, last week in class. This will yield b0 and C1 which go into Newton's method. Stop the computation when two successive points differ by 1/2 x 10-5. Print all intermediate points and function values (a plot of both bn and cn for each iteration of Newton's along with your resulting root estimates Pk is sufficient). Put an upper limit of ten on the number of steps. If you are looking to conserve paper, you could plot bn and cn on of each iteration in the same figure with different colors and/or symbols.

Explanation / Answer

! --------------------------------------------------------------- ! This program contains a function MySqrt() that uses Newton's ! method to find the square root of a positive number. This is ! an iterative method and the program keeps generating better ! approximation of the square root until two successive ! approximations have a distance less than the specified tolerance. ! --------------------------------------------------------------- PROGRAM SquareRoot IMPLICIT NONE REAL :: Begin, End, Step REAL :: x, SQRTx, MySQRTx, Error READ(*,*) Begin, End, Step ! read in init, final and step x = Begin ! x starts with the init value DO IF (x > End) EXIT ! exit if x > the final value SQRTx = SQRT(x) ! find square root with SQRT() MySQRTx = MySqrt(x) ! do the same with my sqrt() Error = ABS(SQRTx - MySQRTx) ! compute the absolute error WRITE(*,*) x, SQRTx, MySQRTx, Error ! display the results x = x + Step ! move on to the next value END DO CONTAINS ! --------------------------------------------------------------- ! REAL FUNCTION MySqrt() ! This function uses Newton's method to compute an approximate ! of a positive number. If the input value is zero, then zero is ! returned immediately. For convenience, the absolute value of ! the input is used rather than kill the program when the input ! is negative. ! --------------------------------------------------------------- REAL FUNCTION MySqrt(Input) IMPLICIT NONE REAL, INTENT(IN) :: Input REAL :: X, NewX REAL, PARAMETER :: Tolerance = 0.00001 IF (Input == 0.0) THEN ! if the input is zero MySqrt = 0.0 ! returns zero ELSE ! otherwise, X = ABS(Input) ! use absolute value DO ! for each iteration NewX = 0.5*(X + Input/X) ! compute a new approximation IF (ABS(X - NewX)
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote