3
$\begingroup$
f[x, y] := {1 - ((20 - x)/20)^y}
scalarField = (1 - ((20 - x)/20)^y) - z       (*This is the same as f[x, y] - z, used later*)
vectorField = D[scalarField,  {{x, y, z}}]

In[98]:= v = VectorPlot3D[vectorField, {x, 0.001, 10}, {y, 0.001, 5}, {z, 0, 1}, 
                          RegionFunction -> Function[{x, y, z}, TrueQ[f[x, y] == z]], 
                          VectorPoints -> Automatic]

I get the following error:

VectorPlot3D::ppts: Value of option PlotPoints -> {} is not an integer >= 2.

I'm VERY new to Mathematica and the documentation doesn't really help me understand what I'm doing wrong.

What I want to happen is that I get only the vectors on the surface of f[x, y], so the documentation says I should be using the RegionFunction property. The Region function property was giving me even MORE errors before I wrapped it in TrueQ (it was claiming f[x,y] == z wasn't boolean).

What am I doing wrong?

$\endgroup$
3
  • $\begingroup$ function f[x, y] should be f[x_, y_], but the problem is that TrueQ[f[x, y] == z] is always false. Hence there is no region to plot. It like writing RegionFunction -> Function[{x, y, z}, False] $\endgroup$ Commented Apr 8, 2020 at 0:24
  • $\begingroup$ @Nasser Why is f[x, y] == z always False? There are values (x, y, z) for which TrueQ[f[x,y] == z] is True. For example: TrueQ[f[3, 3] == {3087/8000}] $\endgroup$ Commented Apr 8, 2020 at 0:26
  • 1
    $\begingroup$ It's really not a good error message, is it? $\endgroup$ Commented Apr 8, 2020 at 2:09

2 Answers 2

4
$\begingroup$

Another way to get the desired sampling:

ClearAll[f];
f[x_, y_] := {1 - ((20 - x)/20)^y}
scalarField = (1 - ((20 - x)/20)^y) - z;
vectorField = D[scalarField, {{x, y, z}}];

r = Plot3D[f[x, y], {x, 0.001, 10}, {y, 0.001, 5}, Mesh -> None, 
   MaxRecursion -> 0, PlotPoints -> 9, NormalsFunction -> None];

v = VectorPlot3D[
  vectorField, {x, 0.001, 10}, {y, 0.001, 5}, {z, 0, 1}, 
  VectorPoints -> 
   Cases[r, {_Real, _Real, z_Real}, Infinity],
  VectorScaling -> Automatic]

enter image description here

$\endgroup$
1
  • $\begingroup$ A more direct way to get sampling: r = Flatten[ Outer[Flatten@{##, f@##} &, Subdivide[0.001, 10, 8], Subdivide[0.001, 5, 8]], 1]. The inner Flatten would be unnecessary if f[x, y] returned a scalar instead of a 1-vector. But Plot3D[] will automatically handle singularities and holes in the domain of f[]. $\endgroup$ Commented Apr 8, 2020 at 12:41
2
$\begingroup$
 Why is f[x, y] == z always False?

The numbers are not exact. You could add tolerance. Without it, RegionFunction returns False, there was no case where TrueQ[f[x, y] == z] returned True.

scalarField = (1 - ((20 - x)/20)^y) - 
  z       (*This is the same as f[x,y]-z,used later*)
vectorField = D[scalarField, {{x, y, z}}]
f[x_, y_] := 1 - ((20 - x)/20)^y
epsilon = 0.1;
VectorPlot3D[vectorField, {x, 0.001, 10}, {y, 0.001, 5}, {z, 0, 1}, 
 RegionFunction -> Function[{x, y, z}, Abs[f[x, y] - z] < epsilon], 
 VectorPoints -> Automatic]

Mathematica graphics

You could also make your VectorPoints -> Fine instead of automatic. But the whole reason for the error you are getting is that TrueQ[f[x, y] == z] returns False for all the sampling used as is.

For example

epsilon = 0.01;
VectorPlot3D[vectorField, {x, 0.001, 10}, {y, 0.001, 5}, {z, 0, 1}, 
 RegionFunction -> Function[{x, y, z}, TrueQ[Abs[f[x, y] - z] < epsilon ]], 
 VectorPoints -> 30]

Returns

Mathematica graphics

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.