Number of squares/circles

 

6

 

 

Dimension

Squaare_area

Circle_area

1

1

3.14

2

4

12.56

3

9

28.26

4

16

50.24

5

25

78.5

6

36

113.04

 

Sub Main()

Dim i As Integer, n As Integer

Dim a() As Double, result1() As Double, result2() As Double

n = Cells(2, 1)

ReDim a(n) As Double, result1(n) As Double, result2(n) As Double

For i = 1 To n Step 1

a(i) = Cells(3 + i, 1)

Next i

Call Square(n, a, result1)

Call Circ(n, a, result2)

For i = 1 To n Step 1

Cells(3 + i, 2) = result1(i)

Cells(3 + i, 3) = result2(i)

Next i

End Sub

 

Sub Square(n, AA, result)

Dim i As Integer

For i = 1 To n

result(i) = AA(i) ^ 2

Next i

End Sub

Sub Circ(n, AB, result)

Dim i As Integer

For i = 1 To n

result(i) = 3.14 * AB(i) ^ 2

Next i

End Sub

 

Bisection Method

 

 

 

 

 

 

 

 

 

 

imax

100

 

 

 

 

es

0.1

 

 

 

 

xl

50

 

 

 

 

xu

200

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

50

200

125

60

 

2

125

200

162.5

23.07692

 

3

125

162.5

143.75

13.04348

 

4

125

143.75

134.375

6.976744

 

5

134.375

143.75

139.0625

3.370787

 

6

139.0625

143.75

141.4063

1.657459

 

7

141.4063

143.75

142.5781

0.821918

 

8

142.5781

143.75

143.1641

0.409277

 

9

142.5781

143.1641

142.8711

0.205058

 

10

142.5781

142.8711

142.7246

0.102634

 

11

142.7246

142.8711

142.7979

0.051291

 

 

Sub Main()

Dim iter As Integer, imax As Integer, i As Integer

Dim xr() As Double, Fr As Double, Fl As Double, ea() As Double, es As Double

Dim xrold As Double, test As Double, xl() As Double, xu() As Double

 

imax = Cells(3, 2)

 

ReDim a(imax) As Double, ea(imax) As Double, xl(imax) As Double, xu(imax) As Double, xr(imax) As Double

 

es = Cells(4, 2)

xl(0) = Cells(5, 2)

xu(0) = Cells(6, 2)

 

xr(0) = xl(0)

xrold = xr(0)

 

For iter = 0 To imax Step 1

 

xr(iter) = (xl(iter) + xu(iter)) / 2

 

If xr(iter) <> 0 Then

ea(iter) = Abs((xr(iter) - xrold) / xr(iter)) * 100

End If

 

Call value(xr(iter), Fr)

Call value(xl(iter), Fl)

 

test = Fl * Fr

 

If test < 0 Then

xu(iter + 1) = xr(iter)

xl(iter + 1) = xl(iter)

ElseIf test > 0 Then

xl(iter + 1) = xr(iter)

xu(iter + 1) = xu(iter)

Else

ea(iter) = 0

End If

 

xrold = xr(iter)

 

If iter = imax Then Exit For

If ea(iter) <= es Then Exit For

 

Next iter

 

Cells(2, 6) = xr(iter)

For i = 0 To iter Step 1

Cells(9 + i, 1) = i + 1

Cells(9 + i, 2) = xl(i)

Cells(9 + i, 3) = xu(i)

Cells(9 + i, 4) = xr(i)

Cells(9 + i, 5) = ea(i)

Next i

 

Cells(2, 12) = xr(iter)

 

End Sub

 

Sub value(x, fx)

Const g As Double = 9.81

Const cd As Double = 0.25

Const v As Double = 36

Const t As Double = 4

Dim a As Double, b As Double, Val As Double

 

a = Sqr(g * cd / x)

b = a * t

Call mytanh(b, Val)

 

fx = Sqr(g * x / cd) * Val - v

 

End Sub

 

Sub mytanh(x, c)

 

c = (Exp(x) - Exp(-x)) / (Exp(x) + Exp(-x))

End Sub

 

 

 

Number of Delts

Delt Equals

Number of Iterations

 

 

Chapter 18 HMWK Number 4) from handout.

4

2

15

 

 

FOR LAB 10

 

 

 

1

 

 

 

 

 

 

 

 

0.5

 

 

 

 

 

 

 

 

0.1

 

 

 

 

 

 

 

time

y

yanaly

error

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2

8

14.84392155

46.10588603

 

 

 

 

 

4

39.6242594

75.33896073

47.4053544

 

 

 

 

 

6

196.2602416

373.8245816

47.49937504

 

 

 

 

 

8

972.0833401

1851.811115

47.50634488

 

 

 

 

 

10

4814.760303

9172.170936

47.50686248

 

 

 

 

 

12

23847.6639

45430.09332

47.50690092

 

 

 

 

 

14

118118.2525

225016.7375

47.50690378

 

 

 

 

 

16

585043.5347

1114515.201

47.50690399

 

 

 

 

 

18

2897739.597

5520229.931

47.50690401

 

 

 

 

 

20

14352598.18

27341877.84

47.50690401

 

 

 

 

 

22

71088884.16

135425207.5

47.50690401

 

 

 

 

 

24

352105548.3

670765443.8

47.50690401

 

 

 

 

 

26

1743990197

3322322992

47.50690401

 

 

 

 

 

28

8638039996

16455573505

47.50690401

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

1

4

6.194631253

35.42795629

 

 

 

 

 

2

10.90216371

14.84392155

26.55469329

 

 

 

 

 

3

25.26321155

33.67717094

24.9841633

 

 

 

 

 

4

56.7243113

75.33896073

24.70786596

 

 

 

 

 

5

126.4922764

167.9059044

24.66478358

 

 

 

 

 

6

281.6387384

373.8245816

24.66018763

 

 

 

 

 

7

626.8610393

832.0487126

24.66053612

 

 

 

 

 

8

1395.136149

1851.811115

24.66099063

 

 

 

 

 

9

3104.948226

4121.313362

24.66119528

 

 

 

 

 

10

6910.197171

9172.170936

24.66126919

 

 

 

 

 

11

15378.93053

20413.05357

24.66129342

 

 

 

 

 

12

34226.44129

45430.09332

24.66130093

 

 

 

 

 

13

76172.34691

101106.5364

24.66130319

 

 

 

 

 

14

169524.6762

225016.7375

24.66130385

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0.5

2

3.751521248

46.68829343

 

 

 

 

 

1

4.483649395

6.194631253

27.62039882

 

 

 

 

 

1.5

7.813818903

9.707041717

19.50360232

 

 

 

 

 

2

12.50059802

14.84392155

15.78641819

 

 

 

 

 

2.5

19.28151337

22.42701305

14.02549542

 

 

 

 

 

3

29.23924722

33.67717094

13.17784004

 

 

 

 

 

3.5

43.97578818

50.41177072

12.76682499

 

 

 

 

 

4

65.87113468

75.33896073

12.56697194

 

 

 

 

 

4.5

98.4684114

112.4964425

12.46975527

 

 

 

 

 

5

147.0477774

167.9059044

12.42250951

 

 

 

 

 

5.5

219.4821331

250.5492058

12.39958935

 

 

 

 

 

6

327.5133372

373.8245816

12.38849628

 

 

 

 

 

6.5

488.6558379

557.7189735

12.38314255

 

 

 

 

 

7

729.0363622

832.0487126

12.38056724

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

0.1

0.4

2.308790049

82.674908

 

 

 

 

 

0.2

0.813314827

2.636362363

69.15011235

 

 

 

 

 

0.3

1.242053434

2.984619533

58.38486547

 

 

 

 

 

0.4

1.688450423

3.355606113

49.68269917

 

 

 

 

 

0.5

2.154879007

3.751521248

42.55986134

 

 

 

 

 

0.6

2.643864936

4.174732317

36.6698333

 

 

 

 

 

0.7

3.15810145

4.62778967

31.75788713

 

 

 

 

 

0.8

3.700465378

5.113442562

27.63260107

 

 

 

 

 

0.9

4.27403446

5.634656376

24.14738051

 

 

 

 

 

1

4.882106022

6.194631253

21.18810915

 

 

 

 

 

1.1

5.528217092

6.796822237

18.66468035

 

 

 

 

 

1.2

6.21616612

7.444961075

16.50505546

 

 

 

 

 

1.3

6.950036403

8.143079799

14.65100951

 

 

 

 

 

1.4

7.734221389

8.895536255

13.05502932

 

 

 

 

 

 

 

Option Explicit

 

Sub Main()

Dim i As Integer, n As Integer, m As Integer, j As Integer, k As Integer

 

Dim y() As Double, yanal() As Double, err() As Double, t() As Double, delt() As Double, dydt As Double

n = Cells(2, 1)

m = Cells(2, 3)

ReDim y(m) As Double, yanal(m) As Double, err(m) As Double, t(m) As Double, delt(n) As Double

y(1) = Cells(7, 2)

t(1) = Cells(7, 1)

yanal(1) = Cells(7, 3)

err(1) = Cells(7, 4)

k = 7

For j = 1 To n Step 1

For i = 2 To m Step 1

delt(j) = Cells(1 + j, 2)

    dydt = 4 * Exp(0.8 * t(i - 1)) - 0.5 * y(i - 1)

    y(i) = y(i - 1) + dydt * delt(j)

    t(i) = t(i - 1) + delt(j)

    yanal(i) = 3.076923 * Exp(0.8 * t(i)) - 3.076923 * Exp(-0.5 * t(i)) + 2 * Exp(-0.5 * t(i))

    err(i) = 100 * (yanal(i) - y(i)) / yanal(i)

Cells(k + i, 1) = t(i)

Cells(k + i, 2) = y(i)

Cells(k + i, 3) = yanal(i)

Cells(k + i, 4) = err(i)

Next i

k = k + m + 1

Next j

 

End Sub