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

38 ビュー (過去 30 日間)
Benjamin Horsley
Benjamin Horsley 2021 年 4 月 18 日
コメント済み: Benjamin Horsley 2021 年 4 月 19 日
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.

採用された回答

Robert Brown
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 ExchangeBiological and Health Sciences についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by