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

Do While loop to recognize to stop running when solution is zero. (Fortran90). C

ID: 3567296 • Letter: D

Question

Do While loop to recognize to stop running when solution is zero. (Fortran90). Currently, this is what the program prints out:

This is what our program looks like:

Do While loop to recognize to stop running when solution is zero. (Fortran90). Currently, this is what the program prints out: This is what our program looks like: Currently the implementation of Newton½s method iterates 10 times which is too much for some functions and too little for others. We need to modify the program so that it iterates until the quantity (Eabs.)n+1=|xn+1?xn|, approximating the absolute error, is less then 10?15. It is probably easiest to do this by changing the do loop to a do-while loop. ANY HELP WOULD BE MUCH APPRECIATED THANK YOU!

Explanation / Answer

! I hope this works. I have changed the loop condition ... the condition you mentioned in questions is not clear

! yet i guess it is abs(xn -xn+1) < 10d-15

program newton

implicit none
double precision :: f,fp,x,dx,xold
integer :: iter
iter=0
x = -0.5d0

do while (abs(x-xold)>10d-15)
xold=x
f = ffun(x)
fp = fpfun(x)
dx = -f/fp
x = x + dx
iter = iter +1
write(*,'(I2.2,2(E24.16))') iter,x,dx
end do

contains

double precision function ffun(x)
implicit none
double precision :: x

ffun = x*x*x + exp(x)

end function ffun

double precision function fpfun(x)
implicit none
double precision :: x

fpfun = 1.d0 + exp(x)

end function fpfun

end program newton

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