1
$\begingroup$

I would like to make 3D plot of the following function.

F[x_]:=(x D[EllipticTheta[3, 0, E^(-Pi x)], {x, 2}] + 
      (3/2) D[EllipticTheta[3, 0, E^(-Pi x)], {x, 1}]) x^(5/4))

It did not work with F[1.0]. The error message is: General::ivar: 1.` is not a valid variable.

So I define it as:

    G[y_]:=((x D[EllipticTheta[3, 0, E^(-Pi x)], {x, 2}] + 
      (3/2) D[EllipticTheta[3, 0, E^(-Pi x)], {x, 1}]) x^(5/4)))//.x->y

I can now do:

Plot[F[t], {t, 0, 3/2}]
Plot[F[I t], {t, -Pi/2, Pi/2}]

Is there a proper way to define F[x] without using replacement?

$\endgroup$
3
$\begingroup$

Just use Evaluate.

Let's define

F[x_] := (x D[EllipticTheta[3, 0, E^(-Pi x)], {x, 2}] + (3/2) D[
      EllipticTheta[3, 0, E^(-Pi x)], {x, 1}]) x^(5/4)

First we plot the function on the real line

Plot[Evaluate[F[x]], {x, -2, 4}]
(* 141107_Plot _F (x).jpg *)

enter image description here

Now the 3D-plot for Re, Im, and Abs, respectively

Plot3D[Evaluate[Re[F[z] /. z -> x + I y]], {x, -2, 2}, {y, -1, 1}]
(* 141107_Plot3D _Re F (x).jpg *)

enter image description here

Plot3D[Evaluate[Im[F[z] /. z -> x + I y]], {x, -2, 2}, {y, -1, 1}]
(* 141107_Plot3D _Im F (x).jpg *)

enter image description here

Plot3D[Evaluate[Abs[F[z] /. z -> x + I y]], {x, -2, 2}, {y, -1, 1}]
(* 141107_Plot3D _Abs F (x).jpg *)

enter image description here

Regards,
Wolfgang

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks a lot for the help! How about the following plot? Plot3D[Evaluate[Abs[F[Exp[z]] /. z -> x + I y]], {x, 0, 2}, {y, -Pi/2, Pi/2}] $\endgroup$ – mike Nov 7 '14 at 22:49
  • $\begingroup$ Hi, evaluating F[1.0] gives an error. The OP pointed that out and I think wants to avoid it. $\endgroup$ – Michael E2 Nov 7 '14 at 23:20
  • $\begingroup$ @ Michael E2: you are right. Hence the best way to avoid it is to adopt Bob Hanlon's proposal. $\endgroup$ – Dr. Wolfgang Hintze Nov 8 '14 at 17:50
3
$\begingroup$

Use Set ( = ) rather than SetDelayed ( := ) so that the derivatives are carried out before x has a value.

F[x_] = (x D[EllipticTheta[3, 0, E^(-Pi x)], {x, 2}] + (3/2) D[
       EllipticTheta[3, 0, E^(-Pi x)], {x, 1}]) x^(5/4);

F[1.]

0.446697

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ @ Bob Hanlon: your idea is even better. I have compared the speed, funny but := with Evaluate[] is slightly faster than =. $\endgroup$ – Dr. Wolfgang Hintze Nov 7 '14 at 22:07
  • $\begingroup$ Thanks a lot. Both methods worked for me. $\endgroup$ – mike Nov 7 '14 at 23:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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