help-octave
[Top][All Lists]
Advanced

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

Linear regression problems


From: Conrad Kopernikus
Subject: Linear regression problems
Date: Tue, 13 May 2014 07:19:09 -0700 (PDT)

Dear Community

I am a newbie and need help. I have this code:
%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

and it doesnt make any linear regression. What am I doing wrong? And are
their any editor in Octave (like in MatLab)? I use Linux Mint ... and can
make my editor to use Octave code. But how to compile from the editor?

Kind regards!



--
View this message in context: 
http://octave.1599824.n4.nabble.com/Linear-regression-problems-tp4664024.html
Sent from the Octave - General mailing list archive at Nabble.com.



reply via email to

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