尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
1
Numerical Methods in Engineering
By
MD Irfan Ali
Thermal & Aerospace Program
School of Mechanical Chemical & Materials
Engineering
Lecture 8 Contents:
Curve Fitting
Or
Regression Analysis
Pre-Requisite Plotting of Data in MATLAB
2
Plotting of Data
Dia. (m) 0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8
Velocity (m/s) 19.2 28.8 38.4 43.2 48 57.6 67.2 76.8
Work (Nm/kg/s) 2898.8 3804.8 4348 4484 4529 4348.3 3804.8 2898.8
3
Plotting of Data
clc
clear all
close all
% entering the diameter readings as a row vector.
d=[0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8];
% entering the velocity values of jet on the pelton wheel in m/s.
u=[19.2 28.8 38.4 43.2 48 57.6 67.2 76.8];
% entering the work done by the pelton wheel in Nm/kg/s.
w=[2898.8 3804.8 4348 4484 4529 4348.3 3804.8 2898.8];
plot(d,w)
title('Diameter vs Work')
xlabel(‘Diameter in meters’)
ylabel(‘Work done in Nm/kg/s’)
grid on
4
5
Plotting of Data
d=[0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8];
u=[19.2 28.8 38.4 43.2 48 57.6 67.2 76.8];
w=[2898.8 3804.8 4348 4484 4529 4348.3 3804.8 2898.8];
plot(d,w, ‘-sk’,d,u,’-pk’)
6
Curve Fitting
‘Curve fitting’ is a technique in which an approximate function or a best fit
is found to the recorded data. Following are the main advantages of ‘curve
fitting’:
 A better and simplified mathematical model can be developed to the
recorded data. Most of the times the step 3 of mathematical model will
become a hint to find a best approximate function to the recorded data.
 Data is often recorded at discrete values of independent variables, and
it is often required to know the estimates of dependent variable at
intermediate values of independent variables.
7
‘polyfit’ Function
Least square method is a powerful method for ‘curve fitting’ readers are
suggested to read this method from any standard book of numerical
methods. In MATLAB software ‘polyfit’ function is used for ‘curve fitting’
which is based on least square method. Below is the syntax for ‘polyfit’
function:
Syntax: polyfit(x,y,n)------------------% ‘x’ independent variable, ‘y’ dependent
variable, ‘n’ degree of polynomial
The above ‘polyfit’ syntax finds the coefficients of polynomial of degree ‘n’
that best fits the data with ‘x’ and ‘y’ by least square method. Since linear
least square method is followed here so always keep ‘n=1’. Table 5.1 shows
the MATLAB syntaxes for various guess functions or best fit functions and
their linear forms to apply linear least square method.
8
Different guess functions and their MATLAB syntaxes
9
Name of guess
function
Mathematical form Conversion to linear
form to apply linear
least square method
Matlab Syntax
Linear function 𝑦 = 𝑎𝑥 + 𝑏 Already in linear form polyfit(x,y,1)
Power function 𝑦 = 𝑎𝑥𝑏 ln 𝑦 = 𝑏𝑙𝑛 𝑥 + ln(𝑎) polyfit(log(x),log(y),1)
Logarithmic
function
𝑦 = 𝑎𝑙𝑛 𝑥 + 𝑏
𝑦 = 𝑎𝑙𝑜𝑔 𝑥 + 𝑏
Already in linear form polyfit(log(x),y,1)
polyfit(log10(x),y,1)
Exponential
function
𝑦 = 𝑎𝑒𝑏𝑥 ln 𝑦 = 𝑏𝑥 + ln(𝑎) polyfit(x,log(y),1)
Reciprocal function
𝑦 =
1
𝑎𝑥 + 𝑏
1
𝑦
= 𝑎𝑥 + 𝑏
Polyfit(x,1./y,1)
Example for Curve Fitting
10
x(independ
ent
variable)
1 2 3 4 5 6 7
y(Dependen
t variable)
4 3.5 3.2 2.6 2.75 2 3
Suppose in an experiment following data is recorded:
Table 2.1
Linear Fit Approximation
Go to command window and execute the below code to get the values of ‘a’ and ‘b’ in the
linear function ‘y=ax+b’.
>>clc
>>clear all
>>x=linspace(1,7,7)------------------% generating row vector ‘x’.
>>y=[4 3.5 3.2 2.6 2.75 2 3]---------% generating row vector ‘y’.
>>p=polyfit(x,y,1)------------------% generates a polynomial ‘p’ where ‘a=p(1)=-0.2304’ and
‘b=p(2)=3.9286’.
p =
-0.2304 3.9286
% so the best linear function that fits the data is ‘𝑦 = −0.2304𝑥 + 3.9286’. Now even at
intermediate point like ‘x=3.5’ the value of ‘y’ can be found using the above linear
function.
11
Exponential Fit Approximation
>>clc
>>clear all
>> x=linspace(1,7,7)
>>y=[4 3.5 3.2 2.6 2.75 2 3]
>>p=polyfit(x,log(y),1)--------% generates a polynomial ‘p’ where ‘b=p(1)’ and ‘a=exp(p(2))
=e1.3850=3.9948’.
p =
-0.0762 1.3850
% so the best exponential fit is ′𝑦 = 3.9948𝑒−0.0762𝑥
′.
12
Power Fit Approximation
>>clc
>>clear all
>>x=linspace(1,7,7)
>>y=[4 3.5 3.2 2.6 2.75 2 3]
>>p=polyfit(log(x),log(y),1)--% generates a polynomial ‘p’ where ‘b=p(1)’ and
‘a=exp(p(2))=e1.3960=4.0390’.
p =
-0.2594 1.3960
% so the best power function fit is ′𝑦 = 4.0390𝑥−0.2594
′.
13
Suppose a cubic function is a best fit for the data in Table 2.1, and then a cubic function should
be used to fit the data. Below is the code to find cubic function best fit of the form′𝑦 = 𝑎1𝑥3
+
𝑎2𝑥2 + 𝑎3𝑥 + 𝑎4′. Now the task is to find the coefficients ‘𝑎1’, ‘𝑎2’, ‘𝑎3’, and ‘𝑎4’.
>>clc
>>clear all
>>x=linspace(1,7,7);
>>y=[4 3.5 3.2 2.6 2.75 2 3]
>>p=polyfit(x,y,3)-------% generates a polynomial ‘p’ where ′𝑝 1 = 𝑎1, 𝑝 2 = 𝑎2, 𝑝 3 =
𝑎3 𝑎𝑛𝑑 𝑝 4 = 𝑎4
′
.
p =
0.0264 -0.2363 0.2087 3.9429
% so the best cubic function fit is ′𝑦 = 0.0264𝑥3 − 0.2363𝑥2 + 0.2087𝑥 + 3.9429′.
Note: p=polyfit(x,y,n) generates a polynomial ‘p’ which is the best fit of degree ‘n’ and the form
is ‘𝑦 = 𝑎1𝑥𝑛 + 𝑎2𝑥𝑛−1 + 𝑎3𝑥𝑛−2 + ⋯ + 𝑎𝑛𝑥 + 𝑎𝑛+1’.
Polynomial Fit Approximation
14
Plotting of Fit
Let’s plot the experimental data and cubic function fit, and observes the
difference. Below is the required code:
clc
clear all
x=linspace(1,7,7);
y=[4 3.5 3.2 2.6 2.75 2 3];-------------------------% experimental data.
yfit=0.0264*x.^3-0.2363*x.^2+0.2087*x+3.9429;---------% Cubic function data.
difference=max(y-yfit)-----% finding the maximum difference between the
experimental data and the fit data.
plot(x,y,'-*k',x,yfit,'-ok')
Following is the output of the above code:
difference =0.3711
15
16
17
Choose The Best Answer
The command used in Matlab for finding best-fit is___________________.
a) ‘polyval’
b) ‘polyfit’
c) ‘xmesh’
d) None of the above
Ans.: b
18
Choose The Best Answer
The linear form of the equation ‘𝑦 =
1
𝑎𝑥+𝑏
’ to apply polyfit function is________.
a) ln 𝑦 = 𝑏𝑙𝑛 𝑥 + ln 𝑎
b)
1
𝑦
= 𝑎𝑥 + 𝑏
c) ln 𝑦 = 𝑏𝑥 + ln(𝑎)
d) None of the above
Ans.: b
19
Choose The Best Answer
The command used in Matlab to draw 2-D plots is ___________________.
a) ‘plot’
b) ‘mesh’
c) ‘pie’
a) None of the above
Ans.: a
20
Summary
In this chapter we covered the following topics
a) Plotting in Matlab
b) Use of ‘polyfit’ function
c) Linear curve fitting
d) Non-linear curve fitting

More Related Content

What's hot

Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
Randa Elanwar
 
Statistical computing with r estatistica - maria l. rizzo
Statistical computing with r   estatistica - maria l. rizzoStatistical computing with r   estatistica - maria l. rizzo
Statistical computing with r estatistica - maria l. rizzo
André Oliveira Souza
 
Error analysis
Error analysisError analysis
Error analysis
Saloni Singhal
 
Merge Sort
Merge SortMerge Sort
Merge Sort
Nikhil Sonkamble
 
Matlab Files
Matlab FilesMatlab Files
Matlab Files
Saloni Singhal
 
Divide & conqre
Divide & conqre Divide & conqre
Divide & conqre
Ammara Siddiqui
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
Philip Schwarz
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
Saloni Singhal
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
Programming Homework Help
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
dusan4rs
 
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
AIST
 
Piecewise Functions
Piecewise FunctionsPiecewise Functions
Piecewise Functions
swartzje
 
Sorting
SortingSorting
Sorting
Ghaffar Khan
 
evaluating recursive_applications
evaluating recursive_applicationsevaluating recursive_applications
evaluating recursive_applications
Rajendran
 
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical Engineering
Debarun Banerjee
 
recursive problem_solving
recursive problem_solvingrecursive problem_solving
recursive problem_solving
Rajendran
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
MuhammadBakri13
 
Selection sort(sorting algorithm in data structure) and its time complexity
Selection sort(sorting algorithm in data structure) and its time complexitySelection sort(sorting algorithm in data structure) and its time complexity
Selection sort(sorting algorithm in data structure) and its time complexity
Computer_ at_home
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithms
snehajiyani
 
Selection sort
Selection sortSelection sort
Selection sort
M Vishnuvardhan Reddy
 

What's hot (20)

Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4Introduction to matlab lecture 4 of 4
Introduction to matlab lecture 4 of 4
 
Statistical computing with r estatistica - maria l. rizzo
Statistical computing with r   estatistica - maria l. rizzoStatistical computing with r   estatistica - maria l. rizzo
Statistical computing with r estatistica - maria l. rizzo
 
Error analysis
Error analysisError analysis
Error analysis
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
Matlab Files
Matlab FilesMatlab Files
Matlab Files
 
Divide & conqre
Divide & conqre Divide & conqre
Divide & conqre
 
The Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterateThe Functional Programming Triad of fold, scan and iterate
The Functional Programming Triad of fold, scan and iterate
 
Matrix operations in MATLAB
Matrix operations in MATLABMatrix operations in MATLAB
Matrix operations in MATLAB
 
Programming Assignment Help
Programming Assignment HelpProgramming Assignment Help
Programming Assignment Help
 
Curve fitting
Curve fittingCurve fitting
Curve fitting
 
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...Dmitrii Tihonkih - The Iterative Closest Points Algorithm and  Affine Transfo...
Dmitrii Tihonkih - The Iterative Closest Points Algorithm and Affine Transfo...
 
Piecewise Functions
Piecewise FunctionsPiecewise Functions
Piecewise Functions
 
Sorting
SortingSorting
Sorting
 
evaluating recursive_applications
evaluating recursive_applicationsevaluating recursive_applications
evaluating recursive_applications
 
Matlab for Chemical Engineering
Matlab for Chemical EngineeringMatlab for Chemical Engineering
Matlab for Chemical Engineering
 
recursive problem_solving
recursive problem_solvingrecursive problem_solving
recursive problem_solving
 
Chapter 14 Searching and Sorting
Chapter 14 Searching and SortingChapter 14 Searching and Sorting
Chapter 14 Searching and Sorting
 
Selection sort(sorting algorithm in data structure) and its time complexity
Selection sort(sorting algorithm in data structure) and its time complexitySelection sort(sorting algorithm in data structure) and its time complexity
Selection sort(sorting algorithm in data structure) and its time complexity
 
Daa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithmsDaa unit 6_efficiency of algorithms
Daa unit 6_efficiency of algorithms
 
Selection sort
Selection sortSelection sort
Selection sort
 

Similar to curve fitting or regression analysis-1.pptx

Different Types of Machine Learning Algorithms
Different Types of Machine Learning AlgorithmsDifferent Types of Machine Learning Algorithms
Different Types of Machine Learning Algorithms
rahmedraj93
 
Regression
RegressionRegression
Regression
ramyaranjith
 
Matlab1
Matlab1Matlab1
Matlab1
guest8ba004
 
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Chyi-Tsong Chen
 
CHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudsko
CHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudskoCHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudsko
CHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudsko
SydneyJaydeanKhanyil
 
Matlab Nn Intro
Matlab Nn IntroMatlab Nn Intro
Matlab Nn Intro
Imthias Ahamed
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
Ameen San
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
Manchireddy Reddy
 
Linear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller AssignmentLinear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller Assignment
Isham Rashik
 
Octave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning AlgorithmsOctave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning Algorithms
Craig Trim
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
Naveed Rehman
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
Abd El Kareem Ahmed
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
Lincoln Hannah
 
Solution of matlab chapter 3
Solution of matlab chapter 3Solution of matlab chapter 3
Solution of matlab chapter 3
AhsanIrshad8
 
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Universitat Politècnica de Catalunya
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
meerobertsonheyde608
 
Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Chyi-Tsong Chen
 
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
Hansol Kang
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Matlab practical file
Matlab practical fileMatlab practical file
Matlab practical file
Archita Misra
 

Similar to curve fitting or regression analysis-1.pptx (20)

Different Types of Machine Learning Algorithms
Different Types of Machine Learning AlgorithmsDifferent Types of Machine Learning Algorithms
Different Types of Machine Learning Algorithms
 
Regression
RegressionRegression
Regression
 
Matlab1
Matlab1Matlab1
Matlab1
 
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 07 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
 
CHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudsko
CHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudskoCHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudsko
CHAPTER 7.pdfdjdjdjdjdjdjdjsjsjddhhdudsko
 
Matlab Nn Intro
Matlab Nn IntroMatlab Nn Intro
Matlab Nn Intro
 
Matlab polynimials and curve fitting
Matlab polynimials and curve fittingMatlab polynimials and curve fitting
Matlab polynimials and curve fitting
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Linear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller AssignmentLinear Control Hard-Disk Read/Write Controller Assignment
Linear Control Hard-Disk Read/Write Controller Assignment
 
Octave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning AlgorithmsOctave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning Algorithms
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Solution of matlab chapter 3
Solution of matlab chapter 3Solution of matlab chapter 3
Solution of matlab chapter 3
 
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018Backpropagation - Elisa Sayrol - UPC Barcelona 2018
Backpropagation - Elisa Sayrol - UPC Barcelona 2018
 
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
Ch 02 MATLAB Applications in Chemical Engineering_陳奇中教授教學投影片
 
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
딥러닝 중급 - AlexNet과 VggNet (Basic of DCNN : AlexNet and VggNet)
 
Numerical methods generating polynomial
Numerical methods generating polynomialNumerical methods generating polynomial
Numerical methods generating polynomial
 
Matlab practical file
Matlab practical fileMatlab practical file
Matlab practical file
 

Recently uploaded

Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl LucknowCall Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
yogita singh$A17
 
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptxMODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
NaveenNaveen726446
 
Basic principle and types Static Relays ppt
Basic principle and  types  Static Relays pptBasic principle and  types  Static Relays ppt
Basic principle and types Static Relays ppt
Sri Ramakrishna Institute of Technology
 
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
simrangupta87541
 
CSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdfCSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdf
Ismail Sultan
 
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
nonods
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
Kamal Acharya
 
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort ServiceCuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
yakranividhrini
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
drshikhapandey2022
 
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
aarusi sexy model
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
LokerXu2
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
Guangdong Ctube Industry Co., Ltd.
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
felixwold
 
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
shourabjaat424
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 
Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
Kamal Acharya
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
ShivangMishra54
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Tsuyoshi Horigome
 
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call GirlCall Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
sapna sharmap11
 

Recently uploaded (20)

Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl LucknowCall Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
Call Girls In Lucknow 🔥 +91-7014168258🔥High Profile Call Girl Lucknow
 
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptxMODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
MODULE 5 BIOLOGY FOR ENGINEERS TRENDS IN BIO ENGINEERING.pptx
 
Basic principle and types Static Relays ppt
Basic principle and  types  Static Relays pptBasic principle and  types  Static Relays ppt
Basic principle and types Static Relays ppt
 
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
 
CSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdfCSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdf
 
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
 
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort ServiceCuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
Cuttack Call Girls 💯Call Us 🔝 7374876321 🔝 💃 Independent Female Escort Service
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
 
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
 
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 
Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
 
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call GirlCall Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
 

curve fitting or regression analysis-1.pptx

  • 1. 1 Numerical Methods in Engineering By MD Irfan Ali Thermal & Aerospace Program School of Mechanical Chemical & Materials Engineering Lecture 8 Contents: Curve Fitting Or Regression Analysis Pre-Requisite Plotting of Data in MATLAB
  • 2. 2 Plotting of Data Dia. (m) 0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8 Velocity (m/s) 19.2 28.8 38.4 43.2 48 57.6 67.2 76.8 Work (Nm/kg/s) 2898.8 3804.8 4348 4484 4529 4348.3 3804.8 2898.8
  • 3. 3 Plotting of Data clc clear all close all % entering the diameter readings as a row vector. d=[0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8]; % entering the velocity values of jet on the pelton wheel in m/s. u=[19.2 28.8 38.4 43.2 48 57.6 67.2 76.8]; % entering the work done by the pelton wheel in Nm/kg/s. w=[2898.8 3804.8 4348 4484 4529 4348.3 3804.8 2898.8]; plot(d,w) title('Diameter vs Work') xlabel(‘Diameter in meters’) ylabel(‘Work done in Nm/kg/s’) grid on
  • 4. 4
  • 5. 5 Plotting of Data d=[0.2 0.3 0.4 0.45 0.5 0.6 0.7 0.8]; u=[19.2 28.8 38.4 43.2 48 57.6 67.2 76.8]; w=[2898.8 3804.8 4348 4484 4529 4348.3 3804.8 2898.8]; plot(d,w, ‘-sk’,d,u,’-pk’)
  • 6. 6
  • 7. Curve Fitting ‘Curve fitting’ is a technique in which an approximate function or a best fit is found to the recorded data. Following are the main advantages of ‘curve fitting’:  A better and simplified mathematical model can be developed to the recorded data. Most of the times the step 3 of mathematical model will become a hint to find a best approximate function to the recorded data.  Data is often recorded at discrete values of independent variables, and it is often required to know the estimates of dependent variable at intermediate values of independent variables. 7
  • 8. ‘polyfit’ Function Least square method is a powerful method for ‘curve fitting’ readers are suggested to read this method from any standard book of numerical methods. In MATLAB software ‘polyfit’ function is used for ‘curve fitting’ which is based on least square method. Below is the syntax for ‘polyfit’ function: Syntax: polyfit(x,y,n)------------------% ‘x’ independent variable, ‘y’ dependent variable, ‘n’ degree of polynomial The above ‘polyfit’ syntax finds the coefficients of polynomial of degree ‘n’ that best fits the data with ‘x’ and ‘y’ by least square method. Since linear least square method is followed here so always keep ‘n=1’. Table 5.1 shows the MATLAB syntaxes for various guess functions or best fit functions and their linear forms to apply linear least square method. 8
  • 9. Different guess functions and their MATLAB syntaxes 9 Name of guess function Mathematical form Conversion to linear form to apply linear least square method Matlab Syntax Linear function 𝑦 = 𝑎𝑥 + 𝑏 Already in linear form polyfit(x,y,1) Power function 𝑦 = 𝑎𝑥𝑏 ln 𝑦 = 𝑏𝑙𝑛 𝑥 + ln(𝑎) polyfit(log(x),log(y),1) Logarithmic function 𝑦 = 𝑎𝑙𝑛 𝑥 + 𝑏 𝑦 = 𝑎𝑙𝑜𝑔 𝑥 + 𝑏 Already in linear form polyfit(log(x),y,1) polyfit(log10(x),y,1) Exponential function 𝑦 = 𝑎𝑒𝑏𝑥 ln 𝑦 = 𝑏𝑥 + ln(𝑎) polyfit(x,log(y),1) Reciprocal function 𝑦 = 1 𝑎𝑥 + 𝑏 1 𝑦 = 𝑎𝑥 + 𝑏 Polyfit(x,1./y,1)
  • 10. Example for Curve Fitting 10 x(independ ent variable) 1 2 3 4 5 6 7 y(Dependen t variable) 4 3.5 3.2 2.6 2.75 2 3 Suppose in an experiment following data is recorded: Table 2.1
  • 11. Linear Fit Approximation Go to command window and execute the below code to get the values of ‘a’ and ‘b’ in the linear function ‘y=ax+b’. >>clc >>clear all >>x=linspace(1,7,7)------------------% generating row vector ‘x’. >>y=[4 3.5 3.2 2.6 2.75 2 3]---------% generating row vector ‘y’. >>p=polyfit(x,y,1)------------------% generates a polynomial ‘p’ where ‘a=p(1)=-0.2304’ and ‘b=p(2)=3.9286’. p = -0.2304 3.9286 % so the best linear function that fits the data is ‘𝑦 = −0.2304𝑥 + 3.9286’. Now even at intermediate point like ‘x=3.5’ the value of ‘y’ can be found using the above linear function. 11
  • 12. Exponential Fit Approximation >>clc >>clear all >> x=linspace(1,7,7) >>y=[4 3.5 3.2 2.6 2.75 2 3] >>p=polyfit(x,log(y),1)--------% generates a polynomial ‘p’ where ‘b=p(1)’ and ‘a=exp(p(2)) =e1.3850=3.9948’. p = -0.0762 1.3850 % so the best exponential fit is ′𝑦 = 3.9948𝑒−0.0762𝑥 ′. 12
  • 13. Power Fit Approximation >>clc >>clear all >>x=linspace(1,7,7) >>y=[4 3.5 3.2 2.6 2.75 2 3] >>p=polyfit(log(x),log(y),1)--% generates a polynomial ‘p’ where ‘b=p(1)’ and ‘a=exp(p(2))=e1.3960=4.0390’. p = -0.2594 1.3960 % so the best power function fit is ′𝑦 = 4.0390𝑥−0.2594 ′. 13
  • 14. Suppose a cubic function is a best fit for the data in Table 2.1, and then a cubic function should be used to fit the data. Below is the code to find cubic function best fit of the form′𝑦 = 𝑎1𝑥3 + 𝑎2𝑥2 + 𝑎3𝑥 + 𝑎4′. Now the task is to find the coefficients ‘𝑎1’, ‘𝑎2’, ‘𝑎3’, and ‘𝑎4’. >>clc >>clear all >>x=linspace(1,7,7); >>y=[4 3.5 3.2 2.6 2.75 2 3] >>p=polyfit(x,y,3)-------% generates a polynomial ‘p’ where ′𝑝 1 = 𝑎1, 𝑝 2 = 𝑎2, 𝑝 3 = 𝑎3 𝑎𝑛𝑑 𝑝 4 = 𝑎4 ′ . p = 0.0264 -0.2363 0.2087 3.9429 % so the best cubic function fit is ′𝑦 = 0.0264𝑥3 − 0.2363𝑥2 + 0.2087𝑥 + 3.9429′. Note: p=polyfit(x,y,n) generates a polynomial ‘p’ which is the best fit of degree ‘n’ and the form is ‘𝑦 = 𝑎1𝑥𝑛 + 𝑎2𝑥𝑛−1 + 𝑎3𝑥𝑛−2 + ⋯ + 𝑎𝑛𝑥 + 𝑎𝑛+1’. Polynomial Fit Approximation 14
  • 15. Plotting of Fit Let’s plot the experimental data and cubic function fit, and observes the difference. Below is the required code: clc clear all x=linspace(1,7,7); y=[4 3.5 3.2 2.6 2.75 2 3];-------------------------% experimental data. yfit=0.0264*x.^3-0.2363*x.^2+0.2087*x+3.9429;---------% Cubic function data. difference=max(y-yfit)-----% finding the maximum difference between the experimental data and the fit data. plot(x,y,'-*k',x,yfit,'-ok') Following is the output of the above code: difference =0.3711 15
  • 16. 16
  • 17. 17 Choose The Best Answer The command used in Matlab for finding best-fit is___________________. a) ‘polyval’ b) ‘polyfit’ c) ‘xmesh’ d) None of the above Ans.: b
  • 18. 18 Choose The Best Answer The linear form of the equation ‘𝑦 = 1 𝑎𝑥+𝑏 ’ to apply polyfit function is________. a) ln 𝑦 = 𝑏𝑙𝑛 𝑥 + ln 𝑎 b) 1 𝑦 = 𝑎𝑥 + 𝑏 c) ln 𝑦 = 𝑏𝑥 + ln(𝑎) d) None of the above Ans.: b
  • 19. 19 Choose The Best Answer The command used in Matlab to draw 2-D plots is ___________________. a) ‘plot’ b) ‘mesh’ c) ‘pie’ a) None of the above Ans.: a
  • 20. 20 Summary In this chapter we covered the following topics a) Plotting in Matlab b) Use of ‘polyfit’ function c) Linear curve fitting d) Non-linear curve fitting
  翻译: