Curve Fitting in MATLAB:
Curve fitting is a process of finding a function that can be used to model
data. The function does not necessarily pass through any of the points, but
models the data with the smallest possible error. Curve fitting is also called
regression analysis (Method of least square).
Example 1: Use least square method for fitting and finding y=f(x) for
following data:
xi=[0 1 3 4]
yi=[1 3 7 10]
Note: Fit with linear method.
Example 2: Use least square method for fitting and finding y=f(x) for
following data:
x=[-1.3 -0.1 0.2 1.3]
y=[0.103 1.099 0.808 1.897]
Note: Fit straight line.
Equation: 𝑦 = 0.66702𝑥 + 0.96007
Example 3: Use least square method for fitting and finding y=f(x) for following
data:
x=[0 2 4 6 8]
y=[5 4 1 6 7]
Note: Use Quadratic method.
Equation: 𝑦 = 0.2143𝑥 2 − 1.4143𝑥 + 5.1143
Example 4: Use least square method for fitting and finding y=f(x) for following
data:
x=[-1 0 1 2]
y=[3 0 2 8]
Find f(x) for x= 5.3
Find f(x) for x= -1:0.01:1
Note: Use Quadratic method.
Equation: 𝑦 = 2.25𝑥 2 − 0.55𝑥 + 0.15
For x=5.3 → 𝑓(𝑥) = 60.4
For x= -1:0.01:1 → 𝑓 𝑥 = 2.95, 2.90, 2.85, 2.80, ….