CURVE FIT USING MATLAB

 curve fit:

It is the process of constructing a curve or a mathematical function,and it has the relationship b/w orginal data set and predicted data set.

Basically,the curve fit depends upon the polynomial equ...

The polynomial equ are show below:

  1. linear equ/first degree polynomial:y=ax+b;
  2. quadratic equ/second degree polynomial:y=ax^2+bx+c;
  3. cubic equ/third degree polynomial:y=ax^3+bx^2+cx+d;
  4. the degree of polynomial can go 4,5 and so on;

coading for linear and quadratic equ:

clear all
close all
clc
%loading data
cp_data=load('data')
temp=cp_data(:,1)
cp=cp_data(:,2)

%curve fit
co_eff1=polyfit(temp,cp,3);
predicted_cp=polyval(co_eff1,temp)
co_eff2=polyfit(temp,cp,1);
predicted_cp2=polyval(co_eff2,temp)
%compare org fit,predicted fit
plot(temp,cp,LineWidth=3);
hold on
plot(temp,predicted_cp,LineWidth=3)
plot(temp,predicted_cp2,LineWidth=3)
xlabel('temperature')
ylabel('specific heat')
legend('original c_p','cubic polynomial','linear polynomial')

process:

First of all,we load the data into the matlab workspace....

In that data,the first column is temprature and 2nd column is specific heat;all that values assign to the variable called temp and cp...

Then,we will enter to the curve fit process;we wants to find co-effi for that data with the help of polyfit command,which is inbuild in matlab

And,we wants to find predicted value of y;so we will use the command polyval;then we will plot that org data and curve fit,then compare itself...

output:

it will also done by curve fitting tools

process:

  • Go to apps and click curve fitting tools,then simply select x data and y data,
  • It will shown projected line and goodness of fit like results also shown as it is..
  • And then click file and click generate code,the code automatically generates...

split the curve fit:

for clearing the error, we assign data to be splitted...

the code formation as it is..we just split the data...

clear all
close all 
clc
%loading a data
cp_data=load('data');
temp1=cp_data(:,1);
cp1=cp_data(:,2);
%spliting the curve fit
co_efficient1=polyfit(temp1(1:1600),cp1(1:1600),3);
co_efficient2=polyfit(temp1(1600:3200),cp1(1600:3200),3);
predicted_cp1=polyval(co_efficient1,temp1(1:1600))
predicted_cp2=polyval(co_efficient2,temp1(1600:3200))
%plotting org valuve and spliting curve fit value
plot(temp1,cp1,'linewidth',3,'color','g')
hold on
plot(temp1(1:1600),predicted_cp1,'LineWidth',3,'color','b')
plot(temp1(1600:3200),predicted_cp2,'LineWidth',3,'color','r')
xlabel('temp')
ylabel('specific heat')
legend('org data','split data 1','split data 2')

output:

HERE,WE COMPARE CURVE FIT AND SPLIT CURVE FIT GRAPH HAVE DIFFRENCES,THE LINE MUCH LIKE A SAME LINE....


Comments

Popular posts from this blog

simple pendulum using matlab

DRAG FORCE

2r robotic arm