# How to plot user-defined function with multiple variables

I wanted to plot the function:

TheoreticalT[n2_, k2_, w_] := (2*cn2[n2, k2]*(n1 + n3)*E^i(2*Pi*w*d2 (cn2[n2, k2] - 1))/c))/
((n1 + cn2[n2, k2])*(n3 + cn2[n2, k2]) - (cn2[n2, k2] - n1)*(cn2[n2, k2] - n3)*
e^(i(2*cn2[n2, k2]*2*Pi*w*d2)/c));


with n2 and k2 defined from:

cn2[n2_, k2_] := n2 - ik2;


and all the other variables being constants (n1, n3, d2, c):

n1 = 1 + i0; (*complex index of refraction of air*)
n3 = 1.7862 + I 0; (*complex index of refraction of substrate*)
d2 = 2.9477*10^-5; (*thickness of the sample(mm)*)
c = 0.29979;(*speed of light:mm/ps*)


I have tried doing a simple plot of just the n2 variable:

Plot[TheoreticalT[n2_, w_], {w, 0, 3}, Evaluated -> True]


But I'm not seeing any plot: [![enter image description here][1]][1]

Any suggestions on how to proceed? Thank you [1]: https://i.stack.imgur.com/m9wXI.png

• Please provide a complete minimal example of your problem. There are variables n2, n3 etc that are undefined, are you setting them somewhere? If yes please provide them. Aug 10, 2020 at 7:28
• Hi, I edited it already. n1 and n3 are also constants Aug 10, 2020 at 7:33
• Please provide the whole code where you set all free variables. Aug 10, 2020 at 7:37
• I edited it again. Thank you Aug 10, 2020 at 7:43
• Mathematica is strict about capitalization. For input Sqrt[-1] is I and not i Any letter followed by letters or numbers is a variable. But 3y is 3*y because it does not start with a letter. It does not understand you may think i0 is the square root of -1 and then multiplied by zero. For input E is Euler's constant and not e When a plot will not appear think "complex numbers? or undefined variables?" Trying Table instead can sometimes show you what is the problem, but you must have the right step size to see the problem. I hope this helped..
– Bill
Aug 10, 2020 at 8:45

The Reason is that you try to plot a function Mathematica does not know: TheoreticalT takes in 3 input values not two. Also the syntax is different, see below. Also you have not set all variables in your provided code the following parameters are free:

ik2, i0, e , i, n2


I think you want to change e->E and i->I. Notice Mathematica Notebook shows unknown variables in blue. You further want to change:

Plot[TheoreticalT[n2_, w_], {w, 0, 3}, Evaluated -> True]


into:

Plot[{Re@TheoreticalT[n2, k2, w], Im@TheoreticalT[n2, k2, w]}, {w, 0, 3}]


Which means you need to set k2 as well.

• there is also a bracket missing in the exponent here: *(n1 + n3)*E^i(2*Pi*w*d2 (cn2[n2, k Aug 10, 2020 at 7:58
• Wow thank you for answering. Let me try it out Aug 10, 2020 at 8:01