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

• Fortran
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:
parameter (np=100)
parameter (eps=1e-3)
real a(np) ,b(np),c(np)
real r ,s ,ri,si
integer n,i

write(*,*)'n,r,s'

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

10 ri=r
si=s
b(n+1)=a(n+1)
b(n)=a(n)+r*b(n+1)
do i=n-1,1,-1
b(i)=a(i)+r*b(i+1)+s*b(i+2)
end do

c(n+1)=b(n+1)
c(n)=b(n)+r*c(n+1)
do i=n-1,1,-1
c(i)=b(i)+r*c(i+1)+s*c(i+2)
end do

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

write(*,*)

d=c(3)*c(3)-c(2)*c(4)
r=r-(1./d)*(c(3)*b(2)-c(4)*b(1))
s=s-(1./d)*(-c(2)*b(2)+c(3)*b(1))

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

end

Last edited by a moderator:

FactChecker
Gold Member
Have you run an example problem with known intermediate values and checked them? If so, where do they start to disagree?

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.

Mark44
Mentor
You have extra spaces in the following code:
I don't believe this makes any difference whatsoever.

DrClaude
aphirst
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
?

jtbell
Mentor
I hope that after more than three months, moebot has gotten his code to work...

I hope that after more than three months, moebot has gotten his code to work...
hahaha, i am doing my second degree now, and i just remembered this, thanks alot for the help.

p.s i got the code to work ! haha

jtbell and Tom.G