Message Boards Message Boards

0
|
6506 Views
|
8 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Trying to plot a function in Mathematica

Posted 10 years ago

Trying this plot command

Plot[p^2/((p^2 - k^2) (p^2 + m^2)), {p, 0, k}]

and Mathematica gives some cryptic message!

POSTED BY: Yaj Bhattacharya
8 Replies

As I said technically you do not need to specify k and m, if you use the following trick:

ContourPlot[p^2/((p^2 - k^2) (p^2 + m^2)) /. k -> 4, {p, -10, 10}, {m, -10, 10}, Frame -> False, 
ContourStyle -> Opacity[0.02] , ImagePadding -> False]

gives you a single slice

enter image description here

For this slice we set k to 4. If we now construct a list of images using:

imgs = Table[Image[ContourPlot[p^2/((p^2 - k^2) (p^2 + m^2)) /. k -> kc, {p, -10, 10}, {m, -10, 10}, PlotPoints -> 50, 
Frame -> False,    ImagePadding -> None, ContourStyle -> Opacity[0.02]]], {kc, -10, 10}];

, we can use Image3D to plot a three dimensional plot, which colour codes the value here in a grayscale:

Image3D[imgs, BoxRatios -> {1, 1, 1}, Background -> White, 
ColorFunction -> (GrayLevel[#, 0.05] &)]

enter image description here

You could also try any of these functions:

Image3D[imgs, BoxRatios -> {1, 1, 1}, Background -> White, ColorFunction -> "XRay"]
Image3D[imgs, BoxRatios -> {1, 1, 1}, Background -> White,  ColorFunction -> "LowRange"]

Like so you can circumvent the problem of having to fix any of p, m, k. The trick is basically that you have three independent variables and code the dependent one in gray.

Cheers, M.

PS: and if you use this command:

imgs = Table[Image[ContourPlot[p^2/((p^2 - k^2) (p^2 + m^2)) /. k -> kc, {p, -10, 10}, {m, -10, 10}, 
PlotPoints -> 50, Frame -> False, ImagePadding -> None, ContourStyle -> Opacity[0.02]]], {kc, -10.5, 10.5, 1}];

you avoid the problem of k being zero. Unfortunately, then the first of the Image3D I give above does not work anymore and you need to use one of the other two.

POSTED BY: Marco Thiel

Hi Yaj,

no the Manipulate is not necessarily to check where the function is defined. I used Manipulate only so that the Plot function would have values for all parameters. The main problem in your command was that if you do not specify k and m Mathematica cannot plot anything. (Well, technically it can, but its not what you wanted.) Manipulate masks that by providing values for k and m that you can later change.

Regarding the domain of the function: If you use the Wolfram Cloud (highly recommended), or Mathematica on the Raspberry Pi or Mathematica 10, and type in

FunctionDomain[p^2/((p^2 - k^2) (p^2 + m^2)),p]

you get

enter image description here

which is the Domain. You can also get essentially the same result if you consult WolframAlpha in Mathematica

== Domain p^2/((p^2 - k^2) (p^2 + m^2))

or via the internet

http://www.wolframalpha.com/input/?i=domain+p%5E2%2F%28%28p%5E2+-+k%5E2%29+%28p%5E2+%2B+m%5E2%29%29

you should get

enter image description here

which is the same result. You also might find this thread useful.

Hope this helps,

Marco

POSTED BY: Marco Thiel

Thank you Marco!

[Thanks everyone who replied]

This is exactly what I needed: Question: Is the command "Manipulate" enough/essential to check where the graph exists i.e. what the constraints on the three variables are?

POSTED BY: Yaj Bhattacharya

I am not quite sure what you want to achieve, but this might help:

Manipulate[If[k == 0, "Not Defined", Plot[p^2/((p^2 - k^2) (p^2 + m^2)), {p, 0, k}]], {m, -10, 10}, {k, -10, 10}]

enter image description here

To plot the function it "pre-sets" m and k for you, but you can change them with the sliders. I also added a "not defined" output when k==0.

M.

POSTED BY: Marco Thiel
Posted 10 years ago

I think the function you want to plot consist in three variables, so plot is as follows

Plot[f[x,y,z],{x,xmin,xmax},{y,ymin,ymax},{z,zmin,zmax}]

in your case the vairables are m,k,p

but maybe one of them is constant or two of them. you know If is three dimensional is Plot3D[.....]

POSTED BY: Charls Mejía

Plot can not be called with multiple variables. Only one.

POSTED BY: Sander Huisman

And the value of m!

POSTED BY: Sander Huisman

You didn't tell it the value of k.

POSTED BY: Frank Kampas
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