Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran I need help in Fortran please -- Bairstow's method & Newton-Raphson

  1. Nov 26, 2016 #1
    this is bairstow's method , i need to put newton-raphson in a subroutine and i don't know whats wrong i keep getting the wrong answer when i execute please help

    Code (Text):

    parameter (np=100)
    parameter (eps=1e-3)
    real a(np) ,b(np),c(np)
    real r ,s ,ri,si  
    integer n,i


        do i=n+1,1,-1
    read(*,*) a(i)
    end do

    10 ri=r
       do i=n-1,1,-1
       end do

       do i=n-1,1,-1
       end do

       do i=n+1,1,-1
       write(*,*) i,a(i),b(i),c(i)
       end do

       if(sqrt(ri**2-r**2).ge.eps.or.sqrt(si**2-s**2).ge.eps)    goto 10
       write(*,*) r,s


    thanks in advance :)
    Last edited by a moderator: Nov 26, 2016
  2. jcsd
  3. Nov 26, 2016 #2


    User Avatar
    Science Advisor
    Gold Member
    2017 Award

    Have you run an example problem with known intermediate values and checked them? If so, where do they start to disagree?
  4. Jan 10, 2017 #3
    You have extra spaces in the following code:

    real a(np) ,b(np),c(np)
    real r ,s ,ri,si

    I haven't used Fortran in many years, but I would make sure the unnecessary spaces are deleted and that you have spaces after the commas.
  5. Jan 11, 2017 #4


    Staff: Mentor

    I don't believe this makes any difference whatsoever.
  6. Mar 8, 2017 #5


    User Avatar
    Gold Member

    @moebot Are you able to provide some comments to your code, such as
    • What the equation is, whose root(s) you're trying to find
    • What you are intending each section of code to do
    • Why you're writing in F77 (fixed) style with GOTOs instead of loops
  7. Mar 8, 2017 #6


    User Avatar

    Staff: Mentor

    I hope that after more than three months, moebot has gotten his code to work...
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted