Question: MAJOR problem with precision in MAPLE do loops

Dear Maple Specialists,

I deal with a major MAPLE problem the last months of my PhD.

PROBLEM:
My programm contains a do loop which calculates for given PsiS (purple color) and for a range of Psi1 and Psi2 (blue color) from PsiS to 0, values for the products Qsu1, Qsu2, Qtot .
The aim to calculate w(RLZ) which is obtained when the blue color loop is completed and Psi2 takes the final value 0.

w(RLZ) depends from Qtot, Qsu1, Qsu2

Qsu1, Qsu2, Qtot are calculated when Psi2 =0 in such a way that always Qtot >= Qsu1, Qsu2.
For PsiS=0.1, Psi1=0.01 and Psi2=0 we get  (included calculation)

Qtot = 1.297046409*10^22,
Qsu1 = 1.271370424*10^22
Qsu2 = 1.297046402*10^22

while it is obvious Qtot>Qsu2 MAPLE calculates the  difference between then DeltaQ2=Qtot-Qsu2 as NEGATIVE and of the order of 1014!!!!!!! (DeltaQ2=-4.27e14!!!!!!!!!!)

I conducted the same calculation seperately (see below: seperate calculation) i.e. without do loops and i noticed that the same calculation when is done without loops delivers different values for the IDS,ID1,ID2,IAS,IA1,IA2,ITS,IT1,IT2 and subsequently different values for the sums Qtot, Qsu1, Qsu2 (comparison of the values is found in attached maple sheets)

At the end the differnce DeltaQ2 is correctly calculated by the seperate calculation while my programm -no matter what i tried- calculates Delta Q2 as negative (DeltaQ2 =-4.27e14 !!!!!!!!!) and in any case the Programm calculates different values for all the with red color highlighted elements.

Why maple calculates differently things in the do loop than in the seperate calculation???????
How can i optimise my already written programm to calculate things exactly like the seperate calculation? (My boss proposed mathematica but i dont want to quit MAPLE after one °!"§$%&/ year of good work with it neither learn to use another mathematical software)

I include the programm and the seperate calculation in order to demonstrate precicly my problem.

The elements of the programm and the seperate calculation marked RED are unterlying that there is a disagreement between the two calculation ways (Programm/seperate calculation)
The GREEN elements are calculated correctly from both calculation ways (programm/ seperate calculation)

Thanx in advance for your help

Thanos Tsirimpis

Universität Erlangen Nürnberg @ Angewandte Physik
-----------------------------------------------------------------

PROGRAMM

restart

T := 298:

d := 0.4e-3:

0.1256637062e-6

(1)

NC := evalf(0.3e22*T^(3/2));

0.1543283279e26

 

0.1671890219e26

(2)

PsiST := ImportMatrix(

Matrix(%id = 171061860)

(3)

PsiS := PsiST[1, 1];

.1

 

0.3e-1

(4)

Psi1 := 0.1e-1;

0.1e-1

 

0.

(5)

wiC := Einb/(k*T)-ECB/(k*T);

-63.76700127

 

-63.84704403

 

1.430221351

 

1.330221351

 

1.420221351

 

1.430221351

 

1.400221351

 

51.75455116

 

55.64522327

 

55.25615606

 

55.64522327

 

54.47802164

 

-61.04353077

 

-56.06569980

 

2.37442463

(6)

FD32 := ImportMatrix(

Matrix(%id = 150549700)

(7)

for i to 9001 do if `or`(FD32[i, 1] < wiC+uB and wiC+uB < FD32[i+1, 1], FD32[i, 1] = wiC+uB) then iFD32Cb := i else FAIL end if end do;

FD32Cb := FD32[iFD32Cb, 2]+(wiC+uB-FD32[iFD32Cb, 1])*(FD32[iFD32Cb+1, 2]-FD32[iFD32Cb, 2])/(FD32[iFD32Cb+1, 1]-FD32[iFD32Cb, 1]);

0.2972328603e-3

(8)

NULL

for i to 10001 do if `or`(FD32[i, 1] < wiC+uS and wiC+uS < FD32[i+1, 1], FD32[i, 1] = wiC+uS) then iFD32Cs := i else FAIL end if; if `or`(FD32[i, 1] < wiC+uS and wiC+uS < FD32[i+1, 1], FD32[i, 1] = wiC+uS) then break end if end do:

0.6071414207e-5

(9)

for i to 10001 do if `or`(FD32[i, 1] < wiC+u1 and wiC+u1 < FD32[i+1, 1], FD32[i, 1] = wiC+u1) then iFD32C1 := i else FAIL end if; if `or`(FD32[i, 1] < wiC+u1 and wiC+u1 < FD32[i+1, 1], FD32[i, 1] = wiC+u1) then break end if end do:

0.2013612589e-3

 

0.2972328603e-3

(10)

IAs := NA*(uB-uS+ln(1/(1+gA*exp(wAi-uS))+gA*exp(wAi-uB)/(1+gA*exp(wAi-uS))));

0.1945336055e22

 

0.1940924598e23

 

0.

(11)

ID1 := ND*(u1-uS+ln(1/(1+gD*exp(u1+wiD))+gD*exp(uS+wiD)/(1+gD*exp(u1+wiD)))); IA1 := NA*(u1-uS+ln(1/(1+gA*exp(wAi-uS))+gA*exp(wAi-u1)/(1+gA*exp(wAi-uS)))); IT1 := piecewise(Psi1 > PsiTf, NT*(u1-uS+ln(1/(1+gD*exp(u1+wiT))+gD*exp(uS+wiT)/(1+gD*exp(u1+wiT)))), Psi1 <= PsiTf, NT*(uT-uS+ln(1/(1+gD*exp(uT+wiT))+gD*exp(uS+wiT)/(1+gD*exp(uT+wiT)))))

0.1747838220e23

 

0.1750802450e22

 

0.

(12)

ID2 := ND*(u2-uS+ln(1/(1+gD*exp(u2+wiD))+gD*exp(uS+wiD)/(1+gD*exp(u2+wiD)))); IA2 := NA*(u2-uS+ln(1/(1+gA*exp(wAi-uS))+gA*exp(wAi-u2)/(1+gA*exp(wAi-uS)))); IT2 := piecewise(Psi2 > PsiTf, NT*(u2-uS+ln(1/(1+gD*exp(u2+wiT))+gD*exp(uS+wiT)/(1+gD*exp(u2+wiT)))), Psi2 <= PsiTf, NT*(uT-uS+ln(1/(1+gD*exp(uT+wiT))+gD*exp(uS+wiT)/(1+gD*exp(uT+wiT)))))

0.1940924598e23

 

0.1945336055e22

 

0.

(13)

Qsu1 := evalf(ID1+IT1-IA1-NC*(FD32C1-FD32Cs));

0.1271370423e23

 

0.1297046401e23

 

0.1297046401e23

 

0.

(14)

NULL

NULL

invFu1 := sqrt(1/(2*k*T*(Qtot-Qsu1)/(eps4H*epsilon0))):

`ΔwRLZ` := 0.5e-2*SinvFu;

0.3197719593e-7

(15)

NULL

NULL

NULL

NULL

NULL

NULL

NULL


SEPERATE CALCULATION

Download Seperate_Calculatio.mw

restart

T := 298:

d := 0.2e-3:

0.3141592655e-7

(1)

NC := evalf(0.3e22*T^(3/2)):

``

wiC := Einb/(k*T)-ECB/(k*T); wVi := EVB/(k*T)-Einb/(k*T); `Φb` := EF/q-Einb/q; uB := q*`Φb`/(k*T); Psi2 := Psi1-0.1e-1; wiD := Einb/(k*T)-ED/(k*T); wAi := EA/(k*T)-Einb/(k*T); wiT := Einb/(k*T)-ET/(k*T); `Φs` := EF/q-Einb/q-PsiS; Phi1 := EF/q-Einb/q-Psi1; Phi2 := EF/q-Einb/q-Psi2; `ΦT` := EF/q-Einb/q-PsiTf; uS := q*`Φs`/(k*T); u1 := q*Phi1/(k*T); u2 := q*Phi2/(k*T); uT := q*`ΦT`/(k*T)

FD32 := ImportMatrix(

Matrix(%id = 152287568)

(2)

for i to 9001 do if `or`(FD32[i, 1] < wiC+uB and wiC+uB < FD32[i+1, 1], FD32[i, 1] = wiC+uB) then iFD32Cb := i else FAIL end if end do;

FD32Cb := FD32[iFD32Cb, 2]+(wiC+uB-FD32[iFD32Cb, 1])*(FD32[iFD32Cb+1, 2]-FD32[iFD32Cb, 2])/(FD32[iFD32Cb+1, 1]-FD32[iFD32Cb, 1]);

0.2972328603e-3

(3)

IDs := evalf(ND*(uB-uS+ln(1/(1+gD*exp(uB+wiD))+gD*exp(uS+wiD)/(1+gD*exp(uB+wiD))))):

ID1 := evalf(ND*(u1-uS+ln(1/(1+gD*exp(u1+wiD))+gD*exp(uS+wiD)/(1+gD*exp(u1+wiD))))); IA1 := evalf(NA*(u1-uS+ln(1/(1+gA*exp(wAi-uS))+gA*exp(wAi-u1)/(1+gA*exp(wAi-uS))))); IT1 := evalf(piecewise(Psi1 > PsiTf, NT*(u1-uS+ln(1/(1+gD*exp(u1+wiT))+gD*exp(uS+wiT)/(1+gD*exp(u1+wiT)))), Psi1 <= PsiTf, NT*(uT-uS+ln(1/(1+gD*exp(uT+wiT))+gD*exp(uS+wiT)/(1+gD*exp(uT+wiT))))))

ID2 := evalf(ND*(u2-uS+ln(1/(1+gD*exp(u2+wiD))+gD*exp(uS+wiD)/(1+gD*exp(u2+wiD))))); IA2 := evalf(NA*(u2-uS+ln(1/(1+gA*exp(wAi-uS))+gA*exp(wAi-u2)/(1+gA*exp(wAi-uS))))); IT2 := evalf(piecewise(Psi2 > PsiTf, NT*(u2-uS+ln(1/(1+gD*exp(u2+wiT))+gD*exp(uS+wiT)/(1+gD*exp(u2+wiT)))), Psi2 <= PsiTf, NT*(uT-uS+ln(1/(1+gD*exp(uT+wiT))+gD*exp(uS+wiT)/(1+gD*exp(uT+wiT))))))

Qsu1 := ID1+IT1-IA1-NC*(FD32C1-FD32Cs); Qsu2 := ID2+IT2-IA2-NC*(FD32C2-FD32Cs); Qtot := IDs+ITs-IAs-NC*(FD32Cb-FD32Cs); `ΔQ2` := Qtot-Qsu2

Cs := 0.1e13*A*eps4H*epsilon0/RLZ:

PsiST := ImportMatrix(

Matrix(%id = 168826932)

(4)

invFu1 := sqrt(1/(2*k*T*(Qtot-Qsu1)/(eps4H*epsilon0))):

``

fdi := open(

0

(5)

for z to 1 do PsiS := PsiST[z, 1]; PsiTf := PsiST[z, 2]; for i to 10001 do if `or`(FD32[i, 1] < wiC+uS and wiC+uS < FD32[i+1, 1], FD32[i, 1] = wiC+uS) then iFD32Cs := i else FAIL end if; if `or`(FD32[i, 1] < wiC+uS and wiC+uS < FD32[i+1, 1], FD32[i, 1] = wiC+uS) then break end if end do; FD32Cs := FD32[iFD32Cs, 2]+(wiC+uS-FD32[iFD32Cs, 1])*(FD32[iFD32Cs+1, 2]/(FD32[iFD32Cs+1, 1]-FD32[iFD32Cs, 1])-FD32[iFD32Cs, 2]/(FD32[iFD32Cs+1, 1]-FD32[iFD32Cs, 1])); Tiefe := 0; for Psi1 from PsiS by -0.1e-1 to 0.1e-1 while Psi2 >= 0 do for i to 10001 do if `or`(FD32[i, 1] < wiC+u1 and wiC+u1 < FD32[i+1, 1], FD32[i, 1] = wiC+u1) then iFD32C1 := i else FAIL end if; if `or`(FD32[i, 1] < wiC+u1 and wiC+u1 < FD32[i+1, 1], FD32[i, 1] = wiC+u1) then break end if end do; FD32C1 := FD32[iFD32C1, 2]+(wiC+u1-FD32[iFD32C1, 1])*(FD32[iFD32C1+1, 2]/(FD32[iFD32C1+1, 1]-FD32[iFD32C1, 1])-FD32[iFD32C1, 2]/(FD32[iFD32C1+1, 1]-FD32[iFD32C1, 1])); for i to 9001 do if `or`(FD32[i, 1] < wiC+u2 and wiC+u2 < FD32[i+1, 1], FD32[i, 1] = wiC+u2) then iFD32C2 := i else FAIL end if; if `or`(FD32[i, 1] < wiC+u2 and wiC+u2 < FD32[i+1, 1], FD32[i, 1] = wiC+u2) then break end if end do; FD32C2 := FD32[iFD32C2, 2]+(wiC+u2-FD32[iFD32C2, 1])*(FD32[iFD32C2+1, 2]/(FD32[iFD32C2+1, 1]-FD32[iFD32C2, 1])-FD32[iFD32C2, 2]/(FD32[iFD32C2+1, 1]-FD32[iFD32C2, 1])); if Psi2 = 0 then invFu2 := 0 else FAIL end if; Tiefe := evalf(Tiefe+0.5e-2*SinvFu); if Psi2 = 0 then RLZ := Tiefe else FAIL end if; if Psi2 = 0 then print(ERFOLG, PQtot = evalf(Qtot), PQsu1 = evalf(Qsu1), PQsu2 = evalf(Qsu2), `PΔQ2` = evalf(`ΔQ2`)) else FAIL end if; if Psi2 = 0 then `and`(print(ERFOLG, `Ψs` = PsiS, `Ψi1` = Psi1, `Ψi2` = Psi2, wRLZ = evalf(Tiefe), C = evalf(Cs)), fprintf(fdi,

ERFOLG, PQtot = 0.1297046409e23, PQsu1 = 0.1271370424e23, PQsu2 = 0.1297046402e23, `PΔQ2` = -0.427e15

 

ERFOLG, `Ψs` = .1, `Ψi1` = 0.1e-1, `Ψi2` = 0., wRLZ = 0.2005595218e-6+0.2479647448e-4*I, C = 0.8850706929e-3-.1094270302*I

 

0

(6)

Psi1 := 0.1e-1; -1; Psi2 := 0

0

(7)

wiC := Einb/(k*T)-ECB/(k*T);

-63.76700127

 

-63.84704403

 

1.430221351

 

1.330221351

 

1.420221351

 

1.430221351

 

1.400221351

 

51.75455116

 

55.64522327

 

55.25615606

 

55.64522327

 

54.47802164

 

-61.04353077

 

-56.06569980

 

2.37442463

(8)

IDs;

0.1940924600e23

 

0.1747838221e23

 

0.1940924599e23

(9)

IAs;

0.1945336057e22

 

0.1750802451e22

 

0.1945336056e22

(10)

ITs;

0.

 

0.

 

0.

(11)

Qtot;

0.1297046409e23

(12)

Qsu1;

0.1271370424e23

(13)

Qsu2;

0.1297046402e23

(14)

``

 

Download Program.mw

PROGRAM


Please Wait...