100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Exam (elaborations) TEST BANK FOR Numerical Methods for Engineers By Steven C. Chapra (Solutions manual)

Rating
-
Sold
-
Pages
516
Grade
A+
Uploaded on
13-11-2021
Written in
2021/2022

Exam (elaborations) TEST BANK FOR Numerical Methods for Engineers By Steven C. Chapra (Solutions manual) CHAPTER 2 2.1 IF x < 10 THEN IF x < 5 THEN x = 5 ELSE PRINT x END IF ELSE DO IF x < 50 EXIT x = x - 5 END DO END IF 2.2 Step 1: Start Step 2: Initialize sum and count to zero Step 3: Examine top card. Step 4: If it says “end of data” proceed to step 9; otherwise, proceed to next step. Step 5: Add value from top card to sum. Step 6: Increase count by 1. Step 7: Discard top card Step 8: Return to Step 3. Step 9: Is the count greater than zero? If yes, proceed to step 10. If no, proceed to step 11. Step 10: Calculate average = sum/count Step 11: End 2.3 start sum = 0 count = 0 INPUT value value = “end of data” sum = sum + value count = count + 1 T F count > 0 average = sum/count end T F 2.4 Students could implement the subprogram in any number of languages. The following Fortran 90 program is one example. It should be noted that the availability of complex variables in Fortran 90, would allow this subroutine to be made even more concise. However, we did not exploit this feature, in order to make the code more compatible with Visual BASIC, MATLAB, etc. PROGRAM Rootfind IMPLICIT NONE INTEGER::ier REAL::a, b, c, r1, i1, r2, i2 DATA a,b,c/1.,5.,2./ CALL Roots(a, b, c, ier, r1, i1, r2, i2) IF (ier .EQ. 0) THEN PRINT *, r1,i1," i" PRINT *, r2,i2," i" ELSE PRINT *, "No roots" END IF END SUBROUTINE Roots(a, b, c, ier, r1, i1, r2, i2) IMPLICIT NONE INTEGER::ier REAL::a, b, c, d, r1, i1, r2, i2 r1=0. r2=0. i1=0. i2=0. IF (a .EQ. 0.) THEN IF (b <> 0) THEN r1 = -c/b ELSE ier = 1 END IF ELSE d = b**2 - 4.*a*c IF (d >= 0) THEN r1 = (-b + SQRT(d))/(2*a) r2 = (-b - SQRT(d))/(2*a) ELSE r1 = -b/(2*a) r2 = r1 i1 = SQRT(ABS(d))/(2*a) i2 = -i1 END IF END IF END The answers for the 3 test cases are: (a) -0.438, -4.56; (b) 0.5; (c) -1.25 + 2.33i; -1.25 - 2.33i. Several features of this subroutine bear mention: · The subroutine does not involve input or output. Rather, information is passed in and out via the arguments. This is often the preferred style, because the I/O is left to the discretion of the programmer within the calling program. · Note that an error code is passed (IER = 1) for the case where no roots are possible. 2.5 The development of the algorithm hinges on recognizing that the series approximation of the sine can be represented concisely by the summation, x i i i n 2 1 1 2 1 - = - å( )! where i = the order of the approximation. The following algorithm implements this summation: Step 1: Start Step 2: Input value to be evaluated x and maximum order n Step 3: Set order (i) equal to one Step 4: Set accumulator for approximation (approx) to zero Step 5: Set accumulator for factorial product (fact) equal to one Step 6: Calculate true value of sin(x) Step 7: If order is greater than n then proceed to step 13 Otherwise, proceed to next step Step 8: Calculate the approximation with the formula approx approx ( 1) x factor i-1 2i-1 = + - Step 9: Determine the error 100% true %error = true- approx Step 10: Increment the order by one Step 11: Determine the factorial for the next iteration factor = factor · (2 · i - 2) · (2 · i - 1) Step 12: Return to step 7 Step 13: End 2.6 start INPUT x, n i > n end i = 1 true = sin(x) approx = 0 factor = 1 approx approx x factor i i - = +(- 1) - 1 2 1 error true approx true = - 100% OUTPUT i,approx,error i = i + 1 F T factor=factor(2i-2)(2i-1) Pseudocode: SUBROUTINE Sincomp(n,x) i = 1 true = SIN(x) approx = 0 factor = 1 DO IF i > n EXIT approx = approx + (-1)i-1·x2·i-1 / factor error = Abs(true - approx) / true) * 100 PRINT i, true, approx, error i = i + 1 factor = factor·(2·i-2)·(2·i-1) END DO END 2.7 The following Fortran 90 code was developed based on the pseudocode from Prob. 2.6: PROGRAM Series IMPLICIT NONE INTEGER::n REAL::x n = 15 x = 1.5 CALL Sincomp(n,x) END SUBROUTINE Sincomp(n,x) IMPLICIT NONE INTEGER::n,i,fac REAL::x,tru,approx,er i = 1 tru = SIN(x) approx = 0. fac = 1 PRINT *, " order true approx error" DO IF (i > n) EXIT approx = approx + (-1) ** (i-1) * x ** (2*i - 1) / fac er = ABS(tru - approx) / tru) * 100 PRINT *, i, tru, approx, er i = i + 1 fac = fac * (2*i-2) * (2*i-1) END DO END OUTPUT: order true approx error 1 0. 1. -50.37669 2 0. 0. 6. 3 0. 1. -0. 4 0. 0. 1.E-02 5 0. 0. -2.E-04 6 0. 0. 0.E+00 7 0. 0. -1.E-05 8 0. 0. 1.E-05 9 0. 0. 3.E-04 10 0. 0. 2.E-03 11 0. 0. 2.E-03 12 0. 0. 4.E-03 13 0. 0. 2.E-03 14 0. 0. 6.E-03 15 0. 0. 1.E-02 Press any key to continue The errors can be plotted versus the number of terms: 1.E-05 1.E-04 1.E-03 1.E-02 1.E-01 1.E+00 1.E+01 1.E+02 0 5 10 15 error Interpretation: The absolute percent relative error drops until at n = 6, it actually yields a perfect result (pure luck!). Beyond, n = 8, the errors starts to grow. This occurs because of round-off error, which will be discussed in Chap. 3. 2.8 AQ = 442/5 = 88.4 AH = 548/6 = 91.33 without final AG = 30(88.4) + 30(91.33) 30 + 30 = 89.8667 with final AG = 30(88.4) + 30(91.33) + 40(91) 30 + 30 = 90.32 The following pseudocode provides an algorithm to program this problem. Notice that the input of the quizzes and homeworks is done with logical loops that terminate when the user enters a negative grade: INPUT number, name INPUT WQ, WH, WF nq = 0 sumq = 0 DO INPUT quiz (enter negative to signal end of quizzes) IF quiz < 0 EXIT nq = nq + 1 sumq = sumq + quiz END DO AQ = sumq / nq PRINT AQ nh = 0 sumh = 0 PRINT "homeworks" DO INPUT homework (enter negative to signal end of homeworks) IF homework < 0 EXIT nh = nh + 1 sumh = sumh + homework END DO AH = sumh / nh PRINT "Is there a final grade (y or n)" INPUT answer IF answer = "y" THEN INPUT FE AG = (WQ * AQ + WH * AH + WF * FE) / (WQ + WH + WF) ELSE AG = (WQ * AQ + WH * AH) / (WQ + WH) END IF PRINT number, name$, AG END 2.9 n F 0 $100,000.00 1 $108,000.00 2 $116,640.00 3 $125,971.20 4 $136,048.90 5 $146,932.81 24 $634,118.07 25 $684,847.52 2.10 Programs vary, but results are Bismarck = -10.842 t = 0 to 59 Yuma = 33.040 t = 180 to 242 2.11 n A 1 40,250.00 2 21,529.07 3 15,329.19 4 12,259.29 5 10,441.04 2.12 Step v(12) et (%) 2 49.96 -5.2 1 48.70 -2.6 0.5 48.09 -1.3 Error is halved when step is halved 2.13 Fortran 90 VBA Subroutine BubbleFor(n, b) Implicit None !sorts an array in ascending !order using the bubble sort Integer(4)::m, i, n Logical::switch Real::a(n),b(n),dum m = n - 1 Do switch = .False. Do i = 1, m If (b(i) > b(i + 1)) Then dum = b(i) b(i) = b(i + 1) b(i + 1) = dum switch = .True. End If End Do If (switch == .False.) Exit m = m - 1 End Do End Option Explicit Sub Bubble(n, b) 'sorts an array in ascending 'order using the bubble sort Dim m As Integer, i As Integer Dim switch As Boolean Dim dum As Single m = n - 1 Do switch = False For i = 1 To m If b(i) > b(i + 1) Then dum = b(i) b(i) = b(i + 1) b(i + 1) = dum switch = True End If Next i If switch = False Then Exit Do m = m - 1 Loop End Sub 2.14 Here is a flowchart for the algorithm: Function Vol(R, d) pi = 3. d < R d < 3 * R V1 = pi * R^3 / 3 V2 = pi * R^2 (d – R) Vol = V1 + V2 Vol = “Overtop” End Function Vol = pi * d^3 / 3 Here is a program in VBA: Option Explicit Function Vol(R, d) Dim V1 As Single, v2 As Single, pi As Single pi = 4 * Atn(1) If d < R Then Vol = pi * d ^ 3 / 3 ElseIf d <= 3 * R Then V1 = pi * R ^ 3 / 3 v2 = pi * R ^ 2 * (d - R) Vol = V1 + v2 Else Vol = "overtop" End If End Function The results are R d Volume 1 0.3 0. 1 0.8 0. 1 1 1. 1 2.2 4. 1 3 7. 1 3.1 overtop 2.15 Here is a flowchart for the algorithm: Function Polar(x, y) r = x2 + y2 x < 0 y > 0 y > 0 p q + ÷ø ö çè = - æ x tan 1 y p q - ÷ø ö çè = - æ x y 1 tan q = 0 2 q = -p y < 0 2 q = p q = p y < 0 p Polar = q 180 End Polar p = 3. T T T T T F F F F And here is a VBA function procedure to implement it: Option Explicit Function Polar(x, y) Dim th As Single, r As Single Const pi As Single = 3. r = Sqr(x ^ 2 + y ^ 2) If x < 0 Then If y > 0 Then th = Atn(y / x) + pi ElseIf y < 0 Then th = Atn(y / x) - pi Else th = pi End If Else If y > 0 Then th = pi / 2 ElseIf y < 0 Then th = -pi / 2 Else th = 0 End If End If Polar = th * 180 / pi End Function The results are: x y q 1 1 90 1 -1 -90 1 0 0 -1 1 135 -1 -1 -135 -1 0 180 0 1 90 0 -1 -90 0 0

Show more Read less











Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
November 13, 2021
Number of pages
516
Written in
2021/2022
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

,CHAPTER 2
2.1
IF x < 10 THEN
IF x < 5 THEN
x = 5
ELSE
PRINT x
END IF
ELSE
DO
IF x < 50 EXIT
x = x - 5
END DO
END IF

2.2
Step 1: Start
Step 2: Initialize sum and count to zero
Step 3: Examine top card.
Step 4: If it says “end of data” proceed to step 9; otherwise, proceed to next step.
Step 5: Add value from top card to sum.
Step 6: Increase count by 1.
Step 7: Discard top card
Step 8: Return to Step 3.
Step 9: Is the count greater than zero?
If yes, proceed to step 10.
If no, proceed to step 11.
Step 10: Calculate average = sum/count
Step 11: End

2.3
start


sum = 0
count = 0




T
count > 0
INPUT
value
F
average = sum/count
value = T
“end of data”


F end
sum = sum + value
count = count + 1

,2.4
Students could implement the subprogram in any number of languages. The following
Fortran 90 program is one example. It should be noted that the availability of complex
variables in Fortran 90, would allow this subroutine to be made even more concise.
However, we did not exploit this feature, in order to make the code more compatible with
Visual BASIC, MATLAB, etc.
PROGRAM Rootfind
IMPLICIT NONE
INTEGER::ier
REAL::a, b, c, r1, i1, r2, i2
DATA a,b,c/1.,5.,2./
CALL Roots(a, b, c, ier, r1, i1, r2, i2)
IF (ier .EQ. 0) THEN
PRINT *, r1,i1," i"
PRINT *, r2,i2," i"
ELSE
PRINT *, "No roots"
END IF
END

SUBROUTINE Roots(a, b, c, ier, r1, i1, r2, i2)
IMPLICIT NONE
INTEGER::ier
REAL::a, b, c, d, r1, i1, r2, i2
r1=0.
r2=0.
i1=0.
i2=0.
IF (a .EQ. 0.) THEN
IF (b <> 0) THEN
r1 = -c/b
ELSE
ier = 1
END IF
ELSE
d = b**2 - 4.*a*c
IF (d >= 0) THEN
r1 = (-b + SQRT(d))/(2*a)
r2 = (-b - SQRT(d))/(2*a)
ELSE
r1 = -b/(2*a)
r2 = r1
i1 = SQRT(ABS(d))/(2*a)
i2 = -i1
END IF
END IF
END


The answers for the 3 test cases are: (a) −0.438, -4.56; (b) 0.5; (c) −1.25 + 2.33i; −1.25 −
2.33i.

Several features of this subroutine bear mention:
• The subroutine does not involve input or output. Rather, information is passed in and out
via the arguments. This is often the preferred style, because the I/O is left to the
discretion of the programmer within the calling program.
• Note that an error code is passed (IER = 1) for the case where no roots are possible.

, 2.5 The development of the algorithm hinges on recognizing that the series approximation of the
sine can be represented concisely by the summation,

n 2i −1
x
∑ (2i − 1)!
i =1


where i = the order of the approximation. The following algorithm implements this
summation:

Step 1: Start
Step 2: Input value to be evaluated x and maximum order n
Step 3: Set order (i) equal to one
Step 4: Set accumulator for approximation (approx) to zero
Step 5: Set accumulator for factorial product (fact) equal to one
Step 6: Calculate true value of sin(x)
Step 7: If order is greater than n then proceed to step 13
Otherwise, proceed to next step
Step 8: Calculate the approximation with the formula
2i-1
x
approx = approx + ( −1) i-1
factor
Step 9: Determine the error
true − approx
%error = 100%
true
Step 10: Increment the order by one
Step 11: Determine the factorial for the next iteration
factor = factor • (2 • i − 2) • (2 • i − 1)
Step 12: Return to step 7
Step 13: End

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Expert001 Chamberlain School Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
795
Member since
4 year
Number of followers
566
Documents
1190
Last sold
1 day ago
Expert001

High quality, well written Test Banks, Guides, Solution Manuals and Exams to enhance your learning potential and take your grades to new heights. Kindly leave a review and suggestions. We do take pride in our high-quality services and we are always ready to support all clients.

4.2

159 reviews

5
104
4
18
3
14
2
7
1
16

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions