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

Objective: Write a program to calculate the root of a function using Newton’s Me

ID: 3629346 • Letter: O

Question



Objective: Write a
program to calculate the root of a function using Newton’s Method.



General Comments: Make sure the program follows the programming
practices discussed in class. The copy of program turned in must be compiled
using Silverfrost. Use subroutines to calculate the values of the functions
used in the root finding method. Format screen outputs for neatness and
clarity.



Program Description & Requirements:



The program needs to calculate the value of x needed to satisfy y=g(x)
using Newton’s Method where y is specified by the user. The function g(x) is
predefined and showed below.



y=g(x)=0.093x^3 0.2x^2 +10x 30



Specifically the program must do the following:



i) Write the equation g(x) to the screen and inform the user
this is the function being solved.



ii) Request from the user the value of y for which x will be
solved for. User will input the value from the screen.



iii) Request from the user an initial guess of x. User will
input the value from the screen.



iv) Calculate the value of x needed to achieve y within a
tolerance of y±0.0001 using Newton’s Method.



v) To produce a code that can be easily modified to solve for
other equations, the functions f(x,y) and f’(x,y) needs to be contained within
a subroutine (see the below Note for definition of these functions).



vi) Write the value of x to the screen.



vii) Write the number of iterations required to reach the
solution to the screen

Explanation / Answer

Hi, Here is the program,,,, real*8 X(0:10), Y(0:10) real*8 b1,b2,e,u,v,u1,v1,u2,v2,u3,v3,x0,y0,xx,yy,x4,y4,z1,z2 integer i,j1,k,m,n,n2,n3 print *,' ' print *,'Input the initial guesses and their bounds:' print *,' ' write(*,"(' X0 = ')",advance='no') read *, x0 write(*,"(' Bond on X0 = ')",advance='no') read *, b1 write(*,"(' Y0 = ')",advance='no') read *, y0 write(*,"(' Bond on Y0 = ')",advance='no') read *, b2 print *,' ' write(*,"(' Convergence criterion: ')",advance='no') read *, e write(*,"(' Maximum number of iterations: ')",advance='no') read *, n write(*,"(' How many roots are to be sought: ')",advance='no') read *, n2 print *,'Is the function defined in Eval (1)' write(*,"(' or is it a series (2): ')",advance='no') read *, n3 call AllRoot(x0,y0,b1,b2,e,n,n2,n3,X,Y,k) !Call complex domain Allroot subroutine print *,' ' print *,'The estimated roots are:' print *,' ' do i=1, n2 write(*,50) X(i) write(*,60) Y(i) end do write(*,70) k stop 50 format(' X = ',f9.6) 60 format(' Y = ',f9.6/) 70 format(' The last number of iterations was: ',i3//) end ! Rectangular to polar conversion Subroutine RectPol(x, y, u, v) real*8 x,y,u,v,PI PI=4.d0*datan(1.d0) u=dsqrt(x*x+y*y); !Guard against ambiguous vector if (y.eq.0.d0) y=1.d-16 !Guard against divide by zero if (x.eq.0.d0) x=1.d-16 v=datan(y/x) !Check quadrant and adjust if (x