0
$\begingroup$

I have two lists which I generated from two plots.

list1 = Cases[
Cases[InputForm[plot1], Line[___], 
Infinity], {_?NumericQ, _?NumericQ}, Infinity];

list2 = Cases[
Cases[InputForm[plot2], Line[___], 
Infinity], {_?NumericQ, _?NumericQ}, Infinity];

Now I want to divide the list1 by list2 and then plot this resulting list3 vs. x. Can anyone please help me with this?

$\endgroup$
4
  • $\begingroup$ Please format the post an place all code in a code block. Make sure that the code can be copied back into Mathematica intact. Click edit above, then if you need help click the ? button in the editing toolbar. $\endgroup$ – Szabolcs Sep 5 '16 at 8:39
  • $\begingroup$ If the lists are of equal length, then the division operator / works as expected. $\endgroup$ – Feyre Sep 5 '16 at 8:43
  • $\begingroup$ Just a comment: list division only makes sense if both lists are on the same x-grid. $\endgroup$ – Markus Roellig Sep 5 '16 at 10:57
  • $\begingroup$ Yes, they are on the same grid. $\endgroup$ – cosmos Sep 5 '16 at 11:48
5
$\begingroup$

The problem here is that list1 and list2 will not be on the same gridding (i.e. at the same x positions}. So the general approach is to convert the lists into interpolation functions and divide the two.

plot1 = Plot[Sin[x], {x, 0, 10}];
plot2 = Plot[x, {x, 0, 10}];
list1 = Cases[
   Cases[InputForm[plot1], Line[_], 
   Infinity], {_?NumericQ, _?NumericQ}, Infinity]; 
list2 = Cases[ 
   Cases[InputForm[plot2], Line[_], 
   Infinity], {_?NumericQ, _?NumericQ}, Infinity];

Unequal lengths:

Length[list1] == Length[list2]
<* Out[] = False *>

inter1 = Interpolation[list1];
inter2 = Interpolation[list2];
Plot[inter1[x]/inter2[x], {x, 0, 10}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks a lot Markus! Interpolation solved my problem! The problem was that the lists were not of same size and that's why simple divide function "/" was not working. $\endgroup$ – cosmos Sep 5 '16 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.