Of course, the linear least-square regression is an easy thing to do in Excel. Just adding a linear trend-line to the plot will do that for you. Anyway, I wrote this piece of code to do it in Matlab.
% Single least-square linear regression
%Created on 02/17
x=input ('x='); %use [] to input a row
y=input ('y='); %use [] to input a row
X=mean(x);
Y=mean(y);
beta=(sum((x-X).*(y-Y)))/sum((x-X).^2);
alpa=Y-beta*X;
Equation=strcat('y=',num2str(beta), 'x+',num2str(alpa))
The num2str function was used to convert the beta and alpa, which are numbers, into strings.
The strcat function was used to concatenate the strings.
MATLAB applications, tutorials, examples, tricks, resources,...and a little bit of everything I learned ...
Subscribe to:
Post Comments (Atom)
my-alpine and docker-compose.yml
``` version: '1' services: man: build: . image: my-alpine:latest ``` Dockerfile: ``` FROM alpine:latest ENV PYTH...
-
It took me a while to figure out how to insert a space in Mathtype equations. This is especially useful when you write an equation with mult...
-
Recently I read post from Dr. Doug Hull's blog: http://blogs.mathworks.com/videos/2009/10/23/basics-volume-visualization-19-defining-s...
-
A couple of days ago, I plotted about twenty figures and was trying to set the markers with thicker edge. This would be very easy if it was ...
You can also calculate the least squares coefficients by using MATLAB's backslash operator to "divide" the dependent variable by the independent variables:
ReplyDeleteCoeff = Input \ Output;
See my posting on this at:
http://matlabdatamining.blogspot.com/2007/04/linear-regression-in-matlab.html