# Trying to plot a function in Mathematica

Posted 9 years ago
5897 Views
|
8 Replies
|
0 Total Likes
|
 Trying this plot command Plot[p^2/((p^2 - k^2) (p^2 + m^2)), {p, 0, k}] and Mathematica gives some cryptic message!
8 Replies
Sort By:
Posted 9 years ago
 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 sliceFor 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] &)] 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 9 years ago
 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 getwhich 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%29you should get which is the same result. You also might find this thread useful. Hope this helps,Marco
Posted 9 years ago
 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 9 years ago
 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}] 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 9 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,pbut maybe one of them is constant or two of them. you know If is three dimensional is Plot3D[.....]
Posted 9 years ago
 Plot can not be called with multiple variables. Only one.
Posted 9 years ago
 And the value of m!
Posted 9 years ago
 You didn't tell it the value of k.