0
$\begingroup$

I have a set of equations pdes and some initial/boundary conditions bcs. These conditions depend on some parameters, which I can group as n sets,bcsi labeled by i where i=1,...,n.

When solving the equations (for one single set of conditions) I write

sols=NDSolveValue[{pdes,bcs},{y1[x],y2[x],...,yN[x]},{x,xi,xf}]

If I want to plot the solution, lets say y1[x], I write

ploty1=Plot[First@sols,{x,xi,xf}]

Now, if I want to solve the equations for each set of conditions, and then to plot, for example, y1[x] again, I would do the following

sol1=NDSolveValue[{pdes,bcs1},{y1[x],y2[x],...,yN[x]},{x,xi,xf}]
sol2=NDSolveValue[{pdes,bcs2},{y1[x],y2[x],...,yN[x]},{x,xi,xf}]
...
soln=NDSolveValue[{pdes,bcsn},{y1[x],y2[x],...,yN[x]},{x,xi,xf}]

and make plots in the same way, etc, and do the following

Plot[{First@sol1,...,First@soln},{x,xi,xf}]

to get the solutions for y1[x] depending on each set of conditions. Is there a way to construct this plot not solving for each set separately but as a List or Table, in such a way that just doing

Plot[First@solutions,{x,xi,xf}],

where solutions is the set of solutions for each condition, allows to see how y1 changes when I change the conditions?

$\endgroup$
  • 1
    $\begingroup$ I would first put the boundary conditions in a table and then use sol=Table[NDSolveValue[{pdes,bcs[[i]]}],{i,1,n}] to get the solutions in one table. $\endgroup$ – egwene sedai Nov 7 '17 at 21:12
  • 2
    $\begingroup$ If you're going to be varying the boundary conditions a lot, you might want to use ParametricNDSolveValue[] instead. $\endgroup$ – J. M. will be back soon Nov 7 '17 at 21:46
1
$\begingroup$

First put the conditions in a table

bcst={bcs1,...bcsn}

As suggested above, to solve the equations together

sols=Table[NDSolveValue[{pdes,bcst[[i]]},{y1[x],...,yN[x]},{x,xi,xf}],{i,1,n}]

to plot the curves for y1[x] for each condition, we write

Plot[Evaluate[Table[First@sols[[i]],{i,1,n}]],{x,xi,xf}]

Since we have n plots, one can give colors to each curve by setting n color inside PlotStyle

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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