Message Boards Message Boards

0
|
5022 Views
|
6 Replies
|
2 Total Likes
View groups...
Share
Share this post:

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

Posted 8 years ago

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

6 Replies

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

Remove["Global`*"]

After that you need to define all variables and function.

Thank you so much! its working now!

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}]

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

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}]

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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract