0
$\begingroup$

I have implemented cubic spline on my own and it is working properly (table SplineProbe consists piecewise of cubic functions). Right now I would like to display in on a grid of 100 points.

What I did is creating the following (xList contains the x-values of the grid):

ConditionalTable = 
  Table[With[{i = i}, 
    ConditionalExpression[SplineProbe[[i]][#], 
      xList[[i]] <= # <= xList[[i + 1]]] &], {i, 1, 99}];

Trial = Table[
   Plot[ConditionalTable[[i]][x], {x, First[xList], Last[xList]}, 
    PlotStyle -> {Red, Thick}], {i, 1, 99}];

   Apply[Show, {Trial, ListPlot[Points], PlotStyle -> Gray, 
  PlotRange -> All}]

The result I obtain looks like that:

enter image description here

When I am trying to display the ommited parts separately, it works only if the bounds are the ones the particular spline has been defined for:

TrialPart = Plot[ConditionalTable[[2]][x], {x, 0.002, 0.003}, 
  PlotStyle -> Dashed]

enter image description here

Here combination of those two (small dashed part between 2nd and 3rd point):

enter image description here

The funny thing is, if I apply the whole thing on a narrower domain, it works properly:

enter image description here

I am so confused, I don't even know where to look for my mistake. Each hint would come in handy for me.

Edit:

It is as if the ConditionalExpression function couldn't manage long intervals. The first five elements of the xList are {0.001,0.002,0.003,0.004,0.005}. If I try to obtain:

trial1 = Plot[ConditionalTable[[1]][x], {x, 0.001, 0.005}]
trial2 = Plot[ConditionalTable[[2]][x], {x, 0.001, 0.005}]
trial3 = Plot[ConditionalTable[[3]][x], {x, 0.001, 0.005}]
trial4 = Plot[ConditionalTable[[4]][x], {x, 0.001, 0.005}]

Apply[Show, {trial1, trial2, trial3, trial4, PlotRange -> All}]

it works:

enter image description here

As soon as I widen my domain, it stops working properly:

trial1 = Plot[ConditionalTable[[1]][x], {x, 0.001, Last[xList]}]
trial2 = Plot[ConditionalTable[[2]][x], {x, 0.001, Last[xList]}]
trial3 = Plot[ConditionalTable[[3]][x], {x, 0.001, Last[xList]}]
trial4 = Plot[ConditionalTable[[4]][x], {x, 0.001, Last[xList]}]

Apply[Show, {trial1, trial2, trial3, trial4, PlotRange -> All}]

enter image description here

$\endgroup$
  • $\begingroup$ What happens if you use the following options in Plot: PlotPoints -> 4n where n is the number of SplineProbes you have and additionally MaxRecursion->5? $\endgroup$ – halirutan Feb 5 '18 at 12:09
  • $\begingroup$ It works! Thank your very much :) But why doesn't it work without those options? It seems like a casual iteration. $\endgroup$ – aniager Feb 6 '18 at 7:31

Your Answer

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

Browse other questions tagged or ask your own question.