Skip to main content
edited tags
Link
azerbajdzan
  • 25.1k
  • 2
  • 22
  • 62
deleted 9255 characters in body
Source Link

UPDATE

With the help of ChatGPT, I was able to come up with a solution to correct the problematic regions of my function. The figure on the left is the "before" plot and the plot on the right is the "after" plot.

enter image description here

It is not perfect in the sense that I had to quiet some error messages (if someone can figure out how to fix them that would be great.) Below is the improved code that comes with annotations.

ClearAll[normEvec3, interpolatedRegion];

(*Define normEvec3*)
normEvec3[x1_, 
   y1_] := -Re[(23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
       1684 Cos[5 x1] + 412 Cos[6 x1] - 
       304 Sqrt[2] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       55 Sqrt[2] Cos[3 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       16 Sqrt[2] Cos[4 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       3 Sqrt[2] Cos[5 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       4 Cos[2 x1] (-6041 + 
          48 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) + 
       2 Cos[x1] (-15698 + 
          99 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) - 
       76 Cos[7 x1] + 
       7 Cos[8 x1])/(\[Sqrt](1 + 
          Abs[((23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
                1684 Cos[5 x1] + 412 Cos[6 x1] - 
                304 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                55 Sqrt[2] Cos[3 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                16 Sqrt[2] Cos[4 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                3 Sqrt[2] Cos[5 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                4 Cos[2 x1] (-6041 + 
                   48 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                2 Cos[x1] (-15698 + 
                   99 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) - 76 Cos[7 x1] + 
                7 Cos[8 x1]) (Cos[2 y1] + I Sin[2 y1]))/((-40 + 
                14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (-180 + 148 Cos[x1] + 42 Cos[3 x1] - 
                12 Cos[4 x1] + 2 Cos[5 x1] + 
                3 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                Cos[2 x1] (-128 + 
                   Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          1/16 Abs[((2158 - 864 Cos[3 x1] + 274 Cos[4 x1] - 
                 64 Cos[5 x1] + 7 Cos[6 x1] - 
                 28 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 3 Sqrt[2] Cos[3 x1] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (1913 - 
                    12 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                 7 Cos[x1] (-416 + 
                    3 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])) Tan[x1/
                2]^2)/((-2 + Cos[x1]) (-180 + 148 Cos[x1] + 
                 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
                 3 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (-128 + 
                    Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          Abs[((-56 + 42 Cos[x1] - 24 Cos[2 x1] + 6 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (Cos[2 y1] + I Sin[2 y1]) Tan[x1/
               2]^2)/(-40 + 14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
              Sqrt[2] Sqrt[
               2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
                278 Cos[4 x1] - 56 Cos[5 x1] + 
                5 Cos[6 x1]])]^2) (-40 + 14 Cos[x1] - 8 Cos[2 x1] + 
         2 Cos[3 x1] + 
         Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) (-180 + 
         148 Cos[x1] + 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
         3 Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
         Cos[2 x1] (-128 + 
            Sqrt[2] Sqrt[
             2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
              278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]])) (Cos[y1] -
          I Sin[y1])^2)];

threshold = 10^-4;
normEvec3deg[x1_, y1_] := 
  Quiet[Chop[normEvec3[x1 Degree, y1 Degree], 
    threshold], {Power::infy, Infinity::indet}];

(*Define the boundary condition explicitly*)
normEvec3deg[0, y1_] := 0;

(*Define the range of interest*)
x1Min = 0;
x1Max = 180;
y1Min = 0;
y1Max = 360;
yStep = 5;

(*Set up a table to store the results*)
resultsTable = {};

(*Function to automatically select well-behaved points for \
interpolation*)
SelectWellBehavedPoints[x1_] := 
  Module[{x1Val1, x1Val2, x1Val3, x1Val4},
   (*Select points dynamically based on current x1 value*)
   If[x1 < 50,
    (*If x1 is below 50,use points between 50 and 180*)x1Val1 = 50;
    x1Val2 = 60;
    x1Val3 = 70;
    x1Val4 = 100,
    (*If x1 is near the indeterminate region,avoid[87,93]*)
    If[87 <= x1 <= 93, x1Val1 = 70;
     x1Val2 = 85;(*Below the problematic region*)
     x1Val3 = 94;(*Just above the problematic region*)
     x1Val4 = 120,(*Further well-behaved point*)
     (*Else,use default values when x1 is well-behaved*)
     x1Val1 = Max[50, x1 - 20];
     (*Dynamically choose values relative to x1*)
     x1Val2 = Max[50, x1 - 10];
     x1Val3 = Min[180, x1 + 10];
     x1Val4 = Min[180, x1 + 20]]];
   Return[{x1Val1, x1Val2, x1Val3, x1Val4}]];

For[y1 = y1Min, y1 <= y1Max, y1 += yStep,
  For[x1 = x1Min, x1 <= x1Max, 
    x1 += 1,(*Check if x1 is in the indeterminate or non-
    smooth region*)
    If[(x1 < 50) || (87 <= x1 <= 93),(*Automatically select well-
      behaved points for interpolation*)
      {x1Val1, x1Val2, x1Val3, x1Val4} = SelectWellBehavedPoints[x1];
      (*Perform interpolation using well-behaved points*)
      interpolatedValue = 
       Interpolation[{{0, normEvec3deg[0, y1]}, {x1Val1, 
           normEvec3deg[x1Val1, y1]}, {x1Val2, 
           normEvec3deg[x1Val2, y1]}, {x1Val3, 
           normEvec3deg[x1Val3, y1]}, {x1Val4, 
           normEvec3deg[x1Val4, y1]}}, InterpolationOrder -> 3][x1];
      (*Append the valid {x1,y1,interpolatedValue} to resultsTable*)
      AppendTo[resultsTable, {x1, y1, N[interpolatedValue]}],
      (*Otherwise,directly evaluate normEvec3deg in the well-
      behaved region*)
      AppendTo[resultsTable, {x1, y1, normEvec3deg[x1, y1]}]];
    ];
  ];

(*Plotting the results using ListPlot3D*)
ListPlot3D[resultsTable, AxesLabel -> {"x1", "y1", "Value"}, 
 PlotRange -> {-1, 1}, ColorFunction -> Hue, InterpolationOrder -> 3]

UPDATE

With the help of ChatGPT, I was able to come up with a solution to correct the problematic regions of my function. The figure on the left is the "before" plot and the plot on the right is the "after" plot.

enter image description here

It is not perfect in the sense that I had to quiet some error messages (if someone can figure out how to fix them that would be great.) Below is the improved code that comes with annotations.

ClearAll[normEvec3, interpolatedRegion];

(*Define normEvec3*)
normEvec3[x1_, 
   y1_] := -Re[(23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
       1684 Cos[5 x1] + 412 Cos[6 x1] - 
       304 Sqrt[2] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       55 Sqrt[2] Cos[3 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       16 Sqrt[2] Cos[4 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       3 Sqrt[2] Cos[5 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       4 Cos[2 x1] (-6041 + 
          48 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) + 
       2 Cos[x1] (-15698 + 
          99 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) - 
       76 Cos[7 x1] + 
       7 Cos[8 x1])/(\[Sqrt](1 + 
          Abs[((23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
                1684 Cos[5 x1] + 412 Cos[6 x1] - 
                304 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                55 Sqrt[2] Cos[3 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                16 Sqrt[2] Cos[4 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                3 Sqrt[2] Cos[5 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                4 Cos[2 x1] (-6041 + 
                   48 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                2 Cos[x1] (-15698 + 
                   99 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) - 76 Cos[7 x1] + 
                7 Cos[8 x1]) (Cos[2 y1] + I Sin[2 y1]))/((-40 + 
                14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (-180 + 148 Cos[x1] + 42 Cos[3 x1] - 
                12 Cos[4 x1] + 2 Cos[5 x1] + 
                3 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                Cos[2 x1] (-128 + 
                   Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          1/16 Abs[((2158 - 864 Cos[3 x1] + 274 Cos[4 x1] - 
                 64 Cos[5 x1] + 7 Cos[6 x1] - 
                 28 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 3 Sqrt[2] Cos[3 x1] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (1913 - 
                    12 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                 7 Cos[x1] (-416 + 
                    3 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])) Tan[x1/
                2]^2)/((-2 + Cos[x1]) (-180 + 148 Cos[x1] + 
                 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
                 3 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (-128 + 
                    Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          Abs[((-56 + 42 Cos[x1] - 24 Cos[2 x1] + 6 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (Cos[2 y1] + I Sin[2 y1]) Tan[x1/
               2]^2)/(-40 + 14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
              Sqrt[2] Sqrt[
               2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
                278 Cos[4 x1] - 56 Cos[5 x1] + 
                5 Cos[6 x1]])]^2) (-40 + 14 Cos[x1] - 8 Cos[2 x1] + 
         2 Cos[3 x1] + 
         Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) (-180 + 
         148 Cos[x1] + 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
         3 Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
         Cos[2 x1] (-128 + 
            Sqrt[2] Sqrt[
             2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
              278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]])) (Cos[y1] -
          I Sin[y1])^2)];

threshold = 10^-4;
normEvec3deg[x1_, y1_] := 
  Quiet[Chop[normEvec3[x1 Degree, y1 Degree], 
    threshold], {Power::infy, Infinity::indet}];

(*Define the boundary condition explicitly*)
normEvec3deg[0, y1_] := 0;

(*Define the range of interest*)
x1Min = 0;
x1Max = 180;
y1Min = 0;
y1Max = 360;
yStep = 5;

(*Set up a table to store the results*)
resultsTable = {};

(*Function to automatically select well-behaved points for \
interpolation*)
SelectWellBehavedPoints[x1_] := 
  Module[{x1Val1, x1Val2, x1Val3, x1Val4},
   (*Select points dynamically based on current x1 value*)
   If[x1 < 50,
    (*If x1 is below 50,use points between 50 and 180*)x1Val1 = 50;
    x1Val2 = 60;
    x1Val3 = 70;
    x1Val4 = 100,
    (*If x1 is near the indeterminate region,avoid[87,93]*)
    If[87 <= x1 <= 93, x1Val1 = 70;
     x1Val2 = 85;(*Below the problematic region*)
     x1Val3 = 94;(*Just above the problematic region*)
     x1Val4 = 120,(*Further well-behaved point*)
     (*Else,use default values when x1 is well-behaved*)
     x1Val1 = Max[50, x1 - 20];
     (*Dynamically choose values relative to x1*)
     x1Val2 = Max[50, x1 - 10];
     x1Val3 = Min[180, x1 + 10];
     x1Val4 = Min[180, x1 + 20]]];
   Return[{x1Val1, x1Val2, x1Val3, x1Val4}]];

For[y1 = y1Min, y1 <= y1Max, y1 += yStep,
  For[x1 = x1Min, x1 <= x1Max, 
    x1 += 1,(*Check if x1 is in the indeterminate or non-
    smooth region*)
    If[(x1 < 50) || (87 <= x1 <= 93),(*Automatically select well-
      behaved points for interpolation*)
      {x1Val1, x1Val2, x1Val3, x1Val4} = SelectWellBehavedPoints[x1];
      (*Perform interpolation using well-behaved points*)
      interpolatedValue = 
       Interpolation[{{0, normEvec3deg[0, y1]}, {x1Val1, 
           normEvec3deg[x1Val1, y1]}, {x1Val2, 
           normEvec3deg[x1Val2, y1]}, {x1Val3, 
           normEvec3deg[x1Val3, y1]}, {x1Val4, 
           normEvec3deg[x1Val4, y1]}}, InterpolationOrder -> 3][x1];
      (*Append the valid {x1,y1,interpolatedValue} to resultsTable*)
      AppendTo[resultsTable, {x1, y1, N[interpolatedValue]}],
      (*Otherwise,directly evaluate normEvec3deg in the well-
      behaved region*)
      AppendTo[resultsTable, {x1, y1, normEvec3deg[x1, y1]}]];
    ];
  ];

(*Plotting the results using ListPlot3D*)
ListPlot3D[resultsTable, AxesLabel -> {"x1", "y1", "Value"}, 
 PlotRange -> {-1, 1}, ColorFunction -> Hue, InterpolationOrder -> 3]

added 9256 characters in body
Source Link

UPDATE

With the help of ChatGPT, I was able to come up with a solution to correct the problematic regions of my function. The figure on the left is the "before" plot and the plot on the right is the "after" plot.

enter image description here

It is not perfect in the sense that I had to quiet some error messages (if someone can figure out how to fix them that would be great.) Below is the improved code that comes with annotations.

ClearAll[normEvec3, interpolatedRegion];

(*Define normEvec3*)
normEvec3[x1_, 
   y1_] := -Re[(23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
       1684 Cos[5 x1] + 412 Cos[6 x1] - 
       304 Sqrt[2] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       55 Sqrt[2] Cos[3 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       16 Sqrt[2] Cos[4 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       3 Sqrt[2] Cos[5 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       4 Cos[2 x1] (-6041 + 
          48 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) + 
       2 Cos[x1] (-15698 + 
          99 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) - 
       76 Cos[7 x1] + 
       7 Cos[8 x1])/(\[Sqrt](1 + 
          Abs[((23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
                1684 Cos[5 x1] + 412 Cos[6 x1] - 
                304 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                55 Sqrt[2] Cos[3 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                16 Sqrt[2] Cos[4 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                3 Sqrt[2] Cos[5 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                4 Cos[2 x1] (-6041 + 
                   48 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                2 Cos[x1] (-15698 + 
                   99 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) - 76 Cos[7 x1] + 
                7 Cos[8 x1]) (Cos[2 y1] + I Sin[2 y1]))/((-40 + 
                14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (-180 + 148 Cos[x1] + 42 Cos[3 x1] - 
                12 Cos[4 x1] + 2 Cos[5 x1] + 
                3 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                Cos[2 x1] (-128 + 
                   Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          1/16 Abs[((2158 - 864 Cos[3 x1] + 274 Cos[4 x1] - 
                 64 Cos[5 x1] + 7 Cos[6 x1] - 
                 28 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 3 Sqrt[2] Cos[3 x1] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (1913 - 
                    12 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                 7 Cos[x1] (-416 + 
                    3 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])) Tan[x1/
                2]^2)/((-2 + Cos[x1]) (-180 + 148 Cos[x1] + 
                 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
                 3 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (-128 + 
                    Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          Abs[((-56 + 42 Cos[x1] - 24 Cos[2 x1] + 6 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (Cos[2 y1] + I Sin[2 y1]) Tan[x1/
               2]^2)/(-40 + 14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
              Sqrt[2] Sqrt[
               2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
                278 Cos[4 x1] - 56 Cos[5 x1] + 
                5 Cos[6 x1]])]^2) (-40 + 14 Cos[x1] - 8 Cos[2 x1] + 
         2 Cos[3 x1] + 
         Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) (-180 + 
         148 Cos[x1] + 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
         3 Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
         Cos[2 x1] (-128 + 
            Sqrt[2] Sqrt[
             2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
              278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]])) (Cos[y1] -
          I Sin[y1])^2)];

threshold = 10^-4;
normEvec3deg[x1_, y1_] := 
  Quiet[Chop[normEvec3[x1 Degree, y1 Degree], 
    threshold], {Power::infy, Infinity::indet}];

(*Define the boundary condition explicitly*)
normEvec3deg[0, y1_] := 0;

(*Define the range of interest*)
x1Min = 0;
x1Max = 180;
y1Min = 0;
y1Max = 360;
yStep = 5;

(*Set up a table to store the results*)
resultsTable = {};

(*Function to automatically select well-behaved points for \
interpolation*)
SelectWellBehavedPoints[x1_] := 
  Module[{x1Val1, x1Val2, x1Val3, x1Val4},
   (*Select points dynamically based on current x1 value*)
   If[x1 < 50,
    (*If x1 is below 50,use points between 50 and 180*)x1Val1 = 50;
    x1Val2 = 60;
    x1Val3 = 70;
    x1Val4 = 100,
    (*If x1 is near the indeterminate region,avoid[87,93]*)
    If[87 <= x1 <= 93, x1Val1 = 70;
     x1Val2 = 85;(*Below the problematic region*)
     x1Val3 = 94;(*Just above the problematic region*)
     x1Val4 = 120,(*Further well-behaved point*)
     (*Else,use default values when x1 is well-behaved*)
     x1Val1 = Max[50, x1 - 20];
     (*Dynamically choose values relative to x1*)
     x1Val2 = Max[50, x1 - 10];
     x1Val3 = Min[180, x1 + 10];
     x1Val4 = Min[180, x1 + 20]]];
   Return[{x1Val1, x1Val2, x1Val3, x1Val4}]];

For[y1 = y1Min, y1 <= y1Max, y1 += yStep,
  For[x1 = x1Min, x1 <= x1Max, 
    x1 += 1,(*Check if x1 is in the indeterminate or non-
    smooth region*)
    If[(x1 < 50) || (87 <= x1 <= 93),(*Automatically select well-
      behaved points for interpolation*)
      {x1Val1, x1Val2, x1Val3, x1Val4} = SelectWellBehavedPoints[x1];
      (*Perform interpolation using well-behaved points*)
      interpolatedValue = 
       Interpolation[{{0, normEvec3deg[0, y1]}, {x1Val1, 
           normEvec3deg[x1Val1, y1]}, {x1Val2, 
           normEvec3deg[x1Val2, y1]}, {x1Val3, 
           normEvec3deg[x1Val3, y1]}, {x1Val4, 
           normEvec3deg[x1Val4, y1]}}, InterpolationOrder -> 3][x1];
      (*Append the valid {x1,y1,interpolatedValue} to resultsTable*)
      AppendTo[resultsTable, {x1, y1, N[interpolatedValue]}],
      (*Otherwise,directly evaluate normEvec3deg in the well-
      behaved region*)
      AppendTo[resultsTable, {x1, y1, normEvec3deg[x1, y1]}]];
    ];
  ];

(*Plotting the results using ListPlot3D*)
ListPlot3D[resultsTable, AxesLabel -> {"x1", "y1", "Value"}, 
 PlotRange -> {-1, 1}, ColorFunction -> Hue, InterpolationOrder -> 3]

UPDATE

With the help of ChatGPT, I was able to come up with a solution to correct the problematic regions of my function. The figure on the left is the "before" plot and the plot on the right is the "after" plot.

enter image description here

It is not perfect in the sense that I had to quiet some error messages (if someone can figure out how to fix them that would be great.) Below is the improved code that comes with annotations.

ClearAll[normEvec3, interpolatedRegion];

(*Define normEvec3*)
normEvec3[x1_, 
   y1_] := -Re[(23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
       1684 Cos[5 x1] + 412 Cos[6 x1] - 
       304 Sqrt[2] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       55 Sqrt[2] Cos[3 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       16 Sqrt[2] Cos[4 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
       3 Sqrt[2] Cos[5 x1] Sqrt[
        2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
         278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] - 
       4 Cos[2 x1] (-6041 + 
          48 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) + 
       2 Cos[x1] (-15698 + 
          99 Sqrt[2] Sqrt[
           2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
            278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) - 
       76 Cos[7 x1] + 
       7 Cos[8 x1])/(\[Sqrt](1 + 
          Abs[((23629 - 11900 Cos[3 x1] + 5036 Cos[4 x1] - 
                1684 Cos[5 x1] + 412 Cos[6 x1] - 
                304 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                55 Sqrt[2] Cos[3 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                16 Sqrt[2] Cos[4 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                3 Sqrt[2] Cos[5 x1] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] - 
                4 Cos[2 x1] (-6041 + 
                   48 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                2 Cos[x1] (-15698 + 
                   99 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) - 76 Cos[7 x1] + 
                7 Cos[8 x1]) (Cos[2 y1] + I Sin[2 y1]))/((-40 + 
                14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (-180 + 148 Cos[x1] + 42 Cos[3 x1] - 
                12 Cos[4 x1] + 2 Cos[5 x1] + 
                3 Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]] + 
                Cos[2 x1] (-128 + 
                   Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          1/16 Abs[((2158 - 864 Cos[3 x1] + 274 Cos[4 x1] - 
                 64 Cos[5 x1] + 7 Cos[6 x1] - 
                 28 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 3 Sqrt[2] Cos[3 x1] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (1913 - 
                    12 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]]) + 
                 7 Cos[x1] (-416 + 
                    3 Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])) Tan[x1/
                2]^2)/((-2 + Cos[x1]) (-180 + 148 Cos[x1] + 
                 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
                 3 Sqrt[2] Sqrt[
                  2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                   888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                   5 Cos[6 x1]] + 
                 Cos[2 x1] (-128 + 
                    Sqrt[2] Sqrt[
                    2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                    888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                    5 Cos[6 x1]])))]^2 + 
          Abs[((-56 + 42 Cos[x1] - 24 Cos[2 x1] + 6 Cos[3 x1] + 
                Sqrt[2] Sqrt[
                 2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 
                  888 Cos[3 x1] + 278 Cos[4 x1] - 56 Cos[5 x1] + 
                  5 Cos[6 x1]]) (Cos[2 y1] + I Sin[2 y1]) Tan[x1/
               2]^2)/(-40 + 14 Cos[x1] - 8 Cos[2 x1] + 2 Cos[3 x1] + 
              Sqrt[2] Sqrt[
               2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
                278 Cos[4 x1] - 56 Cos[5 x1] + 
                5 Cos[6 x1]])]^2) (-40 + 14 Cos[x1] - 8 Cos[2 x1] + 
         2 Cos[3 x1] + 
         Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]]) (-180 + 
         148 Cos[x1] + 42 Cos[3 x1] - 12 Cos[4 x1] + 2 Cos[5 x1] + 
         3 Sqrt[2] Sqrt[
          2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
           278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]] + 
         Cos[2 x1] (-128 + 
            Sqrt[2] Sqrt[
             2154 - 2896 Cos[x1] + 1915 Cos[2 x1] - 888 Cos[3 x1] + 
              278 Cos[4 x1] - 56 Cos[5 x1] + 5 Cos[6 x1]])) (Cos[y1] -
          I Sin[y1])^2)];

threshold = 10^-4;
normEvec3deg[x1_, y1_] := 
  Quiet[Chop[normEvec3[x1 Degree, y1 Degree], 
    threshold], {Power::infy, Infinity::indet}];

(*Define the boundary condition explicitly*)
normEvec3deg[0, y1_] := 0;

(*Define the range of interest*)
x1Min = 0;
x1Max = 180;
y1Min = 0;
y1Max = 360;
yStep = 5;

(*Set up a table to store the results*)
resultsTable = {};

(*Function to automatically select well-behaved points for \
interpolation*)
SelectWellBehavedPoints[x1_] := 
  Module[{x1Val1, x1Val2, x1Val3, x1Val4},
   (*Select points dynamically based on current x1 value*)
   If[x1 < 50,
    (*If x1 is below 50,use points between 50 and 180*)x1Val1 = 50;
    x1Val2 = 60;
    x1Val3 = 70;
    x1Val4 = 100,
    (*If x1 is near the indeterminate region,avoid[87,93]*)
    If[87 <= x1 <= 93, x1Val1 = 70;
     x1Val2 = 85;(*Below the problematic region*)
     x1Val3 = 94;(*Just above the problematic region*)
     x1Val4 = 120,(*Further well-behaved point*)
     (*Else,use default values when x1 is well-behaved*)
     x1Val1 = Max[50, x1 - 20];
     (*Dynamically choose values relative to x1*)
     x1Val2 = Max[50, x1 - 10];
     x1Val3 = Min[180, x1 + 10];
     x1Val4 = Min[180, x1 + 20]]];
   Return[{x1Val1, x1Val2, x1Val3, x1Val4}]];

For[y1 = y1Min, y1 <= y1Max, y1 += yStep,
  For[x1 = x1Min, x1 <= x1Max, 
    x1 += 1,(*Check if x1 is in the indeterminate or non-
    smooth region*)
    If[(x1 < 50) || (87 <= x1 <= 93),(*Automatically select well-
      behaved points for interpolation*)
      {x1Val1, x1Val2, x1Val3, x1Val4} = SelectWellBehavedPoints[x1];
      (*Perform interpolation using well-behaved points*)
      interpolatedValue = 
       Interpolation[{{0, normEvec3deg[0, y1]}, {x1Val1, 
           normEvec3deg[x1Val1, y1]}, {x1Val2, 
           normEvec3deg[x1Val2, y1]}, {x1Val3, 
           normEvec3deg[x1Val3, y1]}, {x1Val4, 
           normEvec3deg[x1Val4, y1]}}, InterpolationOrder -> 3][x1];
      (*Append the valid {x1,y1,interpolatedValue} to resultsTable*)
      AppendTo[resultsTable, {x1, y1, N[interpolatedValue]}],
      (*Otherwise,directly evaluate normEvec3deg in the well-
      behaved region*)
      AppendTo[resultsTable, {x1, y1, normEvec3deg[x1, y1]}]];
    ];
  ];

(*Plotting the results using ListPlot3D*)
ListPlot3D[resultsTable, AxesLabel -> {"x1", "y1", "Value"}, 
 PlotRange -> {-1, 1}, ColorFunction -> Hue, InterpolationOrder -> 3]

added 17 characters in body
Source Link
Loading
deleted 29 characters in body
Source Link
Loading
deleted 29 characters in body
Source Link
Loading
Source Link
Loading