1
$\begingroup$

I have the following code to solve an equation

Solve[-P + (4 a^2 P)/225 - 4/675 (-15 + a)^2 (2 c + P) - 
   8/675 (-15 + a) ((15 + 2 a) c + (-15 + a) P) == 0, a, Reals]

I want to plot the solution and check how the value of changes with P and c. I tried doing this

Plot3D[(15 (c + P))/(2 c) - (15 Sqrt[(2 c^2 - c P + 2 P^2)/c^2])/(
  2 Sqrt[2]), {c, 0, \[Infinity]}, {p, 0, \[Infinity]}, 
 Mesh -> Automatic, MeshFunctions -> Automatic, Filling -> Bottom]

But it is giving me an empty graph. Where am I doing wrong? Also, Can I get a 2D plot where I can see the change in a by changing P and c. I am new to Mathematica.

$\endgroup$
5
  • $\begingroup$ Where am I doing wrong? you have typo. It is P and not p. Try the following. sol = Solve[-P + (4 a^2 P)/225 - 4/675 (-15 + a)^2 (2 c + P) - 8/675 (-15 + a) ((15 + 2 a) c + (-15 + a) P) == 0, a, Reals]; a /. sol[[1]]; Plot3D[%, {c, 0, Infinity}, {P, 0, Infinity}, Mesh -> Automatic, MeshFunctions -> Automatic, Filling -> Bottom] gives !Mathematica graphics $\endgroup$
    – Nasser
    Nov 8, 2022 at 17:38
  • $\begingroup$ I am still getting an empty graph $\endgroup$
    – P Initiate
    Nov 8, 2022 at 17:44
  • $\begingroup$ I am still getting an empty graph Strange. You can see from the screen shot it is not empty. Did you type exactly what I gave? I am using V 13.1. Which version are you using? $\endgroup$
    – Nasser
    Nov 8, 2022 at 17:46
  • $\begingroup$ Now I could get it as there was a mistake. Can I also get a 2D graph for better visualization where I can see how a value falls when I change P and C? $\endgroup$
    – P Initiate
    Nov 8, 2022 at 17:47
  • $\begingroup$ Yes you can. But this is now different question. I'll try to do that but please update first your question with the corrected version and add these new requirements to the question so people can see the updates. $\endgroup$
    – Nasser
    Nov 8, 2022 at 17:49

1 Answer 1

1
$\begingroup$

Also, Can I get a 2D plot where I can see the change in a by changing P and c.

Make a slider to change c and slider to change P, something like this (and corrected the spelling of your P as mentioned in comment`

enter image description here

ClearAll[a, P, c];
sol = Solve[-P + (4 a^2 P)/225 - 4/675 (-15 + a)^2 (2 c + P) - 
     8/675 (-15 + a) ((15 + 2 a) c + (-15 + a) P) == 0, a, Reals];

Manipulate[
 Module[{currentSol = a /. First@sol, 
   g = {GridLines -> Automatic, GridLinesStyle -> LightGray}},
  Grid[{{
     Plot[currentSol /. c -> c0, {P, 0, P0}, PlotLabel -> "a vs. P", 
      AxesLabel -> {"P", "a"}, Evaluate@g, PlotStyle -> Red],
     Plot[currentSol /. P -> P0, {c, 0, c0}, PlotLabel -> "a vs. c", 
      AxesLabel -> {"c", "a"}, Evaluate@g, PlotStyle -> Blue]}}
   ]
  ],
 {{c0, .1, "c ?"}, .1, 100, .1, Appearance -> "Labeled"},
 {{P0, .1, "P ?"}, .1, 100, .1, Appearance -> "Labeled"},
 TrackedSymbols :> {c0, P0}
 ]

Or if you want to show 3D next to the 2D

enter image description here

ClearAll[a, P, c];
sol = Solve[-P + (4 a^2 P)/225 - 4/675 (-15 + a)^2 (2 c + P) - 
     8/675 (-15 + a) ((15 + 2 a) c + (-15 + a) P) == 0, a, Reals];

Manipulate[
 Module[{currentSol = a /. First@sol,
   opt1 = {GridLines -> Automatic, GridLinesStyle -> LightGray}, 
   opt2 = {Mesh -> Automatic, MeshFunctions -> Automatic, 
     Filling -> Bottom, PerformanceGoal -> "Quality", 
     AxesLabel -> {"c", "P", "a"}, BaseStyle -> 12}
   },
  
  Grid[{{Plot3D[currentSol, {c, 0, c0}, {P, 0, P0}, Evaluate@opt2], 
     SpanFromLeft},
    {Plot[currentSol /. c -> c0, {P, 0, P0}, PlotLabel -> "a vs. P", 
      AxesLabel -> {"P", "a"}, Evaluate@opt1, PlotStyle -> Red],
     Plot[currentSol /. P -> P0, {c, 0, c0}, PlotLabel -> "a vs. c", 
      AxesLabel -> {"c", "a"}, Evaluate@opt1, PlotStyle -> Blue]}},
   Spacings -> {3, 3}, Frame -> All
   ]
  ],
 {{c0, .1, "c ?"}, .1, 100, .1, Appearance -> "Labeled"},
 {{P0, .1, "P ?"}, .1, 100, .1, Appearance -> "Labeled"},
 TrackedSymbols :> {c0, P0}
 ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.