Здравствуйте.
Товарищи, помогите пожалуйста разобраться, как можно реализовать вот такую задачу в системе Mathematica
Основная сложность заключается в том, что я слабо представляю, как можно здесь работать с
и как можно построить систему, из заданного нам равенства...
Код:
CoeffMat[a0_, b0_, \[Alpha]0_, \[Beta]0_, n_] :=
Module[{a = a0, b = b0, \[Alpha] = \[Alpha]0, \[Beta] = \[Beta]0, h,
j},
h = (b - a)/n;
Vx = Table[ a + h j, {j, n - 1} ];
Va = Vc = Table[ 0, {n - 2} ];
Vd = Vb = Table[ 0, {n - 1} ];
For[ j = 1, j <= n - 1, j++,
Vd[[j]] = 2 + h^2 q[Vx[[j]]];
Vb[[j]] = - h^2 r[Vx[[j]]]; ];
Vb[[1]] = Vb[[1]] + (1 + 1/2 h p[Vx[[1]]]) \[Alpha];
Vb[[n - 1]] = Vb[[n - 1]] + (1 - 1/2 h p[Vx[[n - 1]]]) \[Beta];
For[ j = 1, j <= n - 2, j++,
Va[[j]] = -1 - 1/2 h p[Vx[[j + 1]]];
Vc[[j]] = -1 + 1/2 h p[Vx[[j]]]; ]; ]
(************************************************************)
TriMat[va_, vd_, vc_, vb_, n_] :=
Module[{a = va, b = vb, c = vc, d = vd, k, u},
u = Table[0, {n - 1}];
For[ k = 2, k <= n - 1, k++,
d[[k]] = d[[k]] - a[[k - 1]]/d[[k - 1]] c[[k - 1]];
b[[k]] = b[[k]] - a[[k - 1]]/d[[k - 1]] b[[k - 1]]; ];
u[[n - 1]] = b[[n - 1]]/d[[n - 1]];
For[ k = n - 2, 1 <= k, k--,
u[[k]] = (b[[k]] - c[[k]] u[[k + 1]])/d[[k]] ];
Return[u]; ]
(*************************************************************)
FineDDE[a0_, b0_, \[Alpha]0_, \[Beta]0_, n_] :=
Module[{a = a0, b = b0, \[Alpha] = \[Alpha]0, \[Beta] = \[Beta]0, i},
CoeffMat[a, b, \[Alpha], \[Beta], n];
Xt = TriMat[Va, Vd, Vc, Vb, n];
pts = Transpose[{Vx, Xt}];
pts = Append[pts, {b, \[Beta]}];
pts = Prepend[pts, {a, \[Alpha]}];
Return[pts]; ]
(****************************************************************)
(****************************************************************)
(****************************************************************)
p[x_] = -1/x;
q[x_] = 1 + 1/x;
r[x_] = (2/x)*Exp[x];
a = 1.0;
b = Exp[1];
\[Alpha] = 0;
\[Beta] = Exp[Exp[1]];
Print["Vamos solucar o D.E.:"]
Print["-u'' + (", p[x], ")u' +(", q[x], ")u = ", -r[x]];
Print["com u(", a, ") = \[Alpha] = ", \[Alpha]];
Print["e u(", b, ") = \[Beta] = ", \[Beta]];
Print["e intevalo x em [", a, ",", b, "]"];
(*********************************************************************)
CoeffMat[1.0, Exp[1], 0.0, Exp[Exp[1]], 50]
Print["\n", "Vx = ", Vx];
Print["\n", "Va = ", Va];
Print["\n", "Vc = ", Vc];
Print["\n", "Vd = ", Vd];
Print["\n", "Vb = ", Vb];
Xt = TriMat[Va, Vd, Vc, Vb, 50];
Print["\n", "Vx = ", Vx];
Print["\n", "Xt = ", Xt];
wi = Xt;
wi = Append[wi, 0];
wi = Prepend[wi, 1];
pts = Transpose[{Vx, Xt}];
Print["\n", "pontos = ", pts];
pts = Append[pts, {1, 0}];
Print["\n", "pontos com boundory direita: ", pts];
pts = Prepend[pts, {0, 1}];
Print["\n", "pontos com boundorry esqueda : ", pts];
pontos4 = FineDDE[1.0, Exp[1], 0.0, Exp[Exp[1]], 50];
Print[""]
Print["Grafico de pontos calculados de metodo das diferenças finitas:"]
Print[ListLinePlot[pontos4, PlotRange -> {{-5, 5.1}, {-5, 5.1}},
AxesLabel -> {"x", "u"}]]
Print["grafico de função exacta -u'' -(1/x) * u = -(2/x) e^{x}:"]
(*Print[Plot[(1-x)*Exp[x],{x,0,1}]]*)
Print["u(", a, ") = ", \[Alpha]];
Print["u(", b, ") = ", \[Beta]];