3
$\begingroup$

I am using this code:

L = {1.5, 2.0, 2.5, 3.0, 3.5};
R = {0.0001, 0.001, 0.01, 0.1, 1, 10};
Y[a_, b_] = Exp[-b/a]/a;
ris = Table[{L[[i]], R[[j]], 
   NIntegrate[Y[Abs[x - 7.6], L[[i]]], {x, 0, R[[j]]}]}, {i, 
   Length[L]}, {j, Length[R]}] 

to build a 3D table: the result of the numerical integration as a function of two parameters (L;R).

Now I need to plot this with a scatter plot: the integral as a function of R, for different values of L, so, on the same plot, I need a different curve, one for each value of L.

Doing:

A = ris[[1, All]]
B = A[[All, 3]]

I have the integral for L=1.5, with A = ris[[2, All]], in B I have the integral for L=2, and so on: in this way I built 5 different list, and plotted them on the same graphic.

How can I make this last part "automatic" and smarter? I tried a Do loop, but I cannot make the different curves on the same plot.

$\endgroup$
  • 4
    $\begingroup$ You can do : res = Table[{l, r, NIntegrate[Y[Abs[x - 7.6], l], {x, 0, r}]}, {l, L}, {r, R}] and then ListLinePlot[#[[All, 2 ;;]] & /@ res , PlotRange -> All] or similar. $\endgroup$ – b.gates.you.know.what May 15 '14 at 8:53
2
$\begingroup$

I am here only by integrating the question with the answer by b.gatessucks.

L = {1.5, 2.0, 2.5, 3.0, 3.5};
R = {0.0001, 0.001, 0.01, 0.1, 1, 10};
Y[a_, b_] = Exp[-b/a]/a;
ris = Table[{L[[i]], R[[j]], 
    NIntegrate[Y[Abs[x - 7.6], L[[i]]], {x, 0, R[[j]]}]}, {i, 
    Length[L]}, {j, Length[R]}];
res = Table[{l, r, NIntegrate[Y[Abs[x - 7.6], l], {x, 0, r}]}, {l, 
   L}, {r, R}]
ListLinePlot[#[[All, 2 ;;]] & /@ res, PlotRange -> All]

enter image description here

$\endgroup$

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.