You are on page 1of 8

CHE555 NUMERICAL METHODS & OPTIMIZATION

LAB 4: CURVE FITTING

Task 1: TO PLOT GRAPH IN MATLAB


Procedure:
(a)
(b)
(c)
(d)

Define X and Y
Use command plot (x,y)
Then, label the graph and x,y axis
Save and Run

Example: LINEAR REGRESSION


Data given:
T(oC)

27.6

10

31

20

34

30

37

40

40

50

42.6

60

45.5

70

48.3

80

51.1

90

54

100

56.7

In m-file:

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 1

Figure generate by Matlab:

Task 2: TO PLOT GRAPH IN EXCEL


Procedure with example:
(a) Define the data

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 2

(b) Select data

(c) Click Insert Scatter Scatter with smooth lines and markers

(d) Design Chart layouts Click Layout 1 Edit title and axis title

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 3

(e) Answer from Excel

Resistance versus temperature


60

Resistance

50
40
30
20
10
0
0

20

40

60

80

100

120

Temperature

Task 3: TO GENERATE EQUATION FROM THE DATA IN MATLAB


Procedure:
(a)
(b)
(c)
(d)
(e)
(f)

Define X and Y.
Use plot command.
Then, label the graph and x,y axis.
Use polyfit command to get the best fit for the data.
Use polyval command to plot the smooth graph based on the equation.
Save and Run

Example:
In m-file:

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 4

In Command window:

Figure generate by Matlab:

Task 4: TO GENERATE EQUATION FROM THE DATA IN EXCEL


Procedure:
(a) Repeat procedure in Task 2 - Procedure (a) (d)
(b) Then, Click on lines Right click Add Trendline Trendline Options Trend/
Regression type Linear/ Polynomial Tick on Display Equation on chart
Tick on Display R-squared value on chart Close

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 5

(c) Answer from Excel

Resistance versus temperature


60

Resistance

50
40
y = 0.2881x + 28.123
R = 0.9994

30
20
10
0
0

20

40

60

80

100

120

Temperature

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 6

Task 5: TO SOLVE NON-LINEAR REGRESSION USING SOLVER


Procedure:
Example:

ve v
v
0.1
0.2
0.4
0.6
0.9
1.3
1.5
1.7
1.8

0.75
1.25
1.45
1.25
0.85
0.55
0.35
0.28
0.18

(a) Open Excel


(b) Generate the table for initial guess (e.g. and ), prediction value based on non-linear
equation and sum of (prediction value - value from data)2

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 7

(c) Open Data Solver

i. Sum of sum of (prediction value - value from data)2 set as Set Objective
with value of 0
ii. Then, initial guess (e.g. and ) set as Changing Variable Cells
iii. Click Solve
(d) Get the answer as:

Prepared by Madam Rabiatul Adawiyah Abdol Aziz (2016)

Page 8

You might also like