MATLAB - Least squares fitting plot
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos

if true
% code function [a1,a2]=fitQuadraticNoIntercept(x,y)
x=[10,20,30,40,50,60,70,80];
y=[25,75,380,550,610,1220,830,1450];
sumx^2=sum(x(i)*x(i));
sumx^3=x(i)*(x(i)^2);
sumx^4=x(i)*(x(i)^3);
sum=x(i)*y;
sumx^2y=(x(i)^2)*y;
a1=(((sumxy)*(sumx^4))-((sumx^2y)*(sumx^3)))/(((sumx^2)*sumx^4)-(((sumx^3)^2))
a2=(((sumx^2)*(sumx^2y)-((sumxy)*(sumx^3)))/(((sumx^2)*sumx^4)-(((sumx^3)^2))
end
function [a1,a2]=SmithTristenHW2pb2(x,y)
[a1,a2]=fitQuadraticNoIntercept(x,y);
plot(x, y, 'b*', 'LineWidth', 2, 'MarkerSize', 15);
coeffs = polyfit(x, y, 1);
% Get fitted values
fittedX = linspace(min(x), max(x), 200);
fittedY = polyval(coeffs, fittedX);
% Plot the fitted line
hold on;
plot(fittedX, fittedY, 'r-', 'LineWidth', 3);
xlabel('x')
ylabel('y')
end
end
This is about as far as I got I really need help on how to plot this least squares regression graph...
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Fit Postprocessing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!