Tutorial 4/5 - Lecture Notes: Arrays

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Tutorial 4/5 - Lecture Notes

column index
Arrays

column 1

column 2

column 3

column 4
𝑏11 𝑏12 𝑏13 𝑏14 row 1 row index

b= 𝑏21 𝑏22 𝑏23 𝑏24 row 2

𝑏31 𝑏32 𝑏33 𝑏34 row 3

entire array element


array In VB syntax b(3,2)

row index column index

110 120 130 140 b(3,2) Row index: 2


𝑏 = 210 520 230 240 Column index: 3
Value: 230
310 320 330 340

LBOUND & UBOUND


Syntax: ubound(b,i)

array dimension i=1 highest row index


(default is 1) i=2 highest column index

Meaning: largest index of array b along dimension I


Example: UBOUND(b,1) 3
UBOUND(b,2) 4

What is the value of the array element with the highest row-index and the
highest column-index?
i_max = ubound(b,1)
j_max = ubound(b,2)
x = b(i_max,j_max)
or
x = b(ubound(b,1), ubound(b,2))
Sum

sum = a + b + c + d

sum = m(1,1) + m(2,1) + m(3,1) + m(4,1)

sum = 0
sum = sum + m(1,1)
sum = sum + m(2,1)
sum = sum + m(3,1)
sum = sum + m(4,1)

sum = 0
FOR i = 1 TO 4
sum = sum + m(i,1)
NEXT i

Numerical Integration

Detailed explanation and equations are on the tutorial sheet. Here the focus is on
the concept.

f
𝑏
f(x)
𝑓 𝑥 𝑑𝑥
𝑎

a b x
Simple approximation:
𝑏
𝑓 𝑎 +𝑓 𝑏
≈ 𝑓 𝑥 𝑑𝑥 = 𝑏−𝑎
𝑎 2
f
f(x)
f(b)

f(a)

a b x

Improve accuracy:

f
f(x)
f(b)

f(a)

a b x
Simple approximation:
𝑏
𝑓 𝑎 +𝑓 𝑏
≈ 𝑓 𝑥 𝑑𝑥 = 𝑏−𝑎
𝑎 2
f
f(x)
f(b)

f(a)

a b x

Improve accuracy:

f
f(x)
f(b)
If we have only data points,
f(x) is unknown. In this case
numerical integration is the
only option (apart from
fitting a function g(x) and
integrating that analytically.
f(a)

a b x

You might also like