Numerical Methods With Excel/VBA
Numerical Methods With Excel/VBA
! Numerical Integration
Recall:
24
25
Sub Nint()
a=0
b=5
n = 100
h = (b - a) / n
I = h * (f(a) + f(b)) / 2
For m = 2 To n
I = I + f(a + h * (m - 1)) * h
Next
Range("B3").Value = I
End Sub
Put the result onto the Excel sheet into the cell B3
Function f(x)
f=x^4
End Function
26
Example 2:
27
- So far we could have solved the intgrals also analytically, but not the
next integral.
Example 3:
- How do we deal with the lower bound a=0? This is well defined
analytically, but the computer can not handle 0/0, if we dont
specify how to do that. Recipe: Just take the lower bound a to be a
very small number, e.g.a=0.0000001.
- The program yields:
28
- Compute instead:
- The program gives:
29
b=10 ?
31
i) open a worksheet
33
! Goal Seek
Goal seek is a numerical routine implemented in Excel in form
of a built-in function. It canbe used to solve equations.
Usage: select Tools Goal Seek a dialog window opens
- Set cell contains the left hand side of
an equation you want to solve
- To value contains the RHS of the equation
- By changing cell contains the variable
of the equation
Disadvantage: You have to guess a value near the answer.
- OK