Project

Curve Fitting

Curve Fitting

Aim:

  • Write code to fit a linear and cubic polynomial for the Cp data.
  • Plot the linear and cubic fit curves along with the raw data points. Title and axes labels are a must, legends could be shown if necessary.
  • Explain the parameters used to measure the fitness characteristics for both the curves.

Theory:

Curve fitting is one of the most powerful and most widely used analysis tools in Origin. Curve fitting examines the relationship between one or more predictors (independent variables) and a response variable (dependent variable), with the goal of defining a "best fit" model of the relationship.

Origin provides tools for linear, polynomial, and nonlinear curve fitting along with validation and goodness-of-fit tests. You can summarize and present your results with customized fitting reports. There are many time-saving options such as a copy-and-paste-operation feature which allows you to "paste" a just-completed fitting operation to another curve or data column. Curve fitting operations can also be part of an Analysis Template™, allowing you to perform batch fitting operations on any number of data files or data columns.

  • Linear, Polynomial, and Multiple Regression
  • Nonlinear Curve Fitting
  • Surface Fitting
  • Compare Models and Datasets
  • Time-Saving Fitting Options

Linear, Polynomial, and Multiple Regression

Linear and Polynomial regressions in Origin make use of weighted least-square method to fit a linear model function or a polynomial model function to data, respectively.

Linear Fit



Polynomial Fit

The Polynomial Fit tool in Origin can fit data with polynomial up to 9th order. Fixed intercept and apparent fit are also supported.

Multiple Linear Regression

Multiple Linear Regression fits multiple independent variables

A unique feature of Origin's Multiple Linear Regression is Partial Leverage Plots, useful in studying the relationship between the independent variable and a given dependent variable:

Program:

clear all 

clc

close all



%%preparin data

cp_data=load('data');

Temp=cp_data(:,1);

Specificheat= cp_data(:,2);

n=1;

%%

%Line fit using splitting the rang%



coeff1=polyfit(Temp,Specificheat,1);%%fourth order equation used 

predicted_cp1=polyval(coeff1,Temp);

figure(1)

hold on

plot(Temp,Specificheat)

plot(Temp,predicted_cp1)

title('Line fiting linear')

%%

%Line fit using splitting the rang%



coeff1=polyfit(Temp,Specificheat,2);%%fourth order equation used 

predicted_cp2=polyval(coeff1,Temp);

figure(2)

hold on

plot(Temp,Specificheat)

plot(Temp,predicted_cp2)

title('Line fiting quadratic')



%%

%Line fit using splitting the rang%



coeff1=polyfit(Temp,Specificheat,3);%%fourth order equation used 

predicted_cp3=polyval(coeff1,Temp);

figure(3)

hold on

plot(Temp,Specificheat)

plot(Temp,predicted_cp3)

title('Line fiting cubic')



%%%Line fit using splitting the rang%

%%

coeff1=polyfit(Temp,Specificheat,4);%%fourth order equation used 

predicted_cp4=polyval(coeff1,Temp);

figure(4)

hold on

subplot

plot(Temp,Specificheat)

plot(Temp,predicted_cp4)

title('Line fiting fourth order')

The above code describes how to do a curve fitting using Matlab. Here i have used a polyfit command for curve fitting a comparison done by using different type of polynomials. According to the theory if we use higher order polynomial the best will be the FIT. but we have a problem with matlab if we increase the order there will be least conditioned fit. So inorder to tackle we use split wise polynomial i.e. defining a polynomial for a certain range of values and splitting the data.

clear all 

clc

close all



%%preparin data

cp_data=load('data');

Temp=cp_data(:,1);

Specificheat= cp_data(:,2);

n=7;

%

Line fit using splitting the rang%



specificheat1=Specificheat(1:500)

temp1=Temp(1:500)

coeff1=polyfit(temp1,specificheat1,4);%%fourth order equatio used 

predicted_cp1=polyval(coeff1,temp1);




specificheat2=Specificheat(501:1000)

temp2=Temp(501:1000)

coeff2=polyfit(temp2,specificheat2,2);

predicted_cp2=polyval(coeff2,temp2);




specificheat3=Specificheat(1001:1500)

temp3=Temp(1001:1500)

coeff3=polyfit(temp3,specificheat3,2);

predicted_cp3=polyval(coeff3,temp3);



specificheat4=Specificheat(1501:2000)

temp4=Temp(1501:2000)

coeff4=polyfit(temp4,specificheat4,2);

predicted_cp4=polyval(coeff4,temp4);



specificheat5=Specificheat(2001:3200)

temp5=Temp(2001:3200)

coeff5=polyfit(temp5,specificheat5,2);

predicted_cp5=polyval(coeff5,temp5);



hold on

plot(Temp,Specificheat)

plot(temp1,predicted_cp1)

plot(temp2,predicted_cp2)

plot(temp3,predicted_cp3)

% plot(temp4,predicted_cp4)

plot(temp5,predicted_cp5)

xlabel('Temperature')

ylabel('Cp')

title('Curve Fitting using quadratic equation')



error1=Specifheat-predicted_cp1;



%initial%

sse=0;

sum1=0;

for i=1:length(Specificheat)

    SSE1=sse+error1.^2;

    SUM1=sum1+Specificheat(i);

    




Result:

The below are the plot used to describe the Curve fitting . First plot is used to compare the various order of polynomial and how the fit will be is analysed as well as we can see that when the higher the order the good the fit is . But the polynomial is least conditioned so we use the process called splitting the data points to small groups and trying to plot the curve with lower order polynomial thus we can fit easily.














Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.