# Mesh quality error with interpolation of table

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.

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.

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.

• Did you try Interpolation[...,InterpolationOrder->1]? Jun 18 '19 at 14:35
• 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. Jun 19 '19 at 5:13
• 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 Jun 19 '19 at 14:20
• @Claire.Bear, unfortunately, the notebook under that link does not contain all the data. Jun 19 '19 at 15:03
• 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. Jun 19 '19 at 20:09

One option is to use every 5th data point:

Needs["NDSolveFEM"]
mesh = ToElementMesh[wtable[[All, 1 ;; 2]][[1 ;; -1 ;; 5]]]

mesh["Wireframe"]


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

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


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}}

{{5611, 6823, 6232}}

{{{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]
`

• That worked great! Thanks very much for your help and time :) Jun 26 '19 at 15:26
• @Claire.Bear, welcome. If you are satisfied with the answer you can accept it. Jun 27 '19 at 7:41