I have two Listsoflist containing x and y coordinates. Now, I want to plot the two profiles, show their intersection and find the area of each intersecting region. I have used interpolating function to find the plots but unable find intersection point.
Asked
Active
Viewed 72 times
1
-
2Can you please provide us with the two lists, so that we can use them in the answer? – Fraccalo Aug 22 '18 at 18:33
-
2Then create a fake test case for us that has the same structrure, but is smaller. – Marius Ladegård Meyer Aug 22 '18 at 19:20
-
This is one of your first posts and I'm going to create data for you, but you should really provide a sample of your data for allowing SE community to help you with your problem. – Fraccalo Aug 22 '18 at 19:28
1 Answers
3
Creating fake data for example
list1 = {Range[20],Join[Range[10] + RandomReal[1, 10],10 - Range[10] + RandomReal[1, 10]]}//Transpose;
list2 = {Range[20],Join[10 - Range[10] + RandomReal[1, 10], Range[10] + RandomReal[1, 10]]}//Transpose;
Interpolating them:
f1 = Interpolation[list1];
f2 = Interpolation[list2];
Finding intersections:
roots = {FindRoot[f1[x] - f2[x] == 0, {x, 5}],
FindRoot[f1[y] - f2[y] == 0, {y, 15}]} // Flatten
{x -> 5.12575, y -> 14.9835}
Showing the plot:
Show[
ListLinePlot[{list1, list2},
Filling -> {2 -> {{1}, {LightBlue, Transparent}}}]
,
ListPlot[{{x, f1[x]}, {y, f1[y]}} /. roots, PlotStyle -> Blue]
]
Integrating for finding the area:
NIntegrate[f1[z] - f2[z], {z, x, y} /. roots]
50.5077
Fraccalo
- 6,057
- 13
- 28
