Vba Programming in Excel 2007: Dr. Majid Mohammadian Majid - Mohammadian@uottawa - Ca
Vba Programming in Excel 2007: Dr. Majid Mohammadian Majid - Mohammadian@uottawa - Ca
Vba Programming in Excel 2007: Dr. Majid Mohammadian Majid - Mohammadian@uottawa - Ca
Editor
Project Manager
Properties
ADDING A NEW MODULE
Select your spreadsheet in the project explorer
Use the main menu or the contextual menu (mouse
right button) to insert the new module
A simple function: my_sum
Open VBA using alt+f11
Type the following:
Function my_sum(a, b)
my_sum = a + b
End Function
Function test_s()
Dim x As Single
x = 1.23456789012345
test_s = x
End Function
Function test_d()
Dim x As Double
x = 1.23456789012345
test_d = x
End Function
THE PARACHUTIST PROBLEM
Analytical solution:
gm c m t
v(t ) 1 e
c
Numerical (finite difference) solution:
c
v(ti 1 ) v (ti ) g v(ti ) (ti 1 ti )
m
or
New value Old value slope step size
We are going to implement both solutions in Excel
ANALYTICAL SOLUTION
To calculate analytical solution using Excel, let
us first set up a simple spreadsheet. As shown
below, the first step involves entering labels and
numbers into the spreadsheet cells
To attach names to parameters values, select cells
Formula tab Define Name
Numerical: G8=0:
(Type in G9) =G8+(g-cd/m*G8)*dt
Function v2_parachute
Task 7: Define the function y= cos(x) +sin(x) using VB, and plot
it from 0 to 3.1415.