Least Square Method Output: 2 parameters and residual

Hi there,
for an university project we need urgent help.
1) We need to estimate 2 parameters (intercept with y-axes, and the slope of the line) and the residual of a stochastic model by using 2 columns. The problem is if we use lsqr we only get the slope and the residual.
2) We imported some data using xlsread and matlab created a variable as a table. We want to create a Matrice with some data out of the table and don't know the correct syntax for doing that, because the colummns and rows are not named with letters, so we don't how to adress for example row 2 and column 3.
Best wishes and thank you for your help! Steffen

답변 (1개)

Chad Greene
Chad Greene 2015년 5월 24일
You can use polyfit to get the slope and y intercept. Below we create some data that should have a slope of 2, and we'll add some random noise to make it realistic:
% Create and plot some data:
x = 1:10;
y = 2*x + 3*randn(size(x)) + 6;
plot(x,y,'bo')
box off
hold on
% calculate slope and y-intercept of linear fit:
p = polyfit(x,y,1);
slope = p(1);
y_intercept = p(2);
LinearFit = slope*x + y_intercept;
Residuals = y-LinearFit;
% plot linear fit:
plot(x,LinearFit,'k-')
legend('data','linear fit','location','northwest')
legend boxoff

카테고리

도움말 센터File Exchange에서 Signal Generation, Analysis, and Preprocessing에 대해 자세히 알아보기

질문:

2015년 5월 24일

댓글:

2015년 8월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by