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

In summary, bairstow's method is to use Newton-Raphson in a subroutine and he doesn't know what's wrong; he keeps getting the wrong answer.
  • #1
moebot
5
2
this is bairstow's method , i need to put Newton-raphson in a subroutine and i don't know what's 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'
read(*,*)n,r,s

    do i=n+1,1,-1
write(*,*)'a(i)'
read(*,*) 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


thanks in advance :)
 
Last edited by a moderator:
Technology news on Phys.org
  • #2
Have you run an example problem with known intermediate values and checked them? If so, where do they start to disagree?
 
  • #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.
 
  • #4
magoo said:
You have extra spaces in the following code:
I don't believe this makes any difference whatsoever.
 
  • Like
Likes DrClaude
  • #5
@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
?
 
  • #6
I hope that after more than three months, moebot has gotten his code to work...
 
  • #7
jtbell said:
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 a lot for the help.

p.s i got the code to work ! haha
 
  • Like
  • Haha
Likes jtbell and Tom.G

1. What is Bairstow's method?

Bairstow's method is a numerical algorithm used to find the roots of a polynomial equation. It is a modification of the Newton-Raphson method and is particularly useful for finding complex roots.

2. How does Bairstow's method work?

Bairstow's method works by approximating the polynomial equation as a product of two quadratic factors. These factors are then iteratively updated using the Newton-Raphson method until the roots of the polynomial are determined.

3. What is the Newton-Raphson method?

The Newton-Raphson method is a numerical algorithm used to find the roots of a function. It works by making an initial guess for the root and then using the slope of the function at that point to iteratively refine the guess until the root is found.

4. How is Bairstow's method different from the Newton-Raphson method?

Bairstow's method is a modification of the Newton-Raphson method that is specifically designed for finding the roots of polynomial equations. It works by approximating the polynomial as a product of two quadratic factors, while the Newton-Raphson method works directly with the function itself.

5. When is Bairstow's method most useful?

Bairstow's method is most useful when dealing with polynomial equations that have complex roots. It is also useful when the polynomial has multiple roots, as it can find all of the roots simultaneously. However, it may not be as efficient as other methods for finding simple roots.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
12
Views
967
Replies
9
Views
1K
  • Programming and Computer Science
Replies
1
Views
752
  • Programming and Computer Science
Replies
1
Views
945
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
4
Views
621
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
2
Views
945
Back
Top