# Density plot using NDSolve

I want solve a differential equation for varying parameter and then I wish to create a list which contains the parameter and corresponding value of differential equation. So that I can make a List Density plot.

differential equation is

f = y'[x] == a*Cos[x] + b*Sin[x];
Table[{a,b,NDSolve[{f,y==1},y,{x,1,10}]},{a,1,5},{b,1,5}]


I want to have a list with parameter and its corresponding differential equation solution, like {{a,b,value},{a',b',value},{}}. So I can use ListDensity Plot . Any suggestions are welcome

• Welcome to the Mathematica Stack Exchange. Please include Mathematica code for what you have tried so far.
– Syed
Nov 17, 2022 at 8:37
• I have added a simple example which I am trying solve Nov 17, 2022 at 8:48
• What is the meaning of " So I can use ListDensity Plot"? Nov 17, 2022 at 8:55
• At the end I want to create a list. Basically I need to make a density plot of the diff equation for varying parameters Nov 17, 2022 at 8:56
• DensityPlot of a,b and ??? or y[a,b][x]? Nov 17, 2022 at 8:58

Useing ParametricNDSolveValue.

Clear[sol];
sol = ParametricNDSolveValue[{y'[x] == a*Cos[x] + b*Sin[x],
y == 1}, y, {x, 1, 10}, {a, b}];
Block[{x = 5}, DensityPlot[sol[a, b]@x, {a, 1, 5}, {b, 1, 5}]] DensityPlot3D[sol[a, b]@x, {a, 1, 5}, {b, 1, 5},{x, 1, 10}] • Thank you for your solution. It worked. What happens if there are more than one differential equations? Then how do you plot a specific differential equation? Nov 17, 2022 at 9:59
• @physicsgeek You can ask a new equations and post a new code about it. Thanks your accption. Nov 17, 2022 at 10:01
• I have posted a different question. I t would be nice to have some help @cvgmt Nov 17, 2022 at 10:12
• mathematica.stackexchange.com/questions/276143/… Nov 17, 2022 at 10:13

Try NDSolveValue :

Table[{a,b,NDSolveValue[{f,y==1},y,{x,1,10}]},{a,1,5},{b,1,5}]

• I tried but it gives me a list which I cannot use to create a density plot using the command list density plot Nov 17, 2022 at 8:58