Approximating an Intersection Point Between 2 Sets of Data
조회 수: 17 (최근 30일)
이전 댓글 표시
Hello - I've tried multiple ways to find an intersection point between two curves. The format of my data is two data sets, one set polynomial XY data (stress-strain) and one set linear XY data (0.2% offset curve). I've tried:
find(stress == offset); %This returns an empty answer
int = intersect(stress, offset); %This also returns an empty answer
I've then generated a polynomial from stress with 100,000 points and tried this again:
sp = polyfit(strain, stress, 7);
op = polyfit(offsetstrain, offset, 7);
x = linspace(0, offsetmax, 100000);
sp1 = polyval(sp, x);
op1 = polyval(op, x);
And still - I can't find an intersection point between the artificially generated curves or the raw data using "find" or intersect". Am I missing something?
댓글 수: 0
답변 (1개)
Star Strider
2017년 11월 8일
Use the fzero function, subtracting your two polynomials to get the point where the curves intersect:
Example —
sp = [4 3 2 1];
op = [8 7 6 5];
f = @(x) polyval(sp, x) - polyval(op, x);
x_int = fzero(f, 1);
xv = linspace(-1.5, 0.5);
figure(1)
plot(xv, polyval(op, xv), xv, polyval(sp, xv))
hold on
plot(x_int, polyval(sp, x_int), 'pg', 'MarkerSize',10, 'MarkerFaceColor','g')
hold off
grid
댓글 수: 1
John D'Errico
2017년 11월 8일
The point of course, is you are thinking "intersection". So you look in MATLAB, and find the function intersect. Of course that must do what you want.
But intersect performs a set intersection. Think Venn diagrams, etc. You have a curve, defined by a set of points. Then you fit it using polynomials, but they are still not sets, just functions.
So you need to do as Star said, subtract the curves. Then look for a root of the difference.
Your problem arose here because of your mental description of the problem you want to solve.
참고 항목
카테고리
Help Center 및 File Exchange에서 Stress and Strain에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!