Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas

Solution manual of Numerical Methods for engineers - Chapra, Exercícios de Cálculo para Engenheiros

Resolução das questões do Livro de Método Númerico.

Tipologia: Exercícios

2020

Compartilhado em 17/07/2020

bruna-vilarino-ramos-10
bruna-vilarino-ramos-10 🇧🇷

4.8

(12)

2 documentos

1 / 515

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
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”
value =
“end of data”
sum = sum + value
count = count + 1
T
F
count > 0
average = sum/count
end
T
F
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe Solution manual of Numerical Methods for engineers - Chapra e outras Exercícios em PDF para Cálculo para Engenheiros, somente na Docsity!

CHAPTER 2

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

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

start

sum = 0

count = 0

INPUT

value

value =

“end of data”

value =

“end of data”

sum = sum + value

count = count + 1

T

F

count > 0

average = sum/count

end

T

F

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, i

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, i

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 = b2 - 4.ac

IF (d >= 0) THEN

r1 = (-b + SQRT(d))/(2*a)

r2 = (-b - SQRT(d))/(2*a)

ELSE

r1 = -b/(2*a)

r2 = r

i1 = SQRT(ABS(d))/(2*a)

i2 = -i

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.33 i ; −1.25 −

2.33 i.

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.

start

INPUT

x, n

i > n

end

i = 1

true = sin(x)

approx = 0

factor = 1

approx approx

x

factor

i

i -

  • 1

2 1

error

true approx

true

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-

  • x

2

i-

/ factor

error = Abs(true - approx) / true) * 100

PRINT i, true, approx, error

i = i + 1

factor = factor(2i-2)(2i-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.

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 * (2i-2) * (2i-1)

END DO
END
OUTPUT:

order true approx error

4 0.9974950 0.9973912 1.0403229E-
5 0.9974950 0.9974971 -2.1511559E-
6 0.9974950 0.9974950 0.0000000E+
7 0.9974950 0.9974951 -1.1950866E-
8 0.9974950 0.9974949 1.1950866E-
9 0.9974950 0.9974915 3.5255053E-
10 0.9974950 0.9974713 2.3782223E-
11 0.9974950 0.9974671 2.7965026E-
12 0.9974950 0.9974541 4.0991469E-
13 0.9974950 0.9974663 2.8801586E-
14 0.9974950 0.9974280 6.7163869E-
15 0.9974950 0.9973251 1.7035959E-

Press any key to continue

The errors can be plotted versus the number of terms:

1.E-

1.E-

1.E-

1.E-

1.E-

1.E+

1.E+

1.E+

0 5 10 15

error

n F

2.10 Programs vary, but results are

Bismarck = −10.842 t = 0 to 59

Yuma = 33.040 t = 180 to 242

n A

Step v (12)

t

Error is halved when step is halved

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 + V

Vol =

“Overtop”

End Function

Vol = pi * d^3 / 3

Here is a program in VBA:

Option Explicit

Function Vol(R, d)

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 θ

4.18 f(x) = x-1-1/2*sin(x)

f '(x) = 1-1/2*cos(x)

f ''(x) = 1/2*sin(x)

f '''(x) = 1/2*cos(x)

f

IV

(x) = -1/2*sin(x)

Using the Taylor Series Expansion (Equation 4.5 in the book), we obtain the following

st

nd

rd

, and 4

th

Order Taylor Series functions shown below in the Matlab program-

f1, f2, f4. Note the 2

nd

and 3

rd

Order Taylor Series functions are the same.

From the plots below, we see that the answer is the 4

th

Order Taylor Series expansion.

x=0:0.001:3.2;

f=x-1-0.5*sin(x) ;

subplot(2,2,1);

plot(x,f);grid;title('f(x)=x-1-0.5*sin(x)');hold on

f1=x-1.5 ;

e1=abs(f-f1); %Calculates the absolute value of the

difference/error

subplot(2,2,2);

plot(x,e1);grid;title('1st Order Taylor Series Error');

f2=x-1.5+0.25.((x-0.5pi).^2);

e2=abs(f-f2);

subplot(2,2,3);

plot(x,e2);grid;title('2nd/3rd Order Taylor Series Error');

f4=x-1.5+0.25.((x-0.5pi).^2)-(1/48)((x-0.5pi).^4);

e4=abs(f4-f);

subplot(2,2,4);

plot(x,e4);grid;title('4th Order Taylor Series Error');hold off

0 1 2 3 4

0

1

2

3

f(x )= x -1-0.5*s in(x )

0 1 2 3 4

0

1s t O rder Tay lor S eries E rror

0 1 2 3 4

0

2nd/3rd O rder Tay lor S eries E rror

0 1 2 3 4

0

4th O rder Tay lor S eries E rror

4.19 EXCEL WORKSHEET AND PLOTS

First Derivative Approximations Compared to Theoretical

-4.

-2.

-2.5 -2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0 2.

x-values

f'(x)

Theoretical

Backward

Centered

Forward