Real*8 Xold, Xnew, EPSILON

Real*8 Xold, Xnew, EPSILON

<p> CSE 1540.03 program Week9v2 Week 10.1 March 17, 2014 implicit none real*8 xold, xnew, EPSILON real*8 f, fprime parameter (EPSILON = 1.d-8) program Week9v1 implicit none read*, xold do real*8 xold, xnew, EPSILON xnew = xold - f(xold)/fprime(xold) parameter (EPSILON = 1.d-8) if (dabs(xnew-xold) .lt. EPSILON) exit xold = xnew read*, xold end do do print*, "x* = ", xnew xnew = xold - (xold*xold-1)/(2.d0*xold) if (dabs(xnew-xold) .lt. EPSILON) exit end xold = xnew end do real*8 function f (x) print*, "x* = ", xnew real*8 x f = x*x - 1 end return end</p><p> real*8 function fprime (x) real*8 x fprime = 2*x return end</p><p>CSE 1540 Week 10.1 – March 17, 2014 page 1 of 3 program Week9v3 program Week9v4 implicit none implicit none real*8 b, c, EPS real*8 x, EPSILON real*8 f integer status external f real*8 f, fprime integer status external f, fprime parameter (EPS = 1.d-8) parameter (EPSILON = 1.d-8) print*, "Enter (b,c) interval: " read*, x read*, b, c call dmyZero(f,fprime,x,EPSILON,status) call dfzero(f,b,c,b,EPS,EPS,status) print*, "x* = ", x print*, "x* = (", b, ",", c, ")" print*, "Status = ", status end end subroutine dmyZero (f,fprime,x,eps,iflag) real*8 function f (x) real*8 f, fprime, x, eps, xnew, xold real*8 x external f, fprime f = x*x - 1 integer iflag, i return end xold = x do i=1,100 xnew = xold - f(xold)/fprime(xold) if (dabs(xnew-xold) .lt. eps) then iflag = 1 x = xnew return end if xold = xnew end do iflag = 2 return end</p><p> real*8 function f (x) real*8 x f = x*x - 1 return end</p><p> real*8 function fprime (x) real*8 x fprime = 2*x return</p><p>CSE 1540 Week 10.1 – March 17, 2014 page 2 of 3 end program Week9v5 program Mortgage implicit none implicit none real*8 b, c, EPS integer n real*8 dbesj1 real*8 rold, rnew, A, P, EPSILON external dbesj1 real*8 f, fprime integer status parameter (EPSILON = 1.d-8) parameter (EPS = 1.d-8) read*, n, A, P print*, "Enter (b,c) interval: " read*, rold read*, b, c do call dfzero(dbesj1,b,c,b,EPS,EPS,status) rnew = rold - f(rold,n,A,P)/fprime(rold,n,A,P) print*, "x* = (", b, ",", c, ")" if (dabs(rnew-rold) .lt. EPSILON) exit print*, "Status = ", status rold = rnew end do end print*, "Interest Rate = ", rnew * 12</p><p> end</p><p> real*8 function f (r,n,A,P) real*8 r, A, P integer n f = 1.d0 – (1.d0 + r)**(-n) – A*r/P return end</p><p> real*8 function fprime (r,n,A,P) real*8 r, A, P integer n fprime = n*(1.d0 + r)**(-n-1) – A/P return end</p><p>CSE 1540 Week 10.1 – March 17, 2014 page 3 of 3</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    3 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us