2
$\begingroup$

I am trying to interpolate a table of the following form.

{{x1,y1,z1},{x2,y2,z2}...}

Where z depends on x and y, and x ranges from 0.01 to 1 in steps of 0.01, and y ranges from 0.01 to 15 in steps of 0.1 . It is a huge table so I cannot post the elements.

This is what the surface looks like.

enter image description here

I want to interpolate the table, however I am getting the following error regarding the mesh,

Interpolation::fememtlq: The quality 0.` of the underlying mesh is too low. 
The quality needs to be larger than 0.`.

I read that this error can be caused by collinear points, so I performed the following perturbation. I tried this at multiple values of epsilon, and also without adding a perturbation to z and the results are more or less the same.

  epsilon = 10^-5;
  perturbData = {#1 + RandomReal[epsilon {-1, 1}], #2 + 
  RandomReal[epsilon {-1, 1}], #3 + 
  RandomReal[epsilon {-1, 1}]} & @@@ intrct;
  reg = ConvexHullMesh[perturbData[[All, 1 ;; 2]]];
  f = Interpolation[perturbData, InterpolationOrder -> 1]

However when I plot this to check how it looks I get this surface which does not seem right at all.enter image description here

I am trying to find the roots of this function, but I cannot do this properly with this setup.

So I would like to know if there are any alternative ways to solve the interpolation error, or to refine the one I have.

$\endgroup$
6
  • $\begingroup$ Did you try Interpolation[...,InterpolationOrder->1]? $\endgroup$ Commented Jun 18, 2019 at 14:35
  • $\begingroup$ It's not possible to help you without the data. Either try to simplify the data and post it here (preferred) or upload the data to some sight where we can download it and work with it. $\endgroup$
    – user21
    Commented Jun 19, 2019 at 5:13
  • $\begingroup$ Yes I have tried setting the interpolation order to 1. Here is a link to dropbox containing the table dropbox.com/sh/p2ju7nqegyne5y3/AADV4vMg9IVNEQjoAcWoaZr3a?dl=0 $\endgroup$ Commented Jun 19, 2019 at 14:20
  • $\begingroup$ @Claire.Bear, unfortunately, the notebook under that link does not contain all the data. $\endgroup$
    – user21
    Commented Jun 19, 2019 at 15:03
  • $\begingroup$ I'm sorry, but the full notebook is rather large with a lot of different computations taking place. What other data in particular do you need? The table that I am trying to interpolate is all that is in the notebook. $\endgroup$ Commented Jun 19, 2019 at 20:09

1 Answer 1

2
$\begingroup$

One option is to use every 5th data point:

Needs["NDSolve`FEM`"]
mesh = ToElementMesh[wtable[[All, 1 ;; 2]][[1 ;; -1 ;; 5]]]


mesh["Wireframe"]

enter image description here

if = ElementMeshInterpolation[{mesh}, 
  wtable[[All, 3]][[1 ;; -1 ;; 5]]]

Plot3D[if[x, y], {x, y} \[Element] mesh]

enter image description here

Or a bit simpler:

if = Interpolation[wtable[[1 ;; -1 ;; 5]], "InterpolationOrder" -> 1];

A second option is to look for the bad data points and slightly perturb them:

mesh = ToElementMesh[wtable[[All, 1 ;; 2]]]
ToElementMesh::femimq: The element mesh has insufficient quality of 0.`. A quality estimate below 0. may be caused by a wrong ordering of element incidents or self-intersecting elements.

pos = Position[mesh["Quality"], _?(# <= 0. &)]
{{1, 10791}}

badInci = Extract[ElementIncidents[mesh["MeshElements"]], pos]
{{5611, 6823, 6232}}

badCoords = mesh["Coordinates"][[#]] & /@ badInci
{{{0.46`, 2.4000000000000004`}, {0.56`, 3.6`}, {0.51`, 3.`}}}

This is not a good polygon:

Area[Polygon[#]] & /@ badCoords
{Undefined}

We make a new mesh:

newCoords = mesh["Coordinates"];
epsilon = 10^-3;
(newCoords[[#]] += epsilon) & /@ badInci[[All, 2]];
mesh2 = ToElementMesh[newCoords]

And a new interpolating function:

if2 = ElementMeshInterpolation[mesh2, wtable[[All, 3]]]

Plot3D[if2[x, y], {x, y} \[Element] mesh2]

enter image description here

$\endgroup$
2
  • $\begingroup$ That worked great! Thanks very much for your help and time :) $\endgroup$ Commented Jun 26, 2019 at 15:26
  • $\begingroup$ @Claire.Bear, welcome. If you are satisfied with the answer you can accept it. $\endgroup$
    – user21
    Commented Jun 27, 2019 at 7:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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