0
$\begingroup$

I have to solve a two coupled differential equations with two parameters. Then I need to make a density plot for a specific value of time. Find the code below

Clear[sol];
sol = ParametricNDSolveValue[{y'[t] == a*Cos[t] + b*Sin[t], z'[t]==a*Tan[t]+b*Sin[t]
,y[0] == 1,z[0]==0}, {y,z}, {t, 1, 10}, {a, b}];
Block[{t = 1}, DensityPlot[y[t]/.sol[a, b]@t, {a, 1, 5}, {b, 1, 5}]]

I tried doing it like the above mentioned way. I used the suggestion from one of the user here in stack exchange. I did not succeed when I tried to modify it

$\endgroup$

2 Answers 2

0
$\begingroup$

We can use ParametricNDSolve and set {t, 0, 1}

Clear[sol];
sol = ParametricNDSolve[{y'[t] == a*Cos[t] + b*Sin[t], 
    z'[t] == a*Tan[t] + b*Sin[t], y[0] == 1, z[0] == 0}, {y, z}, {t, 
    0, 1}, {a, b}];
Block[{t = 1}, DensityPlot[y[a, b][t] /. sol, {a, 1, 5}, {b, 1, 5}]]

enter image description here

$\endgroup$
0
0
$\begingroup$

Try

sol = ParametricNDSolveValue[{y'[t] == a*Cos[t] + b*Sin[t], 
z'[t] == a*Tan[t] + b*Sin[t], y[0] == 1, z[0] == 0}, {y, z}, {t, 
1, 10}, {a, b}];
DensityPlot[ sol[a, b][[1]][1], {a, 1, 5}, {b, 1, 5}] 
$\endgroup$
0

Your Answer

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

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