How can I fit a curve to x, y points and obtain the regression?
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I have plotted x vs y and obtained a plot of points, now I'm trying to fit a curve to my data using a nonlinear polynomial of order 4, the coeficiants are unknown.
I aim to obtain the regression coefficient as well.
Any idea how it is possible to do this? what are the suitable matlab functions to plot the fitting curve and to obtain the regression coeficient?
I already tried polyfit, but is it correct? if yes then how to proceed?
0 comentarios
Respuestas (3)
  KSSV
      
      
 el 19 de Nov. de 2018
        
      Editada: KSSV
      
      
 el 19 de Nov. de 2018
  
      Yes polyfit is the function you need. 
x = linspace(0,4*pi,50);
y = sin(x);
% Use polyfit to fit a 4th-degree polynomial to the points.
p = polyfit(x,y,7);
% Evaluate the polynomial on a finer grid and plot the results.
x1 = linspace(0,4*pi);
y1 = polyval(p,x1);
figure
plot(x,y,'o')
hold on
plot(x1,y1)
hold off
In the above p has your coefficients. YOu can use poly2sym to see the polynomial obtained. 
11 comentarios
  madhan ravi
      
      
 el 19 de Nov. de 2018
        x = linspace(0,4*pi,50);
y = sin(x);
xx = linspace(x(1),x(end),1000);
yy = interp1(x,y,xx,'spline')
plot(x,y,'o',xx,yy)
3 comentarios
Ver también
Categorías
				Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



