0
$\begingroup$

Suppose some function. I need to plot it on the given range, but using the finite number of points. After that I need to approximate obtained discrete plot by the curve. Is it possible to do this?

$\endgroup$

closed as off-topic by Bob Hanlon, march, m_goldberg, Edmund, MarcoB Aug 11 '17 at 4:33

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – march, m_goldberg, Edmund, MarcoB
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ I think we need more detail here. An example data set, an example function, and a description of the desired output. However, you can specify a PlotRange when plotting, and you can either interpolate your data using Interpolation or fit your data to a function using FindFit or NonlinearModelFit. $\endgroup$ – march Aug 10 '17 at 17:56
  • $\begingroup$ @march : thank you for paying the attention. My input function is NIntegrate[f[x,m],{x,a,b}] with f[x,m] being very-very complicated function, and m being the parameter. The integration is very-very slow, however successful for given m. But when I try to plot this quantity as the function of m, this takes so long time that I don't want to wait. Therefore, I want to restrict the number of plot points, then to obtain discrete plot, and then replace the discrete points by continuous curve. $\endgroup$ – John Taylor Aug 10 '17 at 18:06
  • $\begingroup$ @march : I've found MaxPlotPoints in documentation (reference.wolfram.com/language/ref/MaxPlotPoints.html), and (IT SEEMS THAT) this is almost what I want. But I don't know how to eliminate points from the plot and to have only continuous interpolated curve. $\endgroup$ – John Taylor Aug 10 '17 at 18:07
  • 1
    $\begingroup$ Well, you can just do ListLinePlot, which will join your points by lines? Just make a Table of values for your function (say, lst = Table[{m, NIntegrate[f[x,m],{x,a,b}]}, {m, 1, 5, 0.1}] or something), and then ListLinePlot[lst]. $\endgroup$ – march Aug 10 '17 at 18:10
  • $\begingroup$ @march : what I want is to plot only this line, without the points by using which the line was generated. $\endgroup$ – John Taylor Aug 10 '17 at 18:12
1
$\begingroup$

This is the workflow that you seek.

I will use a simple f[x,m] but it should work for the complex one of your actual problem.

Step 1 - Define f[x,m]

f[x_, m_] := m Cos[x]

Plot[f[x, 2], {x, -π/2, π/2}]

Mathematica graphics

Step 2 - Define the intF

intF is the function that integrates f[x,m] over the limits a to b.

intF[m_, a_, b_] := NIntegrate[f[x, m], {x, a, b}]

A test result is:

intF[2, -π/2, π/2]

(* 4. *)

Step 3 - Make a table of intF results

Create a table of the input, m and the result, intF[m, a, b]. The table variable is m and the integration limits, a and b are assumed to be known. Set the step to the increment of the points that you desire (one can use a list as the input increment to Table to precisely control the desired points).

In the example below the step was set to 0.1

intFlist = Table[{m, intF[m, -π/2, π/2]}, {m, 0.1, 2, 0.1}]

(* {{0.1, 0.2}, {0.2, 0.4}, {0.3, 0.6}, {0.4, 0.8}, {0.5, 1.},
    {0.6, 1.2}, {0.7, 1.4}, {0.8, 1.6}, {0.9, 1.8}, {1.0, 2.},
    {1.1, 2.2}, {1.2, 2.4}, {1.3, 2.6}, {1.4, 2.8}, {1.5, 3.},
    {1.6, 3.2}, {1.7, 3.4}, {1.8, 3.6}, {1.9, 3.8}, {2.0, 4.}} *)

Step 4 - ListLinePlot

Plot the table using ListLinePlot. This should produce a smooth curve assuming that you have sufficient density in your input points.

ListLinePlot[intFlist]

Mathematica graphics

$\endgroup$

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