Message Boards Message Boards

[✓] 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

Answer
2 months ago

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}]
POSTED BY: Valeriu Ungureanu
Answer
2 months ago

"i" is the imaginary i. i^2 = -1.

Answer
2 months 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}]
POSTED BY: Valeriu Ungureanu
Answer
2 months ago

Here is what I get when I run the code : enter image description here

Answer
2 months ago

You must clear $f$. You can use also:

Remove["Global`*"]

After that you need to define all variables and function.

POSTED BY: Valeriu Ungureanu
Answer
2 months ago

Thank you so much! its working now!

Answer
2 months ago

Group Abstract Group Abstract