bigdawg New Recruit 32 Posts user info edit post |
program bisection implicit none character::choice real::lower, upper write(*,*)"************************************" write(*,*)"* F. f(x) = x^3 - 3*x +1 *" write(*,*)"* G. f(x) = x^2 - 1 *" write(*,*)"* H. f(x) = x^3 *" write(*,*)"* I. f(x) = x + 1 *" write(*,*)"* J. f(x) = x^2 + 2x *" write(*,*)"* K. f(x) = x^3 + 3x^2 + 3x + 3 *" write(*,*)"* x. Main Menu *" write(*,*)"************************************" write(*,*)"Make a selection from the menu." read(*,*)Choice write(*,*)"Enter the lower bound" read(*,*)lower write(*,*)"Enter the upper bound" read(*,*)upper write(*,*)"Iteration Case(f,F) REAL FUNCTION f(x) IMPLICIT NONE REAL,INTENT(IN):: x f = x^3-3*x+1 call root END FUNCTION Case(g,G) REAL FUNCTION f(x) IMPLICIT NONE REAL,INTENT(IN):: x f = x**2-1 call root END FUNCTION case(h,H) REAL FUNCTION f(x) IMPLICIT NONE REAL,INTENT(IN):: x f = x**3 call root END FUNCTION Case(i,I) REAL FUNCTION f(x) IMPLICIT NONE REAL,INTENT(IN):: x f = x + 1 call root END FUNCTION case(j,J) REAL FUNCTION f(x) IMPLICIT NONE REAL,INTENT(IN):: x f = x**2 + 2*x + 2 call root END FUNCTION Case(k,K) REAL FUNCTION f(x) IMPLICIT NONE REAL,INTENT(IN):: x f = x**3 + 3*x**2 + 3*x + 3 call root END FUNCTION case(x,X) stop end program bisection RECURSIVE SUBROUTINE root(f,answer) IMPLICIT NONE
real, INTENT(in)::f real, INTENT(out)::answer real::lower,upper 11/10/2005 2:36:33 PM |
bigdawg New Recruit 32 Posts user info edit post |
this is what the program is suppose to do
Program Definition: ! Write a FORTRAN program that finds the root of a function between ! two bounds defined by the user using the method of recursive ! bisection. ! ! You can only use Bisection if you assume that there is only 1 ! root between the upper and lower bounds. Given a function that ! crosses the x axis only once between the upper and lower bounds, ! the root can be found by bisecting the interval between the ! bounds and testing the bisection point for which side of the x ! axis f(x) lies on. If the value at the lower bound f(lb) is ! of the same sign as f(x), then the new lower bound would be x. ! Likewise, if the value of the upper bound f(ub) is of the same ! sign as f(x), then the new upper bound would be x. ! ! This process can be accomplished through a DO loop and through ! recursion. To understand the problem better, you may want to code ! the problem using a DO loop first and then code it using ! recursion. Let the root be located at the point where ! abs(f(x)) <0.5E-6 ! ! Enable the program to find the roots for the 6 equations below ! using a menu. ! ! ******************************************* ! * F. f(x) = x^3 - 3*x + 1 * ! * G. f(x) = x^2 - 1 * ! * H. f(x) = x^3 * ! * I. f(x) = x + 1 * ! * J. f(x) = x^2 + 2x * ! * K. f(x) = x^3 + 3x^2 + 3x + 3 * ! * * ! * X. Main Menu * ! ******************************************* 11/10/2005 3:57:29 PM |