# [✓] Use Manipulate[] on a user defined function?

GROUPS:
 I want to define a function with the following variables : g21 g31 = 50 d2 = 20 d = d2 - d1 k = 10 geff =10 O1 = 0.001 O2 = 10 And the function itself is defined as : f[d1_] = O1*geff*(i*g21-2*d)/ ((0.5*g21*(-g31+2*d1)+ d*(-i*g31-2*d1)-0.5*(O2)^2)*i*k +geff^2*(4*d-2*i*g21)) And then I want to use Manipulate[] to see how the function changes for different values of g_21 : Manipulate[Plot[Abs[f[d1]], {d1, -40, 40}], {g21, 1, 50}] But I get a blank plot instead.I would really appreciate it if someone could help me on this. Thanks in advance
1 year ago
6 Replies
 Valeriu Ungureanu 1 Vote Your code have some undefined variables. I have done several modifications and propose you to adapt the following code to your needs: g31 = 50; d2 = 20; k = 10; geff = 10; O1 = 0.001; O2 = 10; f[d1_, g21_, i_] := O1*geff*(i*g21 - 2*(d2 - d1))/((0.5* g21*(-g31 + 2*d1) + (d2 - d1)*(-i*g31 - 2*d1) - 0.5*(O2)^2)* i*k + geff^2*(4*(d2 - d1) - 2*i*g21)) Manipulate[ Plot[Abs[f[d1, g21, i]], {d1, -40, 40}], {g21, 1, 50}, {i, 1, 10}] 
1 year ago
 "i" is the imaginary i. i^2 = -1.
1 year ago
 If $i$ is imaginary, then: f[d1_, g21_] := O1*geff*(I*g21 - 2*(d2 - d1))/((0.5* g21*(-g31 + 2*d1) + (d2 - d1)*(-I*g31 - 2*d1) - 0.5*(O2)^2)* I*k + geff^2*(4*(d2 - d1) - 2*I*g21)) Manipulate[ Plot[Abs[f[d1, g21]], {d1, -40, 40}, PlotRange -> All], {g21, 1, 50}] 
 You must clear $f$. You can use also: Remove["Global*"] `After that you need to define all variables and function.