How can I determine the y-intercept from known x and y values?
40 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Robert Brown
2021-4-18
编辑:Robert Brown
2021-4-18
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 !
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Biological and Health Sciences 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!