# Difficulty plotting a function with ParamericPlot3D

This works:

With[{a = 5, b = 2},
ParametricPlot3D[{(a + b Cos[t]) Cos[s], (a + b Cos[t]) Sin[s],
b Sin[t]}, {s, 0, 2 Pi}, {t, 0, 2 Pi}]]


Producing this image: Then I created this function:

T[s_, t_] := {(a + b Cos[t]) Cos[s], (a + b Cos[t]) Sin[s], b Sin[t]}


And it works:

T[s, t]


Output is: {Cos[s] (a + b Cos[t]), (a + b Cos[t]) Sin[s], b Sin[t]}

Then I tried:

With[{a = 5, b = 2},
ParametricPlot3D[T[s, t], {s, 0, 2 Pi}, {t, 0, 2 Pi}]]


Which produced this image: So, it didn't work. I also tried:

With[{a = 5, b = 2},
ParametricPlot3D[Evaluate@T[s, t], {s, 0, 2 Pi}, {t, 0, 2 Pi}]]


But that also didn't work. I am using Mathematica 11.2. What am I doing wrong?

Update: Thanks to the help below, this works and produces the same image:

T[a_, b_][s_, t_] := {(a + b Cos[t]) Cos[s], (a + b Cos[t]) Sin[s],
b Sin[t]};
With[{a = 5, b = 2},
ParametricPlot3D[T[a, b][s, t], {s, 0, 2 Pi}, {t, 0, 2 Pi}]]

• I think that the problem is that a and b are local variables and they are not assigned to T[s,t]. This definition works obviously T[s_, t_, a_, b_] := {(a + b Cos[t]) Cos[s], (a + b Cos[t]) Sin[s], b Sin[t]}. I just see there is the same answer – José Antonio Díaz Navas Nov 30 '17 at 19:50

With works like Module, i.e. creating local variables, whereas parameters a and b in function T are global (not inside With).

Consider the following example:

In:=   G := {a, b};
With[{a = 5, b = 2}, {{a, b}, G}]

Out:= {{5, 2}, {a, b}}


There are several possible workarounds.

1. You pass parameters a and b somehow to T:

In:=  T[a_, b_][s_, t_] := {(a + b Cos[t])Cos[s], (a + b Cos[t])Sin[s], b Sin[t]};
With[{a = 5, b = 2}, T[a, b][s, t]]

Out:= {Cos[s] (5 + 2 Cos[t]), (5 + 2 Cos[t]) Sin[s], 2 Sin[t]}

2. You use local replacement rule instead of actual variables.

In:=  T[s_, t_] := {(a + b Cos[t]) Cos[s], (a + b Cos[t]) Sin[s], b Sin[t]};
With[{sub = {a -> 5, b -> 2}}, T[s, t] /. sub]

Out:= {Cos[s] (5 + 2 Cos[t]), (5 + 2 Cos[t]) Sin[s], 2 Sin[t]}

• Thanks for the help. I added an update of what worked for me. – David Dec 1 '17 at 5:00

here is the solution:

T[s_, t_, a_, b_] := {(a + b Cos[t]) Cos[s], (a + b Cos[t]) Sin[s],b Sin[t]}

With[{a = 5, b = 2}, ParametricPlot3D[T[s, t, a, b], {s, 0, 2 Pi}, {t, 0, 2 Pi}]]