0
$\begingroup$

I have a forced heat PDE with some parameters, and my goal is to define a function as the numerical solution of the PDE with specified parameters. I have tried the following (got the idea from this post)

g[x_, t_, k_?NumericQ, a_?NumericQ, L_?NumericQ, T_?NumericQ] := 
First [f[x,t] /. NDSolve[{D[f[x, t], {t, 1}] - k D[f[x, t], {x, 2}] == (Exp[-x^2/(2a^2)] / Sqrt[2 Pi a^2]) f[x,t], 
f[x, 0] == L - Abs[x], f[L, t] == f[-L, t] == 0}, f, {x, -L, L}, {t, 0, T}]];

and then I want to plot g several sets of k,a,L,T. I have put ?NumericQ since these are going to be numerical values. Now when I try a specific set of parameters, say sln = g[x,t,1,1,1,1], Mathematica v13.1 seems to generate an interpolation (although with an NDSolve::mxsst error). However, I do not know how to Plot the result, since something like

Plot3D[y[x, t] /. sln, {x, 0, 1}, {t, 0, 1}]

generates errors (I would actually prefer a Manipulate[Plot[y[x,t]/.sln,{x,0,1}],{t,01}] so that I can see how the solution develops over time).

Is there a way to resolve this? Furthermore, since I need to generate many of these plots in a given range of parameters (say 0.2<a<2 and 0.1<k<1 both with 0.1 steps), I was wondering if there is a way to automatically produce all these plots without needing to manually replace the parameters for each plot? My guess is that this is doable with a Table but I don't know how exactly.

$\endgroup$
3
  • $\begingroup$ (1) Have you seen ParametricNDSolveValue[]? (2) If the time integration didn't finish (NDSolve::mxsst?), then adjust the time domain in the plot to how far the integration got. $\endgroup$
    – Michael E2
    Jan 4, 2023 at 18:25
  • $\begingroup$ @MichaelE2 I am trying ParametericNDSolveValue now. Is there a way to pass the interval sizes L,T as parameters too? (when I try it gives an error that says there are too many parameters). (2) How can I find how far the integration has got? $\endgroup$
    – SaMaSo
    Jan 4, 2023 at 21:49
  • 1
    $\begingroup$ Have a look at the documentation, for example HeatTransferPDEComponent that has examples of plotting the solution. $\endgroup$
    – user21
    Jan 5, 2023 at 6:34

0

Your Answer

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