Message Boards Message Boards

No plot appears when inside Manipulate

Posted 11 years ago

Hello everybody, I am having some issues with mathematica : I am trying to plot a function using "Manipulation". I can see the axis but I can not see any plot of the function. I also tried with a simple plot (without "Manipulation") by fixing some of the parameters. Here is my code using manipulation :

Manipulate[Plot[-J1^2 - k3 + (w^2/c^2) + (-1 + (wn1^2/wn1^2 + wn2^2 - w^2), {w, 0, 10}], {J1, 1, 10}, {c, 1,  10}, {k3, 1, 10}, {wn1, 1, 100}, {wn2, 1, 10}]

And here is my code using just "Plot":

J1 = 1; c = 2; k3 = 5; wn1 = 5; wn2 = 3; k1=2;
Plot[-J1^2 - k3 + w^2/c^2 +k1 (-1 + wn1^2/(wn1^2 + wn2^2 - w^2)), {w, 0, 10}]

If anyone can help me I would appreciate a lot.

Thank you very much in advance

edoardo

POSTED BY: edoardo rubino

You are missing a bracket and appear to be missing a factor of k1 in the argument of the Plot and the Manipulate functions also is missing iterator for the k1 parameter. Here is your Manipulate with the bracket and the k1 factor and iterator added--actually just copying the plot expression from your second bit of code:

Manipulate[
 Plot[-J1^2 - k3 + w^2/c^2 + 
   k1 (-1 + wn1^2/(wn1^2 + wn2^2 - w^2)), {w, 0, 10}], {J1, 1, 
  10}, {c, 1, 10}, {k3, 1, 10}, {wn1, 1, 100}, {wn2, 1, 10}, {k1, 1, 
  10}]

This yields a plot. Also you can initialize the values of your parameters to the ones that you specify as in the following:

Manipulate[
 Plot[-J1^2 - k3 + w^2/c^2 + 
   k1 (-1 + wn1^2/(wn1^2 + wn2^2 - w^2)), {w, 0, 10}],
 {{J1, 1}, 1, 10},
 {{c, 2}, 1, 10},
 {{k3, 5}, 1, 10},
 {{wn1, 5}, 1, 100},
 {{wn2, 3}, 1, 10},
 {{k1, 2}, 1, 10}]

Lesson learned: take a good look at your expressions and compare them. Here are your two different arguments of your Plot functions compared (with the syntactically missing bracket in the first one inserted but without the k1 factor in the first one -- by the way, the syntax coloring would give you a hit that something is wrong--minus the second one...):

(-J1^2 - k3 + (w^2/c^2) + (-1 + (wn1^2/wn1^2 + wn2^2 - w^2))) -
  -J1^2 - k3 + w^2/c^2 + 
  k1 (-1 + wn1^2/(wn1^2 + wn2^2 - w^2)) // Simplify

which does not give zero...it gives:

-2 k3 - w^2 + (2 w^2)/c^2 + wn2^2 + 
 k1 (-1 + wn1^2/(-w^2 + wn1^2 + wn2^2))
POSTED BY: David Reiss
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