How can I determine the y-intercept from known x and y values?

38 visualizaciones (últimos 30 días)
I have a series of known x and y values (both 161x1 double) and I would like to plot a line graph and determine the slope and y-intercept of the data. I know there have been a few similar posts, but I'm just a little confused as to the correct method to perform this. I would like to determine the y-intercept as part of a residual analysis for biomechanical data.
Thank you.

Respuesta aceptada

Robert Brown
Robert Brown el 18 de Abr. de 2021
Editada: Robert Brown el 18 de Abr. de 2021
define a vector, x
x = 1:10
define a slope, m
define an intercept, b
NOTE: I did this for the example, to generate the data, you of course would skip this step
m = 2
b = 17
compute y = m*x + b
NOTE: I did this for the example, to generate the data, you of course would skip this step
y = m * x + b
make a plot of the data, plotting variable x along the x axis, and variable y along the y axis
figure
plot(x,y)
xlabel('x values')
ylabel('y values')
title('plot of x,y values')
solve for slope by the following equation, when expression is order = 1 (no x-squared or x-cubed terms...etc)
slope = (y(end) - y(1)) / (x(end) - x(1))
solve for intercept by computing y - m* x = b
intercept is computed for each of my 10 points (or your 161 points), and is always 17in this example... (or whatever your intercept turns out to be)... as it should be
intercept = y - slope*x
I hope this helps !

Más respuestas (0)

Categorías

Más información sobre Biological and Health Sciences en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by