Sie sind auf Seite 1von 2

This page contains examples on how to solve the Initial Value Problems (IVPs) and Boundary Value Problems

(BVPs) using numeric and symbolic solvers in MATHEMATICA. 


The examples used in this page are those given in "Fortran Examples" or "Matlab Examples" pages.

 Example 1: Single first-order ODE, IVP.


(* EXAMPLE-1a: single ODE, symbolic solution *)
ode=y'[x]+2*x*y[x]-4*x
DSolve[ode==0,y[x],x]

(* EXAMPLE-1b: single ODE, numerical solution & plot *)


ode=y'[x]+2*x*y[x]-4*x
NDSolve[{ode==0,y[0]==0},y,{x,0,3}]
Plot[Evaluate[y[x] /. %],{x,0,3}, AxesLabel-> {"x","y"}, Frame-
>True, GridLines->Automatic]

 Example 2: Two first-order ODEs, IVP.


(* EXAMPLE-2a: two simultaneous ODEs, symbolic solution *)
ode1=y1'[x]-y2[x]-x
ode2=y2'[x]-y1[x]-1
DSolve[{ode1==0,ode2==0},{y1[x],y2[x]},x]

(* EXAMPLE-2b: two simultaneous ODEs, numerical solution & plot *)


ode1=y1'[x]-y2[x]-x
ode2=y2'[x]-y1[x]-1
NDSolve[{ode1==0, ode2==0, y1[0]==0, y2[0]==0}, {y1,y2}, {x,0,3}]
Plot[Evaluate[y1[x] /. %], {x,0,3}, AxesLabel-> {"x","y1"}, Frame-
>True, GridLines->Automatic]
Plot[Evaluate[y2[x] /. %%], {x,0,3}, AxesLabel-> {"x","y2"},
Frame->True, GridLines->Automatic]

 Example 3: Single third-order ODE (Boundary Layer Past a Flat


Plate), BVP.
(* EXAMPLE-3a: single 3rd order ODE (boundary layer, flat plate),
symbolic solution *)
ode=y'''[x]+y''[x]*y[x]
DSolve[ode==0,y[x],x]

(* EXAMPLE-3b: single 3rd order ODE (boundary layer, flat plate),


numerical solution *)
ode=y'''[x]+y''[x]*y[x]
NDSolve[{ode==0,y[0]==0,y'[0]==0,y''[0]==0.469599},y,{x,0,5}]
Plot[Evaluate[y[x] /. %], {x,0,5}, AxesLabel-> {"x","y"}, Frame-
>True, GridLines->Automatic]
Plot[Evaluate[y'[x] /. %%], {x,0,5}, AxesLabel-> {"x","y'"},
Frame->True, GridLines->Automatic]
Plot[Evaluate[y''[x] /. %%%], {x,0,5}, AxesLabel-> {"x","y''"},
Frame->True, GridLines->Automatic]
 Example 4: Two second-order ODEs, BVP.
(* EXAMPLE-4a: two simultaneous 2nd order ODEs, symbolic solution
*)
ode1=x''[t]-x[t]-2*y[t]-t
ode2=y''[t]-2*y[t]-3*x[t]-1
DSolve[{ode1==0,ode2==0},{y[t],x[t]},t]

(* EXAMPLE-4b: two simultaneous 2nd order ODEs, numerical solution


*)
ode1=x''[t]-x[t]-2*y[t]-t
ode2=y''[t]-2*y[t]-3*x[t]-1
NDSolve[{ode1==0,ode2==0,x[0]==0,y[0]==0,x'[0]==0.5871,y'[0]==0.02
28},{x,y}, {t,0,1}]
Plot[Evaluate[x[t] /. %], {t,0,1}, AxesLabel-> {"t","x"}, Frame-
>True, GridLines->Automatic]
Plot[Evaluate[y[t] /. %%], {t,0,1}, AxesLabel-> {"t","y"}, Frame-
>True, GridLines->Automatic]
Plot[Evaluate[x'[t] /. %%%], {t,0,1}, AxesLabel-> {"t","x'"},
Frame->True, GridLines->Automatic]
Plot[Evaluate[y'[t] /. %%%%], {t,0,1}, AxesLabel-> {"t","y'"},
Frame->True, GridLines->Automatic]

Das könnte Ihnen auch gefallen