(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 7.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 17074, 553] NotebookOptionsPosition[ 15961, 510] NotebookOutlinePosition[ 16301, 525] CellTagsIndexPosition[ 16258, 522] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell["", "Section"], Cell["\<\ Equation system to solve: a diffusion partial differential equation and an \ ordinary differential equation Note: This is a very much simplified version - in this case the two functions \ u[t,x] and v[t] are not coupled at all, and the equations could be solved \ separately. In the real case they are coupled through boundary conditions.\ \>", "Text", CellChangeTimes->{{3.4396263262297373`*^9, 3.439626335442275*^9}, { 3.439626368084662*^9, 3.439626653815955*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"eq3", "=", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"D", "[", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "x"}], "]"}], ",", "t"}], "]"}], "\[Equal]", RowBox[{"D", "[", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "x"}], "]"}], ",", "x", ",", "x"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"u", "[", RowBox[{"0", ",", "x"}], "]"}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "0"}], "]"}], "\[Equal]", RowBox[{"Sin", "[", "t", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "5"}], "]"}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"D", "[", RowBox[{ RowBox[{"v", "[", "t", "]"}], ",", "t"}], "]"}], "\[Equal]", RowBox[{ RowBox[{"v", "[", "t", "]"}], "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"v", "[", "0", "]"}], "\[Equal]", "0.1"}]}], "}"}]}]], "Input", CellChangeTimes->{{3.4396243848050737`*^9, 3.439624402004895*^9}, { 3.4396244731045218`*^9, 3.439624638744053*^9}, {3.4396247734456043`*^9, 3.439624807220317*^9}, {3.439624841897719*^9, 3.4396248433064003`*^9}, { 3.439624907909479*^9, 3.439624907994878*^9}, {3.439624938694353*^9, 3.4396249730171213`*^9}, {3.439625449503858*^9, 3.439625450001028*^9}}], Cell[BoxData[ FormBox[ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"0", ",", "2"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}]}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0"}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "0"}], ")"}], "\[LongEqual]", RowBox[{"sin", "(", "t", ")"}]}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "5"}], ")"}], "\[LongEqual]", "0"}], ",", RowBox[{ RowBox[{ SuperscriptBox["v", "\[Prime]", MultilineFunction->None], "(", "t", ")"}], "\[LongEqual]", RowBox[{ RowBox[{"v", "(", "t", ")"}], "+", "1"}]}], ",", RowBox[{ RowBox[{"v", "(", "0", ")"}], "\[LongEqual]", "0.1`"}]}], "}"}], TraditionalForm]], "Output", CellChangeTimes->{3.439624974197462*^9, 3.4396254507459507`*^9}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"eq3", "//", "TableForm"}]], "Input", CellChangeTimes->{{3.439624985478775*^9, 3.4396249883679028`*^9}}], Cell[BoxData[ FormBox[ TagBox[ TagBox[GridBox[{ { RowBox[{ RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"0", ",", "2"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}]}]}, { RowBox[{ RowBox[{"u", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0"}]}, { RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "0"}], ")"}], "\[LongEqual]", RowBox[{"sin", "(", "t", ")"}]}]}, { RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "5"}], ")"}], "\[LongEqual]", "0"}]}, { RowBox[{ RowBox[{ SuperscriptBox["v", "\[Prime]", MultilineFunction->None], "(", "t", ")"}], "\[LongEqual]", RowBox[{ RowBox[{"v", "(", "t", ")"}], "+", "1"}]}]}, { RowBox[{ RowBox[{"v", "(", "0", ")"}], "\[LongEqual]", "0.1`"}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.5599999999999999]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], Column], Function[BoxForm`e$, TableForm[BoxForm`e$]]], TraditionalForm]], "Output", CellChangeTimes->{3.439624988891685*^9, 3.439625469173998*^9}] }, Open ]], Cell["Solving this system with NDSolve does not work:", "Text", CellChangeTimes->{{3.439626676227463*^9, 3.4396266928034267`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"sol3", "=", RowBox[{"NDSolve", "[", RowBox[{"eq3", ",", RowBox[{"{", RowBox[{"u", ",", "v"}], "}"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "5"}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.439625013000085*^9, 3.4396250347159433`*^9}}], Cell[BoxData[ FormBox[ RowBox[{"NDSolve", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"0", ",", "2"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}]}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0"}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "0"}], ")"}], "\[LongEqual]", RowBox[{"sin", "(", "t", ")"}]}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "5"}], ")"}], "\[LongEqual]", "0"}], ",", RowBox[{ RowBox[{ SuperscriptBox["v", "\[Prime]", MultilineFunction->None], "(", "t", ")"}], "\[LongEqual]", RowBox[{ RowBox[{"v", "(", "t", ")"}], "+", "1"}]}], ",", RowBox[{ RowBox[{"v", "(", "0", ")"}], "\[LongEqual]", "0.1`"}]}], "}"}], ",", RowBox[{"{", RowBox[{"u", ",", "v"}], "}"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "5"}], "}"}]}], "]"}], TraditionalForm]], "Output", CellChangeTimes->{3.4396250365782337`*^9, 3.4396254710992813`*^9}] }, Open ]], Cell["\<\ Alternatively, if the second variable v is expressed as function of the two \ independent variables, leading to a system of two partial differential \ equations\ \>", "Text", CellChangeTimes->{{3.4396266990282917`*^9, 3.4396267378651047`*^9}, { 3.4396268197774353`*^9, 3.439626840963896*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"eq4", "=", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"D", "[", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "x"}], "]"}], ",", "t"}], "]"}], "\[Equal]", RowBox[{"D", "[", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "x"}], "]"}], ",", "x", ",", "x"}], "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"u", "[", RowBox[{"0", ",", "x"}], "]"}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "0"}], "]"}], "\[Equal]", RowBox[{"Sin", "[", "t", "]"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"u", "[", RowBox[{"t", ",", "5"}], "]"}], "\[Equal]", "0"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"D", "[", RowBox[{ RowBox[{"v", "[", RowBox[{"t", ",", "x"}], "]"}], ",", "t"}], "]"}], "\[Equal]", RowBox[{ RowBox[{"v", "[", RowBox[{"t", ",", "x"}], "]"}], "+", "1"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"v", "[", RowBox[{"0", ",", "x"}], "]"}], "\[Equal]", "0.1"}]}], "}"}]}]], "Input",\ CellChangeTimes->{{3.4396243848050737`*^9, 3.439624402004895*^9}, { 3.4396244731045218`*^9, 3.439624638744053*^9}, {3.4396247734456043`*^9, 3.439624807220317*^9}, {3.439624841897719*^9, 3.4396248433064003`*^9}, { 3.4396251271461477`*^9, 3.4396251272429237`*^9}, {3.439625204593114*^9, 3.4396252707906733`*^9}, {3.439625367691327*^9, 3.439625396090032*^9}}], Cell[BoxData[ FormBox[ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"0", ",", "2"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}]}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0"}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "0"}], ")"}], "\[LongEqual]", RowBox[{"sin", "(", "t", ")"}]}], ",", RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "5"}], ")"}], "\[LongEqual]", "0"}], ",", RowBox[{ RowBox[{ SuperscriptBox["v", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ RowBox[{"v", "(", RowBox[{"t", ",", "x"}], ")"}], "+", "1"}]}], ",", RowBox[{ RowBox[{"v", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0.1`"}]}], "}"}], TraditionalForm]], "Output", CellChangeTimes->{ 3.439625271694332*^9, {3.4396253706756487`*^9, 3.439625397453574*^9}}] }, Open ]], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"eq4", "//", "TableForm"}]], "Input", CellChangeTimes->{{3.439625273951939*^9, 3.439625277936908*^9}}], Cell[BoxData[ FormBox[ TagBox[ TagBox[GridBox[{ { RowBox[{ RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ SuperscriptBox["u", TagBox[ RowBox[{"(", RowBox[{"0", ",", "2"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}]}]}, { RowBox[{ RowBox[{"u", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0"}]}, { RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "0"}], ")"}], "\[LongEqual]", RowBox[{"sin", "(", "t", ")"}]}]}, { RowBox[{ RowBox[{"u", "(", RowBox[{"t", ",", "5"}], ")"}], "\[LongEqual]", "0"}]}, { RowBox[{ RowBox[{ SuperscriptBox["v", TagBox[ RowBox[{"(", RowBox[{"1", ",", "0"}], ")"}], Derivative], MultilineFunction->None], "(", RowBox[{"t", ",", "x"}], ")"}], "\[LongEqual]", RowBox[{ RowBox[{"v", "(", RowBox[{"t", ",", "x"}], ")"}], "+", "1"}]}]}, { RowBox[{ RowBox[{"v", "(", RowBox[{"0", ",", "x"}], ")"}], "\[LongEqual]", "0.1`"}]} }, GridBoxAlignment->{ "Columns" -> {{Left}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.5599999999999999]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], Column], Function[BoxForm`e$, TableForm[BoxForm`e$]]], TraditionalForm]], "Output", CellChangeTimes->{ 3.439625278489254*^9, {3.439625372161067*^9, 3.439625399259295*^9}}] }, Open ]], Cell["In this case NDSolve works fine:", "Text", CellChangeTimes->{{3.439626855577352*^9, 3.439626876001835*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"sol4", "=", RowBox[{"NDSolve", "[", RowBox[{"eq4", ",", RowBox[{"{", RowBox[{"u", ",", "v"}], "}"}], ",", RowBox[{"{", RowBox[{"t", ",", "0", ",", "10"}], "}"}], ",", RowBox[{"{", RowBox[{"x", ",", "0", ",", "5"}], "}"}]}], "]"}]}]], "Input", CellChangeTimes->{{3.4396252950790577`*^9, 3.4396253194876947`*^9}}], Cell[BoxData[ FormBox[ RowBox[{"{", RowBox[{"{", RowBox[{ RowBox[{"u", "\[Rule]", TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.`", "10.`"}, {"0.`", "5.`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], ",", "\<\"<>\"\>"}], "]"}], False, Editable->False]}], ",", RowBox[{"v", "\[Rule]", TagBox[ RowBox[{"InterpolatingFunction", "[", RowBox[{ RowBox[{"(", "\[NoBreak]", GridBox[{ {"0.`", "10.`"}, {"0.`", "5.`"} }, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Baseline}}, "RowsIndexed" -> {}}, GridBoxSpacings->{"Columns" -> { Offset[0.27999999999999997`], { Offset[0.7]}, Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> { Offset[0.2], { Offset[0.4]}, Offset[0.2]}, "RowsIndexed" -> {}}], "\[NoBreak]", ")"}], ",", "\<\"<>\"\>"}], "]"}], False, Editable->False]}]}], "}"}], "}"}], TraditionalForm]], "Output", CellChangeTimes->{ 3.439625321109962*^9, {3.4396253732630463`*^9, 3.4396254005172367`*^9}}] }, Open ]] }, Open ]] }, WindowSize->{640, 750}, WindowMargins->{{12, Automatic}, {Automatic, 24}}, FrontEndVersion->"7.0 for Mac OS X x86 (32-bit) (November 11, 2008)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 19, 0, 67, "Section"], Cell[589, 24, 480, 9, 86, "Text"], Cell[CellGroupData[{ Cell[1094, 37, 1468, 39, 115, "Input"], Cell[2565, 78, 1251, 40, 45, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[3853, 123, 128, 2, 39, "Input"], Cell[3984, 127, 1864, 59, 130, "Output"] }, Open ]], Cell[5863, 189, 131, 1, 26, "Text"], Cell[CellGroupData[{ Cell[6019, 194, 374, 10, 39, "Input"], Cell[6396, 206, 1579, 48, 65, "Output"] }, Open ]], Cell[7990, 257, 305, 6, 41, "Text"], Cell[CellGroupData[{ Cell[8320, 267, 1558, 43, 115, "Input"], Cell[9881, 312, 1448, 48, 45, "Output"] }, Open ]], Cell[CellGroupData[{ Cell[11366, 365, 126, 2, 39, "Input"], Cell[11495, 369, 2082, 67, 130, "Output"] }, Open ]], Cell[13592, 439, 114, 1, 26, "Text"], Cell[CellGroupData[{ Cell[13731, 444, 376, 10, 39, "Input"], Cell[14110, 456, 1823, 50, 58, "Output"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)