math - How to find the square root using the Newton-Raphson Method in fortran 90 -
i need write program find square root using newton-raphson method using guess estimate. equation newton-raphson method is:
xn+1 = xn-xn**2 − a/2*xn   whereby n number of iterations.
the assignment tells me loop should performed between 1 , total number of specified iterations. , each step of loop, current value of ‘solution’ should used calculate next value of solution, in form specified equation.
hint: remember, assignment of value variable evaluates right side of equals before performing assignment itself. means 1 variable x needed calculate each new value; don’t need ‘old_x’ , ‘new_x’ or similar.
this have far:
program assign_10_2 implicit none  real :: a, b, x integer :: c, i, j    write(*,*) 'please enter value determine square root of' read(*,*) write(*,*) 'please enter value use initial guess solution' read(*,*) b write(*,*) 'please enter value how many iterations should perform calculate value' read(*,*) c write(*,*) a, b , c   i= 1, c, 1  x = b-((b**2-a)/2*b) write(*,*)  i, x end  end program assign_10_2   i no means asking answer push in right direction new programming , confusing me. know have done wrong regards equation.
this line wrong:
x = b-((b**2-a)/2*b)   b initial guess. don't want keep going initial guess, want use previous value of x computed. should not write /2*x if want divide 2*x. think want following assignment instead:
x = x - ((x**2-a)/(2*x))      
Comments
Post a Comment