필터 지우기
필터 지우기

Finding intersection of polyfit and line

조회 수: 14 (최근 30일)
Nicholas
Nicholas 2015년 9월 16일
댓글: Jan Ulbrich 2020년 9월 18일
I am trying to find the intersection between the polyfit of a line and the line y=1. I have the following code:
polyfit(l,FS,3)
int=roots(polyfit(l)-1)
Essentially, I want the value of length when the Factor of safety is 1:

답변 (2개)

dpb
dpb 2015년 9월 16일
Doesn't do any good to fit the data but not save the coefficients of the resulting fit...
b=polyfit(l,FS,3); % Get coefficients of polynomial
[~,ix]=min(abs(FS-1)); % Nearest observed point to 1 is
L0=l(ix); % good guess for starting point
LOne=fsolve(@(b,x) polyval(b,x)-1,L0); % Solve for x where == 1

Walter Roberson
Walter Roberson 2015년 9월 16일
b = polyfit(l,FS,3); % Get coefficients of polynomial
LOne = roots(b - [0 0 0 1]);
LOneReal = LOne(imag(LOne==0));
LOneInRange = LOneReal >= min(l) && LOneReal <= max(l);
This would be empty if there are no real roots in the range.
  댓글 수: 1
Jan Ulbrich
Jan Ulbrich 2020년 9월 18일
I think there is a typo and it should be "LOneReal = LOne(imag(LOne)==0);"

댓글을 달려면 로그인하십시오.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by