## 140 Reputation

7 years, 321 days

## How to handle tolerance with eval...

Maple 2016

I tried running the following codes but got error

restart;
Digits := 30:

f1 := proc(n)
lamda * y1[n] + (y2[n])^2;
end proc:

f2 := proc(n)
-y2[n];
end proc:

F1 := proc(n)
lamda * f1(n) + 2 * f2(n) * y2[n];
end proc:

F2 := proc(n)
-f2(n);
end proc:

e1 := y1[n+2] = (53/485) * y1[n] - (6/485) * F1(n+2) * h^2 + (6/485) * f1(n) * h +
(128/485) * f1(n+1/2) * h + (384/485) * f1(n+3/2) * h +
(432/485) * f1(n+1) * h + (20/97) * f1(n+2) * h +
(432/485) * y1[n+1] + (512/485) * y1[n+1/2] - (512/485) * y1[n+3/2]:

e2 := h^2 * F1(n+1/2) = -(9/970) * F1(n+2) * h^2 + (503/1940) * f1(n) * h -
(9412/1455) * f1(n+1/2) * h - (682/485) * f1(n+3/2) * h -
(4041/485) * f1(n+1) * h + (83/1164) * f1(n+2) * h +
(3878/1455) * y1[n] + (9054/485) * y1[n+1] -
(14166/485) * y1[n+1/2] + (11458/1455) * y1[n+3/2]:

e3 := h^2 * F1(n+1) = -(28/4365) * F1(n+2) * h^2 + (541/8730) * f1(n) * h +
(25072/13095) * f1(n+1/2) * h - (5968/4365) * f1(n+3/2) * h +
(224/485) * f1(n+1) * h + (269/5238) * f1(n+2) * h +
(7532/13095) * y1[n] - (9476/485) * y1[n+1] +
(4864/485) * y1[n+1/2] + (116992/13095) * y1[n+3/2]:

e4 := h^2 * F1(n+3/2) = -(31/970) * F1(n+2) * h^2 + (671/5820) * f1(n) * h +
(3902/1455) * f1(n+1/2) * h + (12676/1455) * f1(n+3/2) * h +
(5481/485) * f1(n+1) * h + (329/1164) * f1(n+2) * h +
(1502/1455) * y1[n] + (9846/485) * y1[n+1] +
(5526/485) * y1[n+1/2] - (47618/1455) * y1[n+3/2]:

e5 := y2[n+2] = (53/485) * y2[n] - (6/485) * F2(n+2) * h^2 + (6/485) * f2(n) * h +
(128/485) * f2(n+1/2) * h + (384/485) * f2(n+3/2) * h +
(432/485) * f2(n+1) * h + (20/97) * f2(n+2) * h +
(432/485) * y2[n+1] + (512/485) * y2[n+1/2] - (512/485) * y2[n+3/2]:

e6 := h^2 * F2(n+1/2) = -(9/970) * F2(n+2) * h^2 + (503/1940) * f2(n) * h -
(9412/1455) * f2(n+1/2) * h - (682/485) * f2(n+3/2) * h -
(4041/485) * f2(n+1) * h + (83/1164) * f2(n+2) * h +
(3878/1455) * y2[n] + (9054/485) * y2[n+1] -
(14166/485) * y2[n+1/2] + (11458/1455) * y2[n+3/2]:

e7 := h^2 * F2(n+1) = -(28/4365) * F2(n+2) * h^2 + (541/8730) * f2(n) * h +
(25072/13095) * f2(n+1/2) * h - (5968/4365) * f2(n+3/2) * h +
(224/485) * f2(n+1) * h + (269/5238) * f2(n+2) * h +
(7532/13095) * y2[n] - (9476/485) * y2[n+1] +
(4864/485) * y2[n+1/2] + (116992/13095) * y2[n+3/2]:

e8 := h^2 * F2(n+3/2) = -(31/970) * F2(n+2) * h^2 + (671/5820) * f2(n) * h +
(3902/1455) * f2(n+1/2) * h + (12676/1455) * f2(n+3/2) * h +
(5481/485) * f2(n+1) * h + (329/1164) * f2(n+2) * h +
(1502/1455) * y2[n] + (9846/485) * y2[n+1] +
(5526/485) * y2[n+1/2] - (47618/1455) * y2[n+3/2]:

Digits := 30: lamda := 10000:
h := 0.1:
N := solve(h*p = 10/4, p):
n := 0:
exy1 := [seq](eval(-exp(-2*i/2)/(lamda+2)), i = h .. N, h):
exy2 := [seq](eval(exp(-i/2)), i = h .. N, h):

iny1 := 1:
iny2 := 1:

c := 1:
vars := y1[n+1/2], y1[n+1], y1[n+3/2], y1[n+2], y2[n+1/2], y2[n+1], y2[n+3/2], y2[n+2]:

printf("%6s%15s%15s%15s%15s%10s%10s\n",
"h", "numy1", "numy2",
"exy1", "exy2",
"erry1", "erry2");

tolerance := 1e-6:
st := time():
for k from 1 to N do

res := eval(<vars>, fsolve(eval({e||(1..8)}, [y1[n]=iny1, y2[n]=iny2]), {vars}), tolerance = tolerance):

for i from 1 to 4 do
printf("%6.5f%15.10f%15.10f%15.8g%15.10g%10.3g%10.3g\n",
h*c, res[i], res[i+4],
exy1[c], exy2[c],
abs(res[i]-exy1[c]), abs(res[i+4]-exy2[c])):

c := c+1:
end do:
iny1 := res[4]:
iny2 := res[8]:
end do:
v := time() - st:

## How do I modify the code for initial val...

Maple 2016

Dear all,

Please I want to solve the following boundary value problem numerically with the attached code

y''=((y')^2+y^2)/(2*exp(x)),      0<x<1

with boundary conditions as follows

y(0)-y'(0)=0, y(1)+y'(1)=2*exp(1)

The exact solution is y(x)=exp(x).

How do I modify the code to be able to handle it?

Please the delta in the code represents y'.

Thank you for your time and best regards

restart;
 >
e1:=y[n+2] = (1/12)*h^2*f(n)+(5/6)*h^2*f(n+1)+(1/12)*h^2*f(n+2)+2*y[n+1]-y[n]:
 >
 >
 >

h          Num.y          Num.z            Ex.y           Ex.z        Error y        Error z
0.25000      0.702642933  -11.119327426    0.044732488   -9.516563326       0.65791         1.6028
0.50000     -1.480941776    3.706008390   -0.195836551   -1.080050970        1.2851         4.7861
0.75000      2.177304037    3.857405154    1.966274055   -2.618345553       0.21103         6.4758
1.00000     -0.353401232  -12.899134092   -0.541621655  -16.265122833       0.18822          3.366
1.25000      2.205257809   -0.748313267    1.880461001    0.803458961        0.3248         1.5518
1.50000     -0.457853582   -9.260175135    0.888094914  -17.501091793        1.3459         8.2409
1.75000      2.368665639   -0.220734441    0.227799905   -7.823705892        2.1409          7.603
2.00000     -0.556459764  -11.300336415    2.230324739   -5.428300487        2.7868          5.872
2.25000      2.205494666   -0.953807966   -0.582405956  -17.141951993        2.7879         16.188
2.50000     -0.947043873  -11.871777444    1.457323206    3.126163062        2.4044         14.998
2.75000      1.867780693   -1.104185167    0.366014055  -11.889781987        1.5018         10.786
3.00000     -1.448466064  -12.600325627   -0.692660166   -0.858678078       0.75581         11.742
3.25000      1.408438927   -1.076955833    1.243407129    4.765140072       0.16503         5.8421
3.50000     -1.960671678  -12.838644035   -1.682658102   -6.465546461       0.27801         6.3731
3.75000      0.947838606   -0.761420206    0.210882522   14.697480238       0.73696         15.459
4.00000     -2.352223093  -12.652936159   -0.678627396    0.245000716        1.6736         12.898
4.25000      0.596650899   -0.266003839   -1.802692162    9.387643085        2.3993         9.6536
4.50000     -2.528856863  -12.055589881    0.398695396   14.817725265        2.9276         26.873
4.75000      0.441416507    0.296276900   -2.296698552    0.729525901        2.7381        0.43325
5.00000     -2.446901406  -11.201642111   -0.256333100   19.522565217        2.1906         30.724

 >

## Why are the errors in odd positions not ...

Maple 2016

Dear esteem Colleagues,

Please how do I modify the following two files (though similar) to get consistent errors? I am not sure where I made the mistake.

Any modifications would be appreciated.

Thank you all for your time and mentorship. Best regard

Biratu_Mapleprimes.mw

DDE_2_Mapleprime.mw

## How do I modify the first and second cod...

Maple 2016

Dear respected colleagues,

The first "ex 1" and second "non linear" codes were sent to me by a colleague. It would be appreciated if they can be modified to look like the one saved with "K2 Nonlinear_Fang 2009". Thank you all for your time and best regards.

ex1.mw

non_linear.mw

K2_Nonlinear_Fang_2009.mw

## Are there any differences between implic...

Maple 2016

Dear esteem colleagues,

Please I am trying to plot a function using both implicitplot and contourplot. However, I found out that I have two different plots. What are the differences between them and perhaps which is better?

Thank you all for your time and best regards.

 1 2 3 4 5 6 7 Page 1 of 7
﻿