0
$\begingroup$

I am trying to plot an arrow in the direction of the gradient. This is my code:

Graphics3D[{Red, Arrowheads[0.07], 
 Arrow[Tube[{{x0, y0, 
     F[x0, y0]}, {{x0, y0, F[x0, y0]} + gradF[x0, y0, F[x0, y0]]/
      Norm[gradF[x0, y0, F[x0, y0]]]}, {{x0, y0, F[x0, y0]} + 
      gradF[x0, y0, F[x0, y0]]/Norm[gradF[x0, y0, F[x0, y0]]]}}, 
   0.05]]}]

However, i am getting the error on the description. I am trying to solve it but i am not able to. This is gradF

gradF[x_, y_, z_] = Grad[F1[x, y, z], {x, y, z}]

and this is F1

F1[x_, y_, z_] := F[x, y] - z;

this is F

F[x_, y_] := -( x^2 + y^2);

I am trying to understand exactly why i am getting that error so i can solve it my self in the future. Let me know if you need more details of the code. Any help will be appreciated.

$\endgroup$
2
  • $\begingroup$ x0 and y0 need to be numbers, and you have two many {} around the second and third elements of the Tube. Look at the InputForm of your expression. $\endgroup$
    – Carl Woll
    Commented Jun 7, 2017 at 17:06
  • $\begingroup$ @CarlWoll This is inside a Manipulate and x0 and y0 are the parameters that i manipulate. Does that matter? $\endgroup$
    – blidt
    Commented Jun 7, 2017 at 18:00

1 Answer 1

1
$\begingroup$

As I said in the comments, look at the InputForm of the graphics:

With[{x0=1,y0=1},
    Graphics3D[{
        Red,Arrowheads[0.07],
        Arrow[Tube[
            {
            {x0,y0,F[x0,y0]},
            {{x0,y0,F[x0,y0]}+gradF[x0,y0,F[x0,y0]]/Norm[gradF[x0,y0,F[x0,y0]]]},
            {{x0,y0,F[x0,y0]}+gradF[x0,y0,F[x0,y0]]/Norm[gradF[x0,y0,F[x0,y0]]]}
            },
            0.05
        ]]
    }]
]//InputForm

Graphics3D[{RGBColor[1, 0, 0], Arrowheads[0.07], Arrow[Tube[{{1, 1, -2}, {{1/3, 1/3, -7/3}}, {{1/3, 1/3, -7/3}}}, 0.05]]}]

You should see that the second and third elements of the argument to Tube have an extra {} around them. If you remove these extra braces, you will have:

With[{x0=1,y0=1},
    Graphics3D[{
        Red,Arrowheads[0.07],
        Arrow[Tube[
            {
            {x0,y0,F[x0,y0]},
            {x0,y0,F[x0,y0]}+gradF[x0,y0,F[x0,y0]]/Norm[gradF[x0,y0,F[x0,y0]]],
            {x0,y0,F[x0,y0]}+gradF[x0,y0,F[x0,y0]]/Norm[gradF[x0,y0,F[x0,y0]]]
            },
            0.05
        ]]
    }]
]

The above produces a valid Graphics3D object.

$\endgroup$

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.