how to find slope and intercept.

  • Permalink
  • submit to reddit
  • Email
  • Follow


If i have a linear trend that starts at x and y axis values that are above
and right of the origin how can I:

a - interpolate back to find the intercept
b - find an interpolated value at a given point on the trend

I know that the straight line is y= Mx+C but can't see how to apply this.

thanks in anticipation
SS.


0
Reply webmaster6643 (70) 1/22/2004 10:20:51 PM

See related articles to this posting

"SS" <webmaster@srsteel.co.uk> wrote in
news:bupibs$d58$1@news.freedom2surf.net: 

> 
> If i have a linear trend that starts at x and y axis values that are
> above and right of the origin how can I:
> 
> a - interpolate back to find the intercept

You cannot interpolate to find the intercept.  You must extropolate

Scott
0
Reply namdiesttocs (1202) 1/22/2004 10:33:04 PM

oops.
thats what I meant...

silly me.

SS


0
Reply webmaster6643 (70) 1/22/2004 10:40:58 PM

SS,

If the equation of your line is
y=Mx+C then the Y-intercept can be found by setting X=0 and solving
the equation for y. The X-intercept can be found by setting Y=0 and
solving the equation for X. The slope of the line, M, is:

M = (y2-y1)/(x2-x1) where (x1,y1) and (x2,y2) are points on the line.
Hint: the intercepts are points on the line.

hope that helps,

Scott
0
Reply no18 (4536) 1/22/2004 10:44:06 PM

what I was really hoping for was a pointer to the help command.
I should probably have asked directly what the help command i needed was.

I found 'help interp'

but can't find what the help command is for extrapolation....

SS


0
Reply webmaster6643 (70) 1/22/2004 10:53:14 PM

When you view "help interp" it will show related functions at the
bottom of the help dialog box. Extrapolation should show up there.

hth,

Scott
0
Reply no18 (4536) 1/22/2004 11:29:08 PM

what i see is:

>> help interp

 INTERP Resample data at a higher rate using lowpass interpolation.
    Y = INTERP(X,R) resamples the sequence in vector X at R times

<snip>

    See also DECIMATE, RESAMPLE, UPFIRDN.


0
Reply webmaster6643 (70) 1/22/2004 11:47:30 PM

On Thu, 22 Jan 2004 23:47:30 +0000, SS wrote:

> what i see is:
> 
>>> help interp
> 
>  INTERP Resample data at a higher rate using lowpass interpolation.
>     Y = INTERP(X,R) resamples the sequence in vector X at R times
> 
> <snip>
> 
>     See also DECIMATE, RESAMPLE, UPFIRDN.

Here's a Matlab function you will find useful.

help lookfor

Dan
0
Reply dan4519 (925) 1/23/2004 12:00:28 AM

Ok - lookfor extrapolate yielded me:

>> lookfor extrapolate
extrapolate_values.m: %EXTRAPOLATE_VALUES
extrapolate_values_RBF.m: %EXTRAPOLATE_VALUES_RBF
extrapolate_values.m: %EXTRAPOLATE_VALUES
extrapolate_values_RBF.m: %EXTRAPOLATE_VALUES_RBF

but when i then do :
>> help extrapolate _values
I get
extrapolate.m not found.

Am i missing the point?

in the meantime - I've got...
======================================
x = [ 2  2.5  3  3.5  4]
y = [0.0073  0.0086  0.0099  0.0112  0.0125]
%m = (y2-y1)/(x2-x1)
m =  (0.0125 - 0.0073) / (5.4 - 2)
plot (x,y)
======================================

from my values above
0.0125 = 4m + c
0.0073 = 2m + c

subtracting gives

0.0052 = 2m
so m = 0.0026

substituting back in to solve for c gives c = 0.0021.

So I could now plug values in and find my desired previously unknown value.
but could I have done this with a simple command in matlab?

=====================================
Incidentally - I think that this is a good example of what seasoned hands
would class as newbies clogging up the NG.
For me the problem is - I'm trying to use Matlab to do occasional bits and
pieces. I struggle to find the time to gain a working knowledge of the prog'
I tend to find that the help system is less than useful at times.
I know I want to extrapolate some values but the commands I've used to try
to find the info within the system have yielded me nothing useful.
The command must be there but i've wasted time looking for it with no
benefit.

I'm pretty sure this is why some (not all) of us lesser users tend to jump
in and just ask the question...'how do I...?'

but still...thanks for the help so far..
I'm off to bed.

SS.




0
Reply webmaster6643 (70) 1/23/2004 12:19:16 AM

SS wrote:
> what I was really hoping for was a pointer to the help command.
> I should probably have asked directly what the help command i needed
> was.
>
> I found 'help interp'
>
> but can't find what the help command is for extrapolation....
>
> SS

Since you're trying to extrapolate a line back to the X and Y axes, you
actually don't need to use a command line INTERP or anything like that -- 
backslash will do all you need.   If you have X and Y data in column vectors
(which looking back in the thread, it sounds like you do) the following
gives you the coefficients of the best-fit line:

MB = [X ones(size(X))] \ Y;

% Each row of the corresponding linear system is x*MB(1) + MB(2) = y
% for corresponding elements of x and y.

The equation of the best fit line is y = MB(1)*x  + MB(2).  Now that you
have the equation of the line, finding the intercepts is a simple matter of
plug-and-chug.

-- 
Steve Lord
slord@mathworks.com


0
Reply slord (13688) 1/23/2004 1:19:38 PM

SS,

Use polyfit(x,y,n) to find the least squares fit
to your data.

 >> x = [ 2  2.5  3  3.5  4]
x =
     2.0000    2.5000    3.0000    3.5000    4.0000
 >> y = [0.0073  0.0086  0.0099  0.0112  0.0125]
y =
     0.0073    0.0086    0.0099    0.0112    0.0125
 >> polyfit(x,y,1)
ans =
     0.0026    0.0021

The answer from polyfit means: y = .0026*x + .0021

If you want to know how it works, then look up
'Least Squares' in your linear algebra book.

Gordon Weast
xPC Target Development
The Mathworks

SS wrote:

> Ok - lookfor extrapolate yielded me:
> 
> 
>>>lookfor extrapolate
> 
> extrapolate_values.m: %EXTRAPOLATE_VALUES
> extrapolate_values_RBF.m: %EXTRAPOLATE_VALUES_RBF
> extrapolate_values.m: %EXTRAPOLATE_VALUES
> extrapolate_values_RBF.m: %EXTRAPOLATE_VALUES_RBF
> 
> but when i then do :
> 
>>>help extrapolate _values
> 
> I get
> extrapolate.m not found.
> 
> Am i missing the point?
> 
> in the meantime - I've got...
> ======================================
> x = [ 2  2.5  3  3.5  4]
> y = [0.0073  0.0086  0.0099  0.0112  0.0125]
> %m = (y2-y1)/(x2-x1)
> m =  (0.0125 - 0.0073) / (5.4 - 2)
> plot (x,y)
> ======================================
> 
> from my values above
> 0.0125 = 4m + c
> 0.0073 = 2m + c
> 
> subtracting gives
> 
> 0.0052 = 2m
> so m = 0.0026
> 
> substituting back in to solve for c gives c = 0.0021.
> 
> So I could now plug values in and find my desired previously unknown value.
> but could I have done this with a simple command in matlab?
> 
> =====================================
> Incidentally - I think that this is a good example of what seasoned hands
> would class as newbies clogging up the NG.
> For me the problem is - I'm trying to use Matlab to do occasional bits and
> pieces. I struggle to find the time to gain a working knowledge of the prog'
> I tend to find that the help system is less than useful at times.
> I know I want to extrapolate some values but the commands I've used to try
> to find the info within the system have yielded me nothing useful.
> The command must be there but i've wasted time looking for it with no
> benefit.
> 
> I'm pretty sure this is why some (not all) of us lesser users tend to jump
> in and just ask the question...'how do I...?'
> 
> but still...thanks for the help so far..
> I'm off to bed.
> 
> SS.
> 
> 
> 
> 

0
Reply gweast (588) 1/23/2004 2:32:20 PM

cheers...

stand by what I said earlier...

always more than one way....
thanks all
:o)

SS


0
Reply webmaster6643 (70) 1/23/2004 6:57:25 PM
comp.soft-sys.matlab 201501 articles. 514 followers. Post

11 Replies
231 Views

Similar Articles

[PageSpeed] 49

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Finding the slope and y intercept of lsline
Hi All I had used lsline function to find the least square line.Can you help me for finding the slope and y intercept of the least square line. Thanks in advance PMN PMN <praveenmn1@gmail.com> wrote in message <908774cc-7a99-4819-9dae-db0f7d4ee65b@o16g2000prh.googlegroups.com>... > Hi All > > I had used lsline function to find the least square line.Can you help > me for finding the slope and y intercept of the least square line. > > Thanks in advance > PMN hi.........no need to use lsline........if u r only want to find out slope and intercept ....o it w...

Slope and Intercept
Hi, I have two columns X and Y. Is there a way to find out the slope and intercept for the columns? Thanks much for the help ...

slope and intercept
Dear MATLAB community, I am trying to determine the slope (a) and intercept (b) for a linear fit y = ax+b. I know the function postreg ([slope,intercept,r] = postreg(x',y']) will do it for me, but I would like to find a function that calculates these parameters without the plot postreg creates Thank you for your inputs, Benoit "Benoit " <igneb@iastate.edu> wrote in message <g36uct$1m6$1@fred.mathworks.com>... > Dear MATLAB community, > > I am trying to determine the slope (a) and intercept (b) for > a linear fit y = ax+b. > > I know the ...

How to find a slope of line.
hi I have a plot with diff values of x and y. i want to find the plot of that linear function slope. like y=mx+c and m= slope. Hi Maulik, Polyfit should help you. Best. ...

Re: Slope and Intercept
Hi, Are you trying to do a regression? If so, proc reg will do. -- Regards, Murphy Choy Certified Advanced Programmer for SAS V9 Certified Basic Programmer for SAS V9 DataShaping Certified SAS Professional -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of sasbegy Sent: Tuesday, April 28, 2009 11:27 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Slope and Intercept Hi, I have two columns X and Y. Is there a way to find out the slope and intercept for the columns? Thanks much for the help I wonder if sasbegy is referring to point slope and intercep...

extrapolate to find the intercept
hi all, i'm sure this is a simple one but i'm not sure how to do this the most efficient way in matlab: i have a vector x=[2.5;3.456];. how do i extrapolate this vector so that it hits the intercept? or find the intercept in a different way? is there a simple function for that? any help is appreciated. "Linda" wrote in message <l3r34b$7j9$1@newscl01ah.mathworks.com>... > hi all, > > i'm sure this is a simple one but i'm not sure how to do this the most efficient way in matlab: i have a vector x=[2.5;3.456];. how do i extrapolate this vector ...

Finding the slope/ gradient
Hi all I m given a point P in 3-D , (x,y,z ) values. And its 8 connecting points ( 3-D points.... (x,y,z) values) i.e. these 9 points can be considered to be placed in the form of a 3x3 matrix. I have to find the gradient of the plane containing this 9 points at the (2,2) pt P (mid point of the 3x3 matrix). I tried to use the sobel kernal type weighted summation of the difference of the points and then divide it by dx (or dy) but that didnt work out. I am considering that the z value of the (x,y,z) values as the function value.... z=f(x,y). I am not sure if matlab has an inbuilt func...

Error in slope and intercept
I was informing myself about linear regression with error in both observables and found this algorithm: (Weighted Orthogonal Regression by Alternating Least Squares) worals[x_, y_, sx_, sy_] := Block[{a,b,f,z, u = 1/sx, v = 1/sy, w = (sy/sx)^2}, {a,b} = (y*v).PseudoInverse@{v,x*v}; f = #.#&[(a+b*x-y)v]; While[f > (z = (x*w + (y-a)b)/(b^2 + w); {a,b} = (y*v).PseudoInverse@{v,z*v}; f = #.#&@Join[(z-x)u,(a+b*z-y)v])]; {f,{a,b}}] which gives me {chisquare, {intercept, slope}} as output. This works prefectly fine but I'd like to get the error on slo...

finding slope regions
This issue seems simple at first, but has proven to be quite an algorithmic challenge. I&#8217;d appreciate any insights. We have data that appears as combinations of straight lines in log-log plots, say a slope of 0.3 followed by a slope of 1.6. We'd like to fit lines to the data and get their parameters. The data is experimental, so is of course quite noisy, just seems pretty straight in log-slope... In addition, between different slope regions, e.g. slope of 0.3 and 1.6, there are rounded "knees". The knee regions change in curvature and total length from plot to plot, ...

slope
What is the slope-intercept equation of the line that contain the point (3,2) and has slope m=4? What is the slope and y intercept of the line represented by the equation: 2x + 2y =3? Thanks, SH Sonia Haynes wrote: > > > What is the slope-intercept equation of the line that contain the > point (3,2) and has slope m=4? > > What is the slope and y intercept of the line represented by the > equation: 2x + 2y =3? > > Thanks, > SH look in an elementary maths textbook Sonia Haynes wrote: > What is the slope-intercept equation of the line that contain the > po...

Error on slope and intercept
I was informing myself about linear regression with errors in x and y. I dont really understand the theory behind the following algorithm but it would be nice if someone could tell me how i get the error of the intercept and slope. worals[x_, y_, sx_, sy_] := Block[{a, b, f, z, u = 1/sx, v = 1/sy, w = (sy/sx)^2}, {a, b} = (y*v).PseudoInverse@{v, x*v}; f = #.# &[(a + b*x - y) v]; While[f > (z = (x*w + (y - a) b)/(b^2 + w); {a, b} = (y*v).PseudoInverse@{v, z*v}; f = #.# &@Join[(z - x) u, (a + b*z - y) v])]; {f, {a, b}}] Thanks for any help ...

extrapolate to find the intercept #2
hi all, i'm sure this is a simple one but i'm not sure how to do this the most efficient way in matlab: i have a vector x=[2.5;3.456];. how do i extrapolate this vector so that it hits the intercept? or find the intercept in a different way? is there a simple function for that? a) doc interp1 b) doc polyval % and friends c) how would you find slope/intercept w/ simple algebra??? Implement same... -- ...

Re: Slope and Intercept #6
I am not familiar with the excel functions that you mention. If you wish to fit a least squares line to your data, your best solution is to run either Proc Reg or Proc Glm. While you could calculate the two terms my doing the calculations found in any elementary stat book, it is not worth the effort when the procs are there. If you simply want to know the slope of a line drawn between the two extreme points and they have the values of x1, y1 and x2, y2, then the formula is (y2 - y1 )/ ( x2 - x1 ) if I remember my 9th grade geometry class. I don't recall the formula for the intercept off...

Re: Slope and Intercept #2
the SAS equivalent to slope(y1:y100,x1:x100) intercept(y1:y100,x1:x100) is (as already pointed out): proc reg; model y = x ; run; quit; so yes, you are doing linear regression here. There are other ways to do the same calculation, though this is the simplets, if you have SAS/STAT. Robin High UNMC sasbegy <pattukuttani@GMAIL.COM> Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> 04/28/2009 03:04 PM Please respond to sasbegy <pattukuttani@GMAIL.COM> To SAS-L@LISTSERV.UGA.EDU cc Subject Re: Slope and Intercept On Apr 28, 3:41 pm, Shankar <...

Re: Error in slope and intercept
On Wed, Oct 02, 2013 @ 02:53 AM, Gebbo <nicolasgebbo@googlemail.com> wrote: > I was informing myself about linear regression with > error in both observables and found this algorithm: > (Weighted Orthogonal Regression by Alternating Least Squares) > > worals[x_, y_, sx_, sy_] := Block[ > {a,b,f,z, u = 1/sx, v = 1/sy, w = (sy/sx)^2}, > {a,b} = (y*v).PseudoInverse@{v,x*v}; f = #.#&[(a+b*x-y)v]; > While[f > (z = (x*w + (y-a)b)/(b^2 + w); > {a,b} = (y*v).PseudoInverse@{v,z*v}; > f = #.#&@Join[(z-x)u,(a+b*z-y)v])]; >...

slope and intercept values on a graph
Hello, I have [A1], [B1] and [A2] [B2] plotted on a graph using the robust linear regression function. What I want is to manage to show on the graph a textbox the values of slope and intercept of which are calculated by the robust linear regression. At the moment I do it through the property editor. However, I'd like this to be done automatically. Thanks J. "John M" <ioannis.mitsos@gmail.com> wrote in message <iape11$lt5$1@fred.mathworks.com>... > Hello, > > I have [A1], [B1] and [A2] [B2] plotted on a graph using the robust linear regression...

finding multiple intercepts or solutions
Hi I'm new to MatLab and I'm working on a bouncing ball project modeled as a mass-spring-damper. I'm having trouble finding multiple solutions to an expression with the solve command. I'd would like to know all the solutions within a range instead of just the first one. I don't if finding multiple intercepts is possible or not. I'm not look for zeros. ...

finding the slope of annotation lines
Hey all, I am writing a GUI that will load some data, plot it in a figure window using pcolor, and then allow the user to draw lines over it in order to match some of the linear trends in the data. I was using the command 'gline' in order to do this. What we want is the slope of the line, so I was just doing this: line_handle = gline; <<the user then draws a line in the figure window>> X = get(line_handle,'X'); Y = get(line_handle,'Y'); Then I was going to compute the slope of the line from the x and y data. This works fine when I test it from the comma...

Re: Slope and Intercept #5
On Tue, Apr 28, 2009 at 4:00 PM, sasbegy <pattukuttani@gmail.com> wrote: > On Apr 28, 3:41 pm, Shankar <shankar.s...@gmail.com> wrote: > > If you need just "one slope and intercept" from entire data set, then > > Murphy got it right; > > > > You can do that in PROC REG if you have SAS/STAT ; > > > > If you do not have SAS/STAT, perhaps you can use standard solution, > > based on Least-Squares estimates and implement it in a data step; Is > > that what you want to do? > > > > But first I think you need to cla...

Re: Slope and Intercept #3
I have no idea... :) I don't do regressions. I also don't recall the format for writing the slope over many variables, but it's something like sum ((Y-mean(y))/(x-mean(x))) I imagine. In any event, if you don't have PROC REG, then you need to find out the formula for doing it manually, and then do it that way... works out to something similar to: proc sql; select sum ((Y-mean(y))/(x-mean(x))) from dataset; quit; If you want to use more traditional sas, try using PROC MEANS or PROC FREQ to get whatever statistics you need for the calculation. Anyhow, I suggest you reply to...

finding y-intercepts of a curve.
Hi there, hopefully someone can help as this is driving me insane. I have a data set of points that make up a profile of layers deformed by something pushing down from above. I've separated each layer out, and normalised it to y=0, such that when plotted, I have 65 points making a line which starts at y=0, rises, then drops below y=0 for a while, then rises above again, before returning to zero. I need to find the points where this line crosses the y axis (to measure the length of the depression and the surrounding uplifts). The way I have been doing this is by plotting, fitting a shap...

Re: Slope and Intercept #4
I imagine you could do that in PROC SQL easily. Do you know the formula (ie, the math formula) for calculating slope and intercept? -Joe On Tue, Apr 28, 2009 at 3:00 PM, sasbegy <pattukuttani@gmail.com> wrote: > On Apr 28, 3:41 pm, Shankar <shankar.s...@gmail.com> wrote: > > If you need just "one slope and intercept" from entire data set, then > > Murphy got it right; > > > > You can do that in PROC REG if you have SAS/STAT ; > > > > If you do not have SAS/STAT, perhaps you can use standard solution, > > based on Least-Squ...

Re: Slope and Intercept #7
If you don't have SAS/STAT, thus can't use proc reg, another way of getting the slope and intercept with proc corr is: proc corr data=sashelp.class (rename=(height=x weight=y)) outp=output; var y x; run; data _null_; set output; retain mean_x mean_y std_x std_y; if _TYPE_ eq 'MEAN' then do; mean_x=x; mean_y=y; end; else if _TYPE_ eq 'STD' then do; std_x=x; std_y=y; end; else if _TYPE_ eq 'CORR' and _NAME_ eq 'x' then do; slope=std_y/std_x*y; intercept=mean_y-mean_x*slope; put slope=; put inter...

Find different slopes of experimantal data
Hi ! I have a curve that is consisted of a few linear lines, with different slopes. I need to find the location where the change in slope occures. Since the curve is constructed of experimental data, it is noisy, and not quite linear. Also, maximal second derivative does NOT give the right slope change locations. Does anyone have an Idea how to do it elegantly? Thanks a lot!!! In article <1170770273.084282.217230@j27g2000cwj.googlegroups.com>, "Anyutka" <sanyutka@gmail.com> wrote: > Hi ! > > I have a curve that is consisted of a few linear lines, with diff...