Message Boards Message Boards

Homotopy analysis method code help

Posted 15 days ago

I am trying to solve differential equations by using Homotopy analysis method code but am unable, Please, somebody guide me to success. I am new to this forum.

In[358]:= (*Clear all variables*)ClearAll["Global`*"];

(*Load the required packages*)
Get["C:\\BVPh2\\Package\\BVPh2_0.m"];
Get["C:\\Users\\HP\\Documents\\MATHEMATICA program\\HAM11.m"];

(*Define the type and number of equations*)
TypeEQ = 1;
NumEQ = 2;

(*Define the functions and equations*)
f[1, z_, {f_, g_}, Lambda_] := (1 + K) D[f, {z, 4}] - 
   Rey M D[f, {z, 2}] + 2 Rey f D[f, {z, 3}] - K D[g, {z, 2}];
f[2, z_, {f_, g_}, Lambda_] := (1 + K/2) D[g, {z, 2}] - 
   Rey K (2 g - D[f, {z, 2}]) + Rey (2 f D[g, z] - D[f, z] g);

(*Define the boundary conditions*)
NumBC = 6;

BC[1, z_, {f_, g_}] := f /. z -> 0;
BC[2, z_, {f_, g_}] := f /. z -> 1;
BC[3, z_, {f_, g_}] := (D[f, z] - 1) /. z -> 1;
BC[4, z_, {f_, g_}] := D[f, {z, 2}] /. z -> 0;
BC[5, z_, {f_, g_}] := g /. z -> 1;
BC[6, z_, {f_, g_}] := g /. z -> 0;

(*Define the initial guesses and linear operators*)
zL[1] = 0; zR[1] = 1;
zL[2] = 0; zR[2] = 1;

U[1, 0] = (z^3 - z)/2;
U[2, 0] = 0;

L[1, u_] := D[u, {z, 4}];
L[2, u_] := D[u, {z, 2}];

(*Set parameters and solve*)
Rey = M = 2;
K = 1/2;

GetOptiVar[4, {}, {c0[1], c0[2]}];
BVPh[1, 20];

(*Plot the results*)
Plot[{U[1, 20], U[2, 20]}, {z, 0, 1}, AxesLabel -> {"z", ""}, 
 PlotStyle -> {{Thin, Red}, {Dashed, Blue}}, 
 PlotRange -> {{0, 1}, {-0.2, 0.2}}]

ListLogPlot[Table[{2 i, ErrTotal[2*i]}, {i, 1, 10}], Joined -> True, 
 Mesh -> All, PlotRange -> {{2, 20}, {10^(-34), 1}}, 
 AxesLabel -> {"m", "error"}]

%%  ERROR:
During evaluation of In[358]:= Get::noopen: Cannot open C:\BVPh2\Package\BVPh2_0.m.

During evaluation of In[358]:= Get::noopen: Cannot open C:\Users\HP\Documents\MATHEMATICA program\HAM11.m.

Out[382]= \!\(\*
GraphicsBox[{{}, {}},
AspectRatio->0.6180339887498948,
Axes->{True, True},
AxesLabel->{
FormBox[
TagBox["\"z\"", HoldForm], TraditionalForm], 
FormBox[
TagBox["\"\"", HoldForm], TraditionalForm]},
AxesOrigin->{0, 0},
DisplayFunction->Identity,
Frame->{{False, False}, {False, False}},
FrameLabel->{{None, None}, {None, None}},
FrameTicks->{{Automatic, Automatic}, {Automatic, Automatic}},
GridLines->{None, None},
GridLinesStyle->Directive[
GrayLevel[0.5, 0.4]],
ImagePadding->All,
Method->{"DefaultBoundaryStyle" -> Automatic, 
     "DefaultGraphicsInteraction" -> {"Version" -> 1.2, 
       "TrackMousePosition" -> {True, False}, 
       "Effects" -> {"Highlight" -> {"ratio" -> 2}, 
         "HighlightPoint" -> {"ratio" -> 2}, 
         "Droplines" -> {"freeformCursorMode" -> True, 
           "placement" -> {"x" -> "All", "y" -> "None"}}}}, 
     "DefaultMeshStyle" -> AbsolutePointSize[6], 
     "ScalingFunctions" -> None, 
     "CoordinatesToolOptions" -> {"DisplayFunction" -> ({
(Identity[#]& )[
Part[#, 1]], 
(Identity[#]& )[
Part[#, 2]]}& ), "CopiedValueFunction" -> ({
(Identity[#]& )[
Part[#, 1]], 
(Identity[#]& )[
Part[#, 2]]}& )}},
PlotRange->{{0., 1.}, {-0.2, 0.2}},
PlotRangeClipping->True,
PlotRangePadding->{{0, 0}, {0, 0}},
Ticks->{Automatic, Automatic}]\)

Out[383]= \!\(\*
GraphicsBox[{{}, {}, {{}, {}}},
AspectRatio->0.6180339887498948,
Axes->{True, True},
AxesLabel->{
FormBox[
TagBox["\"m\"", HoldForm], TraditionalForm], 
FormBox[
TagBox["\"error\"", HoldForm], TraditionalForm]},
AxesOrigin->{2.0000000000000044`, -78.28789316179738},
DisplayFunction->Identity,
Frame->{{False, False}, {False, False}},
FrameLabel->{{None, None}, {None, None}},
FrameTicks->{{
Charting`ScaledTicks[{Log, Exp}, {Log, Exp}, "Nice", 
       WorkingPrecision -> 15.954589770191003`, RotateLabel -> 0], 
Charting`ScaledFrameTicks[{Log, Exp}]}, {Automatic, Automatic}},
GridLines->{None, None},
GridLinesStyle->Directive[
GrayLevel[0.5, 0.4]],
Method->{"AxisPadding" -> 17.995, "DefaultBoundaryStyle" -> Automatic,
      "DefaultGraphicsInteraction" -> {"Version" -> 1.2, 
       "TrackMousePosition" -> {True, False}, 
       "Effects" -> {"Highlight" -> {"ratio" -> 2}, 
         "HighlightPoint" -> {"ratio" -> 2}, 
         "Droplines" -> {"freeformCursorMode" -> True, 
           "placement" -> {"x" -> "All", "y" -> "None"}}}}, 
     "DefaultMeshStyle" -> AbsolutePointSize[6], "DefaultPlotStyle" -> {
Directive[
RGBColor[0.368417, 0.506779, 0.709798], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.880722, 0.611041, 0.142051], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.560181, 0.691569, 0.194885], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.922526, 0.385626, 0.209179], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.528488, 0.470624, 0.701351], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.772079, 0.431554, 0.102387], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.363898, 0.618501, 0.782349], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[1, 0.75, 0], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.647624, 0.37816, 0.614037], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.571589, 0.586483, 0.], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.915, 0.3325, 0.2125], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.40082222609352647`, 0.5220066643438841, 0.85], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.9728288904374106, 0.621644452187053, 0.07336199581899142], 

AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.736782672705901, 0.358, 0.5030266573755369], 
AbsoluteThickness[1.6]], 
Directive[
RGBColor[0.28026441037696703`, 0.715, 0.4292089322474965], 
AbsoluteThickness[1.6]]}, "DomainPadding" -> 17.995, 
     "PointSizeFunction" -> "SmallPointSize", 
     "RangePadding" -> 44.987500000000004`, 
     "OptimizePlotMarkers" -> True, "OptimizePlotMarkers" -> True, 
     "CoordinatesToolOptions" -> {"DisplayFunction" -> ({
Identity[
Part[#, 1]], 
Exp[
Part[#, 2]]}& ), "CopiedValueFunction" -> ({
Identity[
Part[#, 1]], 
Exp[
Part[#, 2]]}& )}},
PlotRange->{{2., 20.}, {-78.28789316179756, 0.}},
PlotRangeClipping->True,
PlotRangePadding->{{0, 0}, {0, 0}},
Ticks->FrontEndValueCache[{Automatic, 
Charting`ScaledTicks[{Log, Exp}, {Log, Exp}, "Nice", 
       WorkingPrecision -> 15.954589770191003`, 
       RotateLabel -> 0]}, {Automatic, {{-69.07755278982137, 
FormBox[
TemplateBox[{"10", 
RowBox[{"-", "30"}]}, "Superscript", SyntaxForm -> SuperscriptBox], 
         TraditionalForm], {0.01, 0.}}, {-46.051701859880914`, 
FormBox[
TemplateBox[{"10", 
RowBox[{"-", "20"}]}, "Superscript", SyntaxForm -> SuperscriptBox], 
         TraditionalForm], {0.01, 0.}}, {-23.025850929940457`, 
FormBox[
TemplateBox[{"10", 
RowBox[{"-", "10"}]}, "Superscript", SyntaxForm -> SuperscriptBox], 
         TraditionalForm], {0.01, 0.}}, {0., 
FormBox["1", TraditionalForm], {0.01, 0.}}, {-80.5904782547916, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-78.28789316179756, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-75.9853080688035, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-71.38013788281542, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-66.77496769682732, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-64.47238260383328, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-62.16979751083923, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-57.564627324851145`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-55.262042231857095`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-52.95945713886305, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-50.65687204586901, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-43.74911676688687, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-41.44653167389282, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-39.14394658089878, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-34.538776394910684`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-32.23619130191664, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-29.933606208922594`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-27.631021115928547`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-20.72326583694641, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-18.420680743952367`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-16.11809565095832, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-11.512925464970229`, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-9.210340371976182, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-6.907755278982137, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 
        0.}}, {-4.605170185988091, 
FormBox[
TemplateBox[{0, 0}, "Spacer2"], TraditionalForm], {0.005, 0.}}}}]]\)
POSTED BY: Minati Patra

You get error because package BVPh2_0.m is not loaded !

It is very important that you receive this description after loading the package:

Package BVPh.m was successfully loaded from C:\Users\Legion\Documents\BVPh2_0.m !

Last updated by Yin-long Zhao, 00:22, Apr. 26, 2013.

Very strange happen after loading packet and execute code I can't get plot of the solution. Then in file:BVPh.m in:

Default of control parameters

I changed from: ErrReq = 10^(-20) to: ErrReq = 10^(-30);Then it works fine I get Plot and Solution.

Regards M.I

Attachments:
POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract