Fit points to curve with zero slope

조회 수: 1 (최근 30일)
Niclas Madsen
Niclas Madsen 2018년 8월 21일
편집: Torsten 2018년 8월 21일
Hi
I have to fit a set of coordinates (two points) to a linear slope, however, in one case I know the slope is 0. I'm using polyfit.
polyfit([x1 x2], [y1 y2], 1)
This returns a slope coefficient of -263.0023e-018.
I know the slope for this specific case is 0, but I want to make my script able to handle changes to input, which is why I don't want to manually change the slope coefficient. While e-018 might be accurate enough for the task at hand, I'd like to be able to do it correctly.
So how do I fit two points to a linear curve where the slope is 0?

채택된 답변

Torsten
Torsten 2018년 8월 21일
편집: Torsten 2018년 8월 21일
The polynomial is given by
p = (sum_{i=1}^{n} yi) / n
where
(x1,y1), (x2,y2), ..., (xn,yn)
are the given data points.
In your case:
p = (y1+y2)/2
Best wishes
Torsten.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by