MATLAB - Least squares fitting plot

조회 수: 17 (최근 30일)
Tristen Smith
Tristen Smith 2016년 10월 5일
편집: Tristen Smith 2016년 10월 5일
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개)

카테고리

Help CenterFile Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by