Académique Documents
Professionnel Documents
Culture Documents
CHARACTER OPERATIONS
INTEGRAL CALCULATION
Integral Calculation – the concept
a standard mathematical technique
can be used to calculate the area, volume,
etc
can be solved analytically or numerically
expression:
Integral Calculation – the concept
Three numerical methods to solve integral
problems
Simpson method
Rectangle
Trapezoid
Similar idea:
Total Area = sum of the partial area
Integral Calculation – the concept
Analytical
y
Y = F(x)
B
Area = ∫ F ( x ) dx
A
x
A B
F ( X 0 ) + 4 × F ( X 0+1( p ) ) + 2 × F ( X 0+ 2( p ) )
P
B
Area = ∫ F ( x)dx = × + 4 × F ( X 0+ 3( p ) ) + ... +
A
3
2 × F ( X ( n − 2)( p ) ) + 4 × F ( X ( n −1)( p ) ) + F ( X ( n )( p ) )
Where:
N = (B-A) / P; the number of sub intervals
P : the width of sub interval
X0 : A
parabolic approach
Xn : B
Simpson Method – analytical vs. numerical
2
∫ − + 2)dx = ???
3 2
( 4 x 3 x
1
[ ]
2
2
∫ − + = − + 2x 1
3 2 4 3
( 4 x 3 x 2) dx x x =12-2 = 10
1
(4 • 13 − 3 • 12 + 2)
+ 4(4 • 1.1 − 3 • 1.1 + 2) + 2((4 • 1.2 − 3 • 1.2 + 2)
3 2 3 2
= ( p / 3) × + ...
+ 2(4 • 1.8 − 3 • 1.8 + 2) + 4(4 • 1.9 − 3 • 1.9 + 2)
3 2 3 2
+ (4 • 2 − 3 • 2 + 2)
3 2
= 9.602
Simpson Method – error
Accuration limit
Analytical
Area
iteration #
Accuration limit
Analytical
I.S iteration #
L.C.
Start Integral_simpsoncurrentcalculation
LastCalc pervious calculation
ABS [ Integral_Simpson-LastCalc)/
FOR I=1 TO 20 Integral_Simpson]
< ε ??
NO
LastCalc = Integral_Simpson P=P/2 Print
N=(B-A)/P Integral_Simpson
Next I
x
A B
F ( x0 ) + F ( x0+ p )
2
Area = ∫ F ( x)dx = P + F ( x0+ 2 p ) + ...
1 + F ( x ) + F ( x )
( n−2) p ( n −1) p
Rectangle - numerical
[ ]
2
2
∫ − + = − + 2x 1
3 2 4 3
( 4 x 3 x 2) dx x x
1
(4 • 13 − 3 • 12 + 2)
+ (4 • 1.1 − 3 • 1.1 + 2) + (4 • 1.2 − 3 • 1.2 + 2)
3 2 3 2
= ( p / 2) × + ...
+ (4 • 1.8 − 3 • 1.8 + 2) + (4 • 1.9 − 3 • 1.9 + 2)
3 2 3 2
+ (4 • 2 − 3 • 2 + 2)
3 2
= 9.075
Rectangle – the error
Integral _ Re ct − LastCalc
<ε
Integral _ Re ct
Analytical
Area
iteration #
Rectangle - flowchart
Integral_rectcurrentcalculation
Start LastCalc pervious calculation
P width, Nnumber of sub classes
Read F(x), A,
B, ε
Integral_Rect=
Integral_rect=0 P*SUM
P=(B-A)/2
ABS [ Integral_Rect-LastCalc)/
FOR I=1 TO 20 Integral_Rect]
< ε ??
NO
LastCalc = Integral_Rect P=P/2 Print
N=(B-A)/P Integral_Rect
Next I
x
A B
F ( X 0 ) + 2 × F ( X 0+1( p ) ) + 2 × F ( X 0+ 2( p ) )
P + 2 × F ( X 0+ 3( p ) ) + ...
B
Area = ∫ F ( x)dx = × =12-2 = 10
2 + 2 × F ( X ) + 2 × F ( X )
A
( n − 2 )( p ) ( n − 1)( p )
+ F ( X ( n )( p ) )
Trapezoid
[ ]
2
2
∫ − + = − + 2x 1
3 2 4 3
( 4 x 3 x 2) dx x x
1
(4 • 13 − 3 • 12 + 2)
+ 2(4 • 1.1 − 3 • 1.1 + 2) + 2((4 • 1.2 − 3 • 1.2 + 2)
3 2 3 2
= ( p / 2) × + ...
+ 2(4 • 1.8 − 3 • 1.8 + 2) + 2(4 • 1.9 − 3 • 1.9 + 2)
3 2 3 2
+ (4 • 2 − 3 • 2 + 2)
3 2
= 11.125
Trapezoid - flowchart
Integral_trapcurrentcalculation
Start LastCalc pervious calculation
P width, Nnumber of sub classes
Read F(x), A,
B, ε
Integral_Trap=
Integral_trap=0 P*SUM
P=(B-A)/2
ABS [ Integral_Trap-LastCalc)/
FOR I=1 TO 20 Integral_Trap]
< ε ??
NO
LastCalc = Integral_Trap P=P/2 Print
N=(B-A)/P Integral_Trap
Next I
trapezoid in-between
Least square
LEAST SQUARE
Least Square - Introduction
Independent Variable -1
(x1)
Independent Variable -2
Dependent Variable
(x2)
BLACK
(y)
BOX
Independent Variable -3
(x3)
Independent Variable -4
(x4)
relationships ??
The Model
Thefirst order linear model or a simple
regression model,
y = A + Bx
y = dependent variable
A and B are unknown,
x = independent variable
ytherefore, are estimated
Α = y-intercept from the data.
A Run
x
Estimating the Coefficients
The estimates are determined by
drawing a sample from the population of interest,
calculating sample statistics.
producing a straight line that cuts into the data.
where: (∑ xi ∑ yi )
∑ xiyi −
ˆ n ∑ xiyi − nx y
βB1 = 2
or 2 2
2 (∑ x i ) ∑ xi − n x
∑ xi −
n
Aˆ0 = yYbar
β − βˆ1-xB Xbar
n : # data
• Example 1 Relationship between odometer
reading and a used car’s selling price.
A car dealer wants to find
Car Odometer Price
the relationship between 1 37388 5318
the odometer reading and 2 44758 5061
the selling price of used 3 45833 5008
4 30862 5795
cars. 5 31705 5784
A random sample of 100 6 34010 5359
cars is selected, and the . . .
. . .
data. . . .
Find the regression line.
Independent variable x
Dependent variable
Least Square Method – flow chart (∑ xi ∑ yi )
∑ xiyi −
n ∑ xiyi − nx y
βˆB1-=# of data
N 2
or 2 2
2 (∑ xi ) ∑ xi − nx
START ∑ xi −
n
βˆ0 = yYbar
A − βˆ1x- B Xbar
Read N
NEXT I
STOP
Using the computer
Tools > Data analysis > Regression > [Shade the y range and the x range] >
SUMMARY OUTPUT
6000
Price
Multiple R 0.806308 5000
R Square 0.650132
Adjusted R Square
0.646562
4500
Standard Error
151.5688 19000 29000 39000 49000
Observations 100 Odometer
ŷ = 6533−.0312
x
ANOVA
df SS MS F Significance F
Regression 1 4183528 4183528 182.1056 4.4435E-24
Residual 98 2251362 22973.09
Total 99 6434890
Price
5000
4500
0 No data 19000 29000 39000 49000
Odometer
ŷ = 6533−.0312
x
CHARACTER OPERATIONS
character - Inverting the sentence
from I=1 to N
from J=N to 1
inversion - flowchart
counter: I
start
counter: J
Read SENTENCE
J=N
for I = 1 to N
INVERT[J] = SENTENCE[I]
PRINT INVERT
J = J-1
STOP
NEXT I