1
$\begingroup$

like the title says: is that possible? In my case, I have a plot of an integral that is evaluated numerically. Maybe using Interpolate with the points used by mathematica to draw the graph or something?

$\endgroup$
3
$\begingroup$

Starting with the plots

plts = Plot[{Sin[x], Sin[2 x], Sin[3 x]}, {x, 0, 2 Pi}, 
  PlotLegends -> "Expressions"]

enter image description here

Extracting the sets of points from the plot

pts = Cases[plts, Line[pts_] :> pts, Infinity];

Interpolating each set of points

funcs = Interpolation /@ pts;

Plotting the interpolations for comparison

Plot[Evaluate[#[x] & /@ funcs], {x, 0, 2 Pi}, 
 PlotLegends -> Automatic]

enter image description here

EDIT: Addressing the additional questions in the comments.

To evaluate one of the three functions at x == 1 use Part ( [[...]] ). For example, to evaluate the second interpolated function

funcs[[2]][1]

(* 0.909298 *)

To integrate the product of each function with Sin[x] over the interval {0, 1}

NIntegrate[#[x]*Sin[x], {x, 0, 1}] & /@ funcs

(* {0.272675, 0.397216, 0.321925} *)

Or for a single function

NIntegrate[funcs[[2]][x]*Sin[x], {x, 0, 1}]

(* 0.397216 *)
$\endgroup$
  • $\begingroup$ Thanks! One question: how could I integrate the interpolated function? Say I wanted to integrate func Sin[x] between x=0 and x=1, would the following code be correct? (func is like your funcs) NIntegrate[Sin[x] Evaluate[#[x] & /@ func], {x,0,1}] $\endgroup$ – Fisher Jun 26 '18 at 20:07

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.