Info

This question is closed. Reopen it to edit or answer.

HOW TO CONVERT THE FOLLOWING MAHEMATICA CODE TO MATLAB CODE

1 view (last 30 days)
\!\(\*
RowBox[{\(F[0] = A*η + \((
1 - A)\)*\((1 - Exp[\(-η\)])\) - M\/Pr - α*\(n -
1\)\/\(n + 1\);\), "\[IndentingNewLine]", \(G[
0] = 1 - Exp[\(-η\)];\), "\[IndentingNewLine]", "\
\[IndentingNewLine]", \(M = 2/10;\), "\[IndentingNewLine]", \(n = 2/10;\),
"\[IndentingNewLine]", \(β1 = 1/
10;\), "\[IndentingNewLine]", \(β2 = 1/10;\), \
"\[IndentingNewLine]", \( (*\(A = 1/10;\)*) \), "\[IndentingNewLine]", \(H = \
1/10;\), "\[IndentingNewLine]", \(Pr = 10/10;\), "\[IndentingNewLine]", \(δ = \
\(-1\)/10;\), "\[IndentingNewLine]", \(α = 1/10;\), "\[IndentingNewLine]", \
\(g[0] = G[0];\),
"\[IndentingNewLine]", \(f[0] = F[0];\), "\[IndentingNewLine]",
RowBox[{"For", " ", "[",
RowBox[{\(m = 1\), ",", \(m
≤ 35\), ",", \(m++\), ",", "\[IndentingNewLine]",
RowBox[{\(If[m > 1, chi[m] = 1, chi[
m] = 0]\), ";", "\[IndentingNewLine]",
RowBox[{"rhs1", "=",
RowBox[{"h", "*", \(Exp[\(-η\)]\), "*",
RowBox[{"(",
RowBox[{\((D[F[m - 1], {η, 3}])\), "-",
RowBox[{\((\(2*n\)\/\(n + 1\))\), "*",
RowBox[{"(",
StyleBox[\(∑\+\(k = \ 0\)\%\(m - 1\)\((D[F[m - 1 - k], {
η, 1}]*D[F[k], {η, 1}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}]}],
StyleBox["+",
FontSize->16],
RowBox[{"(",
StyleBox[\(∑\+\(k = \ 0\)\%\(m - 1\)\((D[F[m - 1 - k], {η,
0}]*D[F[k], {η, 2}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}],
StyleBox["+",
FontSize->16], \(β1*\((3*n - 1)\)*\((∑\+\(k =
0\)\%\(m - 1\)\ \((D[F[m - 1 - k], {η, 0}]*\((∑\+\(p =
0\)\%k\ D[F[k - p], {η, 1}]*D[F[p], {
η, 2}])\))\))\)\), "-", \(β1*\(2*n*\((n - 1)\)\)\/\(n \
+ 1\)*\((∑\+\(k = 0\)\%\(m - 1\)\ \((D[F[m - 1 - k], {η, 1}]*\((
∑\+\(p = 0\)\%k\ D[F[k - p], {η, 1}]*D[F[p], {η,
1}])\))\))\)\), "+", \(\((
η + α)\)*β1*\((\(n - 1\)\/2)\)*\((
∑\+\(k = 0\)\%\(m - 1\)\ \((D[F[m -
1 - k], {η, 1}]*\((∑\+\(p = 0\)\%k\ D[F[k - p], {η, 1}]*
D[F[p], {
η, 2}])\))\))\)\), "-
", \(β1*\((\(n + 1\)\/2)\)*\((∑\+\(k = \
0\)\%\(m - 1\)\ \((D[F[m - 1 - k], {η, 0}]*\((∑\+\(p = 0\)\%k\ D[
F[k - p], {η, 0}]*D[F[p], {η, \
3}])\))\))\)\), "-", \(\(2*n*\((n -
1)\)\)\/\(n + 1\)*β1*A^3*\((1 - chi[m])\)\), "+",
RowBox[{"β2", "*", \((\(3*n - 1\)\/2)\), "*",
RowBox[{"(",
StyleBox[\(∑\+\(k = \
0\)\%\(m - 1\)\((D[F[m - 1 - k], {η, 2}]*
D[F[k], {η, 2}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}]}], "-",
RowBox[{"β2", "*", \((\(n + 1\)\/2)\), "*",
RowBox[{"(",
StyleBox[\(∑\+\(k = \ 0\)\%\(m -
1\)\((D[F[m - 1 - k], {η, 0}]*D[F[k], {η, 4}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}]}],
StyleBox["+",
FontSize->16],
RowBox[{"β2", "*", \((n - 1)\), "*",
RowBox[{"(",
StyleBox[\(∑\+\(k = \ 0\)\%\(m -
1\)\((D[F[m - 1 - k], {η, 1}]*D[F[k], {η, 3}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}]}],
StyleBox["+",
FontSize->16],
RowBox[{"β1",
"*", \((\(n - 1\)\/\(n + 1\))\),
"*", "H", "*", \((η + α)\), "*",
RowBox[{"(",
StyleBox[\(∑\+\(k = \ 0\)\%\(m - 1\)\((D[F[m - 1 - k], {
η, 1}]*D[F[k], {η, 2}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}]}],
StyleBox["-",
FontSize->16], \(2\/\(1 + n\)*H*\((D[F[m - 1], {η,
1}])\)\), "+",
RowBox[{"H", "*", "β1", "*",
RowBox[{"(",
StyleBox[\(∑\+\(k = \ 0\)\%\(m - 1\)\((D[F[m - 1 - k], {η,
0}]*D[F[k], {η, 2}])\)\),
FontSize->16],
StyleBox[")",
FontSize->16]}]}],
StyleBox["+",
FontSize->16],
RowBox[{
RowBox[{
StyleBox["(",
FontSize->16],
RowBox[{
StyleBox[
RowBox[{
RowBox[{"(",
FractionBox[
StyleBox[\(2*n\),
FontSize->16], \(1 + n\)], ")
"}], "*", \(A^2\)}],
FontSize->16],
StyleBox["+",
FontSize->16],
RowBox[{
StyleBox["H",
FontSize->16],
StyleBox["*",
FontSize->16],
RowBox[{
StyleBox["(",
FontSize->16], \(\(2*A\)\/\(1 + n\)\), ")
"}]}]}], ")"}], "*", \((1 - chi[m])\)}]}],
StyleBox[")",
FontSize->16]}]}]}], ";",
StyleBox[\(rhs2 = h*Exp[\(-η\)]*\((D[G[m -
1], {η, 2}] + Pr*\((\((∑\+\(k = \ 0\)\%\(m - 1\)\((F[
m - 1 - k]*D[G[k], {η, 1}])\))\) + \(2*δ\)\/\(n + 1\)*G[m -
1])\))\)\),
FontSize->16],
StyleBox[";",
FontSize->16], "\[IndentingNewLine]",
StyleBox["\[IndentingNewLine]",
FontSize->16], \(w1 = DSolve[\(y'''\)[η] - \(y'\)[η] == rhs1,
y[η], η]\), ";",
"\[IndentingNewLine]", \(w2 = DSolve[\(y''\)[
η] - y[η] == rhs2, y[η], η]\),
";", "\[IndentingNewLine]",
"\[IndentingNewLine]", \(a = Expand[w1[\([1, 1, \
2]\)]] /. C[_] -> 0\), ";", "\[IndentingNewLine]", \(d = Expand[w2[\([1,
1, 2]\)]] /. C[_] -> 0\), ";", "\[IndentingNewLine]",
"\[IndentingNewLine]", \(a2 = D[a, η] /. η -> 0\), ";",
"\[IndentingNewLine]", \(d1 = \(-d\) /. η ->
0\), ";", "\[IndentingNewLine]", "\[IndentingNewLine]", \(l1 = \(-
l\) /. η -> 0\), ";", "\[IndentingNewLine]", \(a3 = a /. η ->
0\), ";", "\[IndentingNewLine]", \(d2 = D[d, η] /. η -> 0\),
";", "\[IndentingNewLine]", \(a1 = \(-a2\) - a3 - M\/Pr*\((\(-
d1\) + d2)\)\),
";", "\[IndentingNewLine]", \(F[m] = a + a2*Exp[\(-η\)] + a1 +
chi[m]*F[m - 1]\), ";", "\[IndentingNewLine]", \(G[
m] = d + d1*Exp[\(-η\)] + chi[m]*G[m - 1]\), ";",
"\[IndentingNewLine]", "\[IndentingNewLine]", \(f[m] = F[m] +
f[m - 1]\), ";", "\[IndentingNewLine]", \(g[m] = G[
m] + g[m - 1]\), ";", "\[IndentingNewLine]",
"\[IndentingNewLine]", "\[IndentingNewLine]", \(u1 = D[f[
m], {η, 1}]\), ";", "\n", " ", \(u2 = g[m]\), ";",
"\[IndentingNewLine]", "\[IndentingNewLine]",
RowBox[{"Print", "[",
StyleBox[\("\<F =\>", u1\),
FontSize->18],
StyleBox["]",
FontSize->18]}],
StyleBox[";",
FontSize->18], "\[IndentingNewLine]",
StyleBox[\(Print["\<G =\>", u2]\),
FontSize->18],
StyleBox[";",
FontSize->18]}]}],
StyleBox["\[IndentingNewLine]",
FontSize->18], "\[IndentingNewLine]",
StyleBox["]",
FontSize->18]}], "\[IndentingNewLine]", "
Null", "\[IndentingNewLine]", "\[IndentingNewLine]", "Null"}]\)
u11 = Plot[{
u1[η, 0.8, -0.9], u1[η, 0.9, -0.9], u1[η, 1.0, -0.9], u1[η, 1.1, -1],
u1[η, 1.2, -1]}, {η, 0, 7}, PlotRange -> All, FrameLabel -> {
η, "\!\(\*
StyleBox[\"f\",\nFontFamily->\"Times New Roman\",\nFontSize->16,\n
FontSlant->\"Italic\"]\)\!\(\*
StyleBox[\"'\",\nFontFamily->\"Times
New Roman\",\nFontSize->16,\nFontSlant->\"Italic\"]\)\!\(\*
StyleBox[\"(\",\nFontFamily->\"Times New Roman\",\nFontSize->16,\nFontSlant->\
\"Italic\"]\)\!\(\*
StyleBox[\"η\",\nFontFamily->\"Times New Roman\",\nFontSize->16,\nFontSlant->\
\"Italic\"]\)\!\(\*
StyleBox[\")\",\nFontFamily->\"Times New Roman\",\nFontSize->16,\nFontSlant->\
\"Italic\"]\)"}, Frame -> True, ImageSize -> {350, 390}, AspectRatio -> \
Full];
Show[{u11}, PlotRange -> All]
Null
  1 Comment
Geoff Hayes
Geoff Hayes on 20 Feb 2019
Minati - well, what does the above code do? What have you tried so far? I think that it will be challenging for you to find someone to translate all that code for you...especially when you haven't attempted anything yourself.

Answers (0)

This question is closed.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!