help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Linear regression


From: Hannibal Smith
Subject: Linear regression
Date: Tue, 13 May 2014 16:26:49 +0200

What is wrong with my linear regression?
%konstanter defineres
h=6.62606957*10^-34;
c=3*10^8;
e=1.60217657*10^-19;
%xu er den ufærdige x-værdi!
xu = [366 405 436 492 546 570];
x = c./(xu*10^(-9));
y = [1.48 1.15 0.93 0.62 0.36 0.24];
% Create a function to plot the data
function plotData(x,y)
plot(x,y,'rx','MarkerSize',8); % Plot the data
end
% Plot the data
plotData(x,y);
xlabel('frekvensen [Hz]'); % Set the x-axis label
ylabel('V(0)'); % Set the y-axis label
% Count how many data points we have
m = length(x);
% Add a column of all ones (intercept term) to x
X = [ones(m, 1) x];
% Calculate theta
theta = (pinv(x'*x))*x'*y;
% Plot the fitted equation we got from the regression
hold on; % this keeps our previous plot of the training data visible
plot(x(:,2), x*theta, '-')
legend('Training data', 'Linear regression')
grid on
hold off % Don't put any more plots on this figure

thansk for help :)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]