Plotting the solution

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.

• 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 Nov 8, 2022 at 17:38
• I am still getting an empty graph Nov 8, 2022 at 17:44
• 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? Nov 8, 2022 at 17:46
• 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? Nov 8, 2022 at 17:47
• 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. Nov 8, 2022 at 17:49

1 Answer

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

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

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