EBK NUMERICAL METHODS FOR ENGINEERS
EBK NUMERICAL METHODS FOR ENGINEERS
7th Edition
ISBN: 8220100254147
Author: Chapra
Publisher: MCG
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 7, Problem 9P

Use the program developed in Prob. 7.8 to determine the roots of the equations in Prob. 7.5.

Expert Solution & Answer
Check Mark
To determine

To calculate: Create a program for finding roots of polynomial equation using Bairstow’s method for the functions given below.

(a) f3(x)=0.7x34x2+6.2x2

(b) f4(x)=3.704x4+16.3x221.97x+9.34

(c) f4(x)=x42x3+6x22x+5

Answer to Problem 9P

Solution:

The roots for the Problem 7.5(a) are  3.2786, 2.0000, 0.4357.

The roots for the Problem 7.5(b) are  2.2947, 1.1525, 0.9535.

The roots for the Problem 7.5(c) are  1.0000+2.0000i, 1.0000-2.0000i, 0.0000+1.0000i,  0.0000-1.0000i.

Explanation of Solution

Given Information:

Finding the roots of the equation given in Problem 7.5.

Calculation:

Code for Problem 7.5(a):

OptionExplicit

SubPolynomialRoot()

Dim num AsInteger

DimmaxItrAsInteger,ierAsInteger,iAsInteger

Dimarr(10)AsDouble, real(10)AsDouble

Dimimaginary(10)AsDouble' Variable to provide negative or positive sign

Dim r AsDouble, s AsDouble, es AsDouble

'In example, the function is having 3 as highest power, so num is initialized to 3.

num =3

'Values of coefficients of the variables in function is given

arr(0) = -2: arr(1) = 6.2: arr(2) = -4: arr(3) = 0.7

'Maximum number of iterations are defined.

maxItr=20

es =0.0001

r =-1

s =-1

CallBairstow_method(arr(), num, es, r, s,maxItr, real(), imaginary(),ier)

'Loop will run to all the powers of function to assign sign between real and imaginary numbers.

Fori=1To num

' If the value at iteration is greater than or equal to 0, assign '+' sign.

If imaginary(i)>=0Then

MsgBox real(i)&" + "& imaginary(i)&"i"

' If the value at iteration is lesser than 0, assign '-' sign.

Else

MsgBox real(i)&" - "& Abs(imaginary(i))&"i"

EndIf

Nexti

EndSub

'method with arguments to apply bairstow method in function.

SubBairstow_method(arr,nn, es,rr, ss,maxItr, real, imaginary,ier)

DimiterAsInteger, num AsInteger,iAsInteger

Dim r AsDouble, s AsDouble, ea1 AsDouble, ea2 AsDouble

Dim determine AsDouble,drAsDouble, ds AsDouble

Dim r_1 AsDouble, i1 AsDouble, r_2 AsDouble, i2 AsDouble

Dimbrr(10)AsDouble,crr(10)AsDouble

' Assigning values.

r =rr

s = ss

num =nn

ier=0

ea1 =1

ea2 =1

Do

'Loop will get terminated if power is less than 3 or if iteration is equal to or greater than maximum iteration.

If num <3Oriter>=maxItrThenExitDo

iter=0

Do

'Incrementing iter variable by 1.

iter=iter+1

'assigning values of array into another array.

brr(num)=arr(num)

'Disc brr(num-1) is calculated.

brr(num -1)=arr(num -1)+ r *brr(num)

crr(num)=brr(num)

'Disc crr(num-1) is calculated.

crr(num -1)=brr(num -1)+ r *crr(num)

'Loop will run for powers less than 3 till power 0.

Fori= num -2To0Step-1

'Values of brr(i) and crr(i) are updated.

brr(i)=arr(i)+ r *brr(i+1)+ s *brr(i+2)

crr(i)=brr(i)+ r *crr(i+1)+ s *crr(i+2)

Nexti

determine =crr(2)*crr(2)-crr(3)*crr(1)

If determine <>0Then

dr=(-brr(1)*crr(2)+brr(0)*crr(3))/ determine

ds =(-brr(0)*crr(2)+brr(1)*crr(1))/ determine

r = r +dr

s = s + ds

'Values of ea1 and ea2 are determined for different values in loop .

If r <>0Then ea1 =Abs(dr/ r)*100

If s <>0Then ea2 =Abs(ds / s)*100

Else

' Incrementing r and s by 1.

r = r +1

s = s +1

iter=0

EndIf

' If the values of ea1 and ea2 are less than value of es or iterations are completed then loop will be terminated

If ea1 <= es And ea2 <= es Oriter>=maxItrThenExitDo

Loop

'method call to find quadratic roots.

CallQuadroot(r, s, r_1, i1, r_2, i2)

'Formulae to calculate real and imaginary values at the every term of function.

real(num)= r_1

imaginary(num)= i1

real(num -1)= r_2

imaginary(num -1)= i2

num = num -2

'Updating the coeffinents of function at every iteration.

Fori=0To num

arr(i)=brr(i+2)

Nexti

Loop

Ifiter<maxItrThen

If num =2Then

r =-arr(1)/arr(2)

s =-arr(0)/arr(2)

CallQuadroot(r, s, r_1, i1, r_2, i2)

'Use the values of i1, i2, r_1 and r_2 to determine real(num), imaginary(num), real(num-1) and imaginary(num-1).

real(num)= r_1

imaginary(num)= i1

real(num -1)= r_2

imaginary(num -1)= i2

Else

real(num)=-arr(0)/arr(1)

imaginary(num)=0

EndIf

Else

ier=1

EndIf

EndSub

SubQuadroot(r, s, r_1, i1, r_2, i2)

Dim Disc

'Value of Disc is calculated.

Disc = r ^2+4* s

'Condition for Disc>0.

If Disc >0Then

r_1 =(r +Sqr(Disc))/2

r_2 =(r -Sqr(Disc))/2

i1 =0

i2 =0

'Condition if Disc less than or equal to 0.

Else

r_1 = r /2

r_2 = r_1

i1 =Sqr(Abs(Disc))/2

i2 =-i1

EndIf

EndSub

Code for Problem 7.5(b):

OptionExplicit

SubPolynomialRoot()

Dim num AsInteger

DimmaxItrAsInteger,ierAsInteger,iAsInteger

Dimarr(10)AsDouble, real(10)AsDouble

Dimimaginary(10)AsDouble' Variable to provide negative or positive sign

Dim r AsDouble, s AsDouble, es AsDouble

'In example, the function is having 3 as highest power, so num is initialized to 3.

num =3

'Values of coefficients of the variables in function is given

arr(0) = 9.34: arr(1) = -21.97: arr(2) = 16.3: arr(3) = 3.704

'Maximum number of iterations are defined.

maxItr=20

es =0.0001

r =-1

s =-1

CallBairstow_method(arr(), num, es, r, s,maxItr, real(), imaginary(),ier)

'Loop will run to all the powers of function to assign sign between real and imaginary numbers.

Fori=1To num

' If the value at iteration is greater than or equal to 0, assign '+' sign.

If imaginary(i)>=0Then

MsgBox real(i)&" + "& imaginary(i)&"i"

' If the value at iteration is lesser than 0, assign '-' sign.

Else

MsgBox real(i)&" - "& Abs(imaginary(i))&"i"

EndIf

Nexti

EndSub

'method with arguments to apply bairstow method in function.

SubBairstow_method(arr,nn, es,rr, ss,maxItr, real, imaginary,ier)

DimiterAsInteger, num AsInteger,iAsInteger

Dim r AsDouble, s AsDouble, ea1 AsDouble, ea2 AsDouble

Dim determine AsDouble,drAsDouble, ds AsDouble

Dim r_1 AsDouble, i1 AsDouble, r_2 AsDouble, i2 AsDouble

Dimbrr(10)AsDouble,crr(10)AsDouble

' Assigning values.

r =rr

s = ss

num =nn

ier=0

ea1 =1

ea2 =1

Do

'Loop will get terminated if power is less than 3 or if iteration is equal to or greater than maximum iteration.

If num <3Oriter>=maxItrThenExitDo

iter=0

Do

'Incrementing iter variable by 1.

iter=iter+1

'assigning values of array into another array.

brr(num)=arr(num)

'Disc brr(num-1) is calculated.

brr(num -1)=arr(num -1)+ r *brr(num)

crr(num)=brr(num)

'Disc crr(num-1) is calculated.

crr(num -1)=brr(num -1)+ r *crr(num)

'Loop will run for powers less than 3 till power 0.

Fori= num -2To0Step-1

'Values of brr(i) and crr(i) are updated.

brr(i)=arr(i)+ r *brr(i+1)+ s *brr(i+2)

crr(i)=brr(i)+ r *crr(i+1)+ s *crr(i+2)

Nexti

determine =crr(2)*crr(2)-crr(3)*crr(1)

If determine <>0Then

dr=(-brr(1)*crr(2)+brr(0)*crr(3))/ determine

ds =(-brr(0)*crr(2)+brr(1)*crr(1))/ determine

r = r +dr

s = s + ds

'Values of ea1 and ea2 are determined for different values in loop .

If r <>0Then ea1 =Abs(dr/ r)*100

If s <>0Then ea2 =Abs(ds / s)*100

Else

' Incrementing r and s by 1.

r = r +1

s = s +1

iter=0

EndIf

' If the values of ea1 and ea2 are less than value of es or iterations are completed then loop will be terminated

If ea1 <= es And ea2 <= es Oriter>=maxItrThenExitDo

Loop

'method call to find quadratic roots.

CallQuadroot(r, s, r_1, i1, r_2, i2)

'Formulae to calculate real and imaginary values at the every term of function.

real(num)= r_1

imaginary(num)= i1

real(num -1)= r_2

imaginary(num -1)= i2

num = num -2

'Updating the coeffinents of function at every iteration.

Fori=0To num

arr(i)=brr(i+2)

Nexti

Loop

Ifiter<maxItrThen

If num =2Then

r =-arr(1)/arr(2)

s =-arr(0)/arr(2)

CallQuadroot(r, s, r_1, i1, r_2, i2)

'Use the values of i1, i2, r_1 and r_2 to determine real(num), imaginary(num), real(num-1) and imaginary(num-1).

real(num)= r_1

imaginary(num)= i1

real(num -1)= r_2

imaginary(num -1)= i2

Else

real(num)=-arr(0)/arr(1)

imaginary(num)=0

EndIf

Else

ier=1

EndIf

EndSub

SubQuadroot(r, s, r_1, i1, r_2, i2)

Dim Disc

'Value of Disc is calculated.

Disc = r ^2+4* s

'Condition for Disc>0.

If Disc >0Then

r_1 =(r +Sqr(Disc))/2

r_2 =(r -Sqr(Disc))/2

i1 =0

i2 =0

'Condition if Disc less than or equal to 0.

Else

r_1 = r /2

r_2 = r_1

i1 =Sqr(Abs(Disc))/2

i2 =-i1

EndIf

EndSub

Code for Problem 7.5(c):

OptionExplicit

SubPolynomialRoot()

Dim num AsInteger

DimmaxItrAsInteger,ierAsInteger,iAsInteger

Dimarr(10)AsDouble, real(10)AsDouble

Dimimaginary(10)AsDouble' Variable to provide negative or positive sign

Dim r AsDouble, s AsDouble, es AsDouble

'In example, the function is having 4 as highest power, so num is initialized to 4.

num =4

'Values of coefficients of the variables in function is given

arr(0) = 5: arr(1) = -2: arr(2) = 6: arr(3) = -2: arr(4) = 1

'Maximum number of iterations are defined.

maxItr=20

es =0.0001

r =-1

s =-1

CallBairstow_method(arr(), num, es, r, s,maxItr, real(), imaginary(),ier)

'Loop will run to all the powers of function to assign sign between real and imaginary numbers.

Fori=1To num

' If the value at iteration is greater than or equal to 0, assign '+' sign.

If imaginary(i)>=0Then

MsgBox real(i)&" + "& imaginary(i)&"i"

' If the value at iteration is lesser than 0, assign '-' sign.

Else

MsgBox real(i)&" - "& Abs(imaginary(i))&"i"

EndIf

Nexti

EndSub

'method with arguments to apply bairstow method in function.

SubBairstow_method(arr,nn, es,rr, ss,maxItr, real, imaginary,ier)

DimiterAsInteger, num AsInteger,iAsInteger

Dim r AsDouble, s AsDouble, ea1 AsDouble, ea2 AsDouble

Dim determine AsDouble,drAsDouble, ds AsDouble

Dim r_1 AsDouble, i1 AsDouble, r_2 AsDouble, i2 AsDouble

Dimbrr(10)AsDouble,crr(10)AsDouble

' Assigning values.

r =rr

s = ss

num =nn

ier=0

ea1 =1

ea2 =1

Do

'Loop will get terminated if power is less than 3 or if iteration is equal to or greater than maximum iteration.

If num <3Oriter>=maxItrThenExitDo

iter=0

Do

'Incrementing iter variable by 1.

iter=iter+1

'assigning values of array into another array.

brr(num)=arr(num)

'Disc brr(num-1) is calculated.

brr(num -1)=arr(num -1)+ r *brr(num)

crr(num)=brr(num)

'Disc crr(num-1) is calculated.

crr(num -1)=brr(num -1)+ r *crr(num)

'Loop will run for powers less than 3 till power 0.

Fori= num -2To0Step-1

'Values of brr(i) and crr(i) are updated.

brr(i)=arr(i)+ r *brr(i+1)+ s *brr(i+2)

crr(i)=brr(i)+ r *crr(i+1)+ s *crr(i+2)

Nexti

determine =crr(2)*crr(2)-crr(3)*crr(1)

If determine <>0Then

dr=(-brr(1)*crr(2)+brr(0)*crr(3))/ determine

ds =(-brr(0)*crr(2)+brr(1)*crr(1))/ determine

r = r +dr

s = s + ds

'Values of ea1 and ea2 are determined for different values in loop .

If r <>0Then ea1 =Abs(dr/ r)*100

If s <>0Then ea2 =Abs(ds / s)*100

Else

' Incrementing r and s by 1.

r = r +1

s = s +1

iter=0

EndIf

' If the values of ea1 and ea2 are less than value of es or iterations are completed then loop will be terminated

If ea1 <= es And ea2 <= es Oriter>=maxItrThenExitDo

Loop

'method call to find quadratic roots.

CallQuadroot(r, s, r_1, i1, r_2, i2)

'Formulae to calculate real and imaginary values at the every term of function.

real(num)= r_1

imaginary(num)= i1

real(num -1)= r_2

imaginary(num -1)= i2

num = num -2

'Updating the coeffinents of function at every iteration.

Fori=0To num

arr(i)=brr(i+2)

Nexti

Loop

Ifiter<maxItrThen

If num =2Then

r =-arr(1)/arr(2)

s =-arr(0)/arr(2)

CallQuadroot(r, s, r_1, i1, r_2, i2)

'Use the values of i1, i2, r_1 and r_2 to determine real(num), imaginary(num), real(num-1) and imaginary(num-1).

real(num)= r_1

imaginary(num)= i1

real(num -1)= r_2

imaginary(num -1)= i2

Else

real(num)=-arr(0)/arr(1)

imaginary(num)=0

EndIf

Else

ier=1

EndIf

EndSub

SubQuadroot(r, s, r_1, i1, r_2, i2)

Dim Disc

'Value of Disc is calculated.

Disc = r ^2+4* s

'Condition for Disc>0.

If Disc >0Then

r_1 =(r +Sqr(Disc))/2

r_2 =(r -Sqr(Disc))/2

i1 =0

i2 =0

'Condition if Disc less than or equal to 0.

Else

r_1 = r /2

r_2 = r_1

i1 =Sqr(Abs(Disc))/2

i2 =-i1

EndIf

EndSub

Output for Problem 7.5(a):

Now, run the code by pressing ‘F5’ key. Hence the output will be,

1st Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  1

2nd Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  2

3rd Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  3

Output for Problem 7.5(b):

Now, run the code by pressing ‘F5’ key. Hence the output will be,

1st Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  4

2nd Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  5

3rd Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  6

Output for Problem 7.5(c):

Now, run the code by pressing ‘F5’ key. Hence the output will be,

1st Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  7

2nd Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  8

3rd Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  9

4th Root:

EBK NUMERICAL METHODS FOR ENGINEERS, Chapter 7, Problem 9P , additional homework tip  10

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Knowledge Booster
Background pattern image
Mechanical Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, mechanical-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Algebra & Trigonometry with Analytic Geometry
Algebra
ISBN:9781133382119
Author:Swokowski
Publisher:Cengage
Text book image
Trigonometry (MindTap Course List)
Trigonometry
ISBN:9781337278461
Author:Ron Larson
Publisher:Cengage Learning
Points, Lines, Planes, Segments, & Rays - Collinear vs Coplanar Points - Geometry; Author: The Organic Chemistry Tutor;https://www.youtube.com/watch?v=dDWjhRfBsKM;License: Standard YouTube License, CC-BY
Naming Points, Lines, and Planes; Author: Florida PASS Program;https://www.youtube.com/watch?v=F-LxiLSSaLg;License: Standard YouTube License, CC-BY