0
$\begingroup$

I have here a code. I have the density plot of a function with the parameters.

May I ask about correcting some errors. (This is a Gaussian Function)

The parameters

zr = (\[Pi]*w0^2)/\[Lambda]\
[Lambda] = 543*10^-7
wz = w0 Sqrt[1 + (z/zr)^2]
Rz = z[1 + (zr/z)^2]
theta = \[Lambda]/(\[Pi]*w0)
f = 50
w0 = 6.275*10^-1
r = sqrt[x^2 + y^2]
I (r, z) = exp[-2*[r/wz]^2]


DensityPlot[I[r, z], {x, -0.5, 0.5}, {y, -0.5, 0.5}, ColorFunction -> GrayLevel, MaxRecursion -> 5]


Color[z_] := RGBColor[0, z, 0]

Manipulate[DensityPlot[I[r, z]*(Cos[l*ArcTan[y/x]])^2, {x, -0.2, 0.2}, {y, -0.2, 0.2}, ColorFunction -> Color, MaxRecursion -> 5], {z, -50, 50}, {l, 1, 3}]
$\endgroup$
2
  • $\begingroup$ In the last line, "color" (after command ColorFunction) is blue, so this is not a valid option $\endgroup$ – user740332 Feb 17 at 13:40
  • 2
    $\begingroup$ you cannot use "I" because this letter is protected, "I" is the imaginary number $\endgroup$ – user740332 Feb 17 at 13:50
2
$\begingroup$

Your question is poorly written for this site. You should try to minimize your code and identify where the first errors are. Then ask the specific errors here on this site, we can help. We don't normally fix all the code like I have done below

I recommend you read the following

  1. https://www.wolfram.com/language/fast-introduction-for-math-students/en/
  2. http://www2.eng.ox.ac.uk/~labejp/Seminar/Mathematica/MathematicaSeminarNotes.pdf

But anyway, in the comments, I have identified where some of your errors were.

(* define variables before you use them *) 
\[Lambda] = 543*10^-7;
f = 50;
w0 = 6.275*10^-1;
zr = (\[Pi]*w0^2)/\[Lambda];
theta = \[Lambda]/(Pi*w0);

wz[z_] := w0 *Sqrt[1 + (z/zr)^2];
(* rz is not used*) 
rz[z_] := z (1 + (zr/z)^2)

(* mathematica functions need capitals *) 
r[x_, y_] := Sqrt[x^2 + y^2];

(* dont define your functions with capitals *) 
(* don't use [] for multiplication *) 
ifunc[x_, y_, z_] := Module[{rtemp, result},
  rtemp = r[x, y];
  result = Exp[-2*(rtemp/wz[z])^2];
  Return[result]; 
  ]

z = 1
DensityPlot[ifunc[x, y, z], {x, -0.5, 0.5}, {y, -0.5, 0.5}]
DensityPlot3D[
 ifunc[x, y, z], {x, -0.5, 0.5}, {y, -0.5, 0.5}, {z, -1, 1}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you so much. This is a big help. (I am just having a crashed course for simulating my data). Thanks also for the resources. $\endgroup$ – AMA Feb 17 at 23:06

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.