Approximating an Intersection Point Between 2 Sets of Data
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Star Strider
le 8 Nov 2017
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 commentaire
John D'Errico
le 8 Nov 2017
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.
Voir également
Catégories
En savoir plus sur Stress and Strain dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!