Einführung in Mathematica XXII

Nichtlineare und Randwert-Probleme

© Jürgen Schnack, 2009/07/03

Problem

Mathematica kann Randwertprobleme z.B. mit 
DSolve
analytisch lösen.

Wenn das nicht weiterhilft, dann kann Mathematica mittels
NDSolve 
numerische Lösungen erzeugen.

Einfaches Beispiel 
(siehe Mathematica-Hilfe)

inhomogeneousequation = y''[x] +y[x]==E^x;
generalsolution = DSolve[inhomogeneousequation, y,x]

Jetzt mit Randbedingungen links und rechts.

SolA=DSolve[{inhomogeneousequation, y[0]==1, y[1]==1/2}, y,x]

Plot[y[x]/.SolA,{x,0,1},
PlotStyle->{{Thickness[0.01],Red}},
AxesLabel->{"x","y"},
TextStyle->{FontFamily->Helvetica,FontSize->18}]

It should be noted that, in contrast to initial value problems, there are no general existence or uniqueness theorems when boundary values are prescribed, and there may be no solution in some cases.

This problem has no solution because the term with C[2] in the general solution vanishes at both x==0 and x==π. Hence there are two inconsistent conditions for the parameter C[1] and the solution is an empty set.

DSolve[{inhomogeneousequation, y[0]==1, y[Pi]==6}, y,x]

Clear[x,y,z,t]

Eine Methode "Shooting"
(siehe Mathematica-Hilfe)

For boundary value problems, there is no guarantee of uniqueness as there is in the initial value problem case. "Shooting" will find only one solution. Just as you can affect the particular solution FindRoot gets for a system of nonlinear algebraic equations by changing the starting values, you can change the solution that "Shooting" finds by giving different initial conditions to start the iterations from.

"StartingInitialConditions" is an option of the "Shooting" method that allows you to specify the values and position of the initial conditions to start the shooting process from.

The shooting method by default starts with zero initial conditions so that if there is a zero solution, it will be returned.

This computes a very simple solution to the boundary value problem x''+sin(x)==0withx(0)=x(1)=0.

sols = Map[First[NDSolve[{x''[t] + Sin[x[t]] == 0, x[0] == x[10] == 0},x,t, Method->{"Shooting", "StartingInitialConditions"->{x[0] == 0, x'[0] == #}}]]&,
{1.5, 1.75, 2}];
Plot[Evaluate[x[t] /. sols], {t,0,10},PlotStyle->{{Red,Thick},{Blue,Thick},{Green,Thick}},
TextStyle->{FontFamily->Helvetica,FontSize->18}]

Clear[x,y,z,t]

Nichtlineare Probleme I
Logistische Gleichung

LogisticEquation = y'[t]== r(1-(y[t]/K))*y[t];

The right-hand side of the equation can be expanded to a quadratic polynomial in y[t]. Hence, the logistic equation is simply a Riccati equation, and its general solution can be easily found.

DSolve[LogisticEquation, y,t]

The next command sets the intrinsic growth rate r to 1/2 and the saturation level K to 4 and solves the initial value problem. The warning message from Solve is issued while solving for the arbitrary constant C[1] from the general solution.

DSolve[{LogisticEquation/.{r-> (1/2), K-> 4}, y[0]==1}, y,t]

The next command solves the initial value problem for the logistic equation with symbolic parameters r and K.

sol=DSolve[{LogisticEquation, y[0]==a*K}, y,t]

Here is a plot of the solution for different values of r and K.

Plot[Evaluate[Table[y[t]/.sol[[1]]/.{K-> 4, a-> i, r-> (1/3)}, {i,2,1/10, -1/3}]], {t,0,8}, PlotRange -> All,PlotStyle->{{Red,Thick},{Blue,Thick},{Green,Thick},{Black,Thick},{Cyan,Thick},{Magenta,Thick}},
TextStyle->{FontFamily->Helvetica,FontSize->18}]

Clear[x,y,z,t]

Beispiele für NDSolve

NDSolve in Hilfe nachschlagen.

SolB=NDSolve[{y''[x]+ Sin[y[x]]y[x]==0,y[0]==1,y'[0]==0},y,{x,0,30}]

Plot[Evaluate[{y[x],y'[x],y''[x]}/.SolB],{x,0,30},PlotStyle->{{Red,Thick},{Blue,Thick},{Green,Thick}},
AxesLabel->{"x","y"},
TextStyle->{FontFamily->Helvetica,FontSize->18}]

Clear[x,y,z,t]

Beispiel 2

SolC = NDSolve[{x''[t]==y[t] x[t],y'[t]==2-x[t],x[0]==x[4]==1,y[1]==1},{x,y}, t]//Quiet

Plot[Evaluate[{x[t], y[t]} /. First[SolC]],{t,0,4},Epilog->{PointSize[Large],Red,Point[{0,1}],Point[{4,1}],Blue,Point[{1,1}]},PlotStyle->{{Red,Thick},{Blue,Thick},{Green,Thick}},
AxesLabel->{"x","y"},
TextStyle->{FontFamily->Helvetica,FontSize->18}]

Clear[x,y,z,t]

Nonlinear sine-Gordon equation in two spatial dimensions with periodic boundary conditions

L = 4;
SolD = NDSolve[{D[u[t,x,y], t, t] == D[u[t,x,y], x,x] + D[u[t, x, y], y, y] + Sin[u[t,x,y]], u[t,-L, y] == u[t, L, y], u[t, x, -L] == u[t, x, L], u[0,x, y] == Exp[-(x^2 + y^2)], Derivative[1,0,0][u][0,x,y] == 0}, u, {t,0,L/2}, {x,-L,L},{y,-L,L}]

Plot the solution at the final time:

Plot3D[u[L/2, x, y] /. First[SolD], {x,-L,L},{y,-L,L}]

For[i=0,i<21,i++,
Print[Plot3D[u[(i/20)*L/2, x, y] /. First[SolD], {x,-L,L},{y,-L,L},PlotRange->{0.0,1.0}]]]