help-octave
[Top][All Lists]
Advanced

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

Re: polyfit with a fixed slope ??


From: James Sherman Jr.
Subject: Re: polyfit with a fixed slope ??
Date: Tue, 25 May 2010 09:19:30 -0400

I believe it becomes trivial actually, since you just need to find the y-intercept of the y = mx+b equation.  If you want to use all your points to estimate, let X, Y be your data vectors of length n, and m be the specified slope, then you're solving the equation:

Y = m*X + b*ones(n, 1)

for b.  So, solving it in a least squares sense becomes:

b = ones(n, 1)\(Y-m*x);
(there are other ways to solve this using matrix manipulations, such as pinv)

But this is a bit of overkill, since this problem is in one-dimension:
b = mean(Y-m*X);

Of course, there are other ways to do the optimization without using least squares, but off the top of my head I don't know if you're interested in these or the if/how to do them easily in octave.

2010/5/25 Oisín Ó Cuanacháin <address@hidden>
Hi,

Does anyone know if there is a function to fit a line with a specified slope to some data. I have a load of data 'x' and
polyfit(1:length(x),x,1) gives me the best-fit line, with arbitrary slope.
What I want however is the best fit line with a particular slope. This is essentially just a minimization problem and I know I could code something up myself, but x has 100's of millions of elements I'm guessing my coding efforts will take forever to run, so does such a nice function already exist? It is essentially polyfit with an added constraint that the slope is fixed.

Thanks,

Oisín.

_______________________________________________
Help-octave mailing list
address@hidden
https://www-old.cae.wisc.edu/mailman/listinfo/help-octave



reply via email to

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