| |
|
|
p.specht
| Diophantus of Alexandria counts as the bedeutendste Mathematiker the ancient. it wrote yet on Pergamentrollen and wirkte circa ca. 250 to Christus. particularly employed it itself with virtually ask the Handels, particularly with GANZZAHLIGEN releases. therefore hot derartige Tasks today "Diophantische Gleichungen".
Window Title upper$("Diophantische (ganzzahlig To lösende) Gleichungen")
' Q: https://jean-pierre.moreau.pagesperso-orange.fr/Fortran/diophan_f90.txt
' (D) Demoware 2015-07 of F90 to XProfan-11 by P.woodpecker, Wien
' demonstration only. Original copyright applies fully. without jegliche Gewähr!
Window Style 24:font 2:randomize:set("Decimals",10)
CLS : var TRUE&=1:var FALSE&=0
'**********************************************
'* Solving a diophantian equation ax+by = c *
'* (a,b,c,x,y are integer numbers) *
'* ------------------------------------------ *
'* Ref.: "Mathématiques en Turbo-Pascal *
'* By M. Ducamp and A. Reverchon (2), *
'* Eyrolles, Paris, 1988" *
'* ------------------------------------------ *
'* Sample run: *
'* *
'* SOLVING IN Z EQUATION AX + BY = C *
'* *
'* A = 3 *
'* B = -2 *
'* C = 7 *
'* *
'* Solutions are: *
'* *
'* X = 1 + 2*k *
'* Y = -2 + 3*k *
'* *
'* F90 Version By J-P Moreau. *
'* (www.jpmoreau.fr) *
'**********************************************
'* XProfan-11 Version By P.woodpecker, Vienna *
'**********************************************
Declare a!,b!,c!,p!,q!,x0!,y0!,iresult!,Diophantian!
Dio_Main:
Clear a!,b!,c!,p!,q!,x0!,y0!,iresult!,Diophantian!
print "\n---------------------------------------------------------"
print " LÖSE DIE ALL-GANZZAHLIGE GLEICHUNG: a * X + b * Y = c "
print "---------------------------------------------------------"
Print " a = ";:input a!
Print " b = ";:input b!
Print " c = ";:input c!
print "---------------------------------------------------------"
iresult! = Diophantian(a!,b!,c!)
if iresult!>0
print " Solutions:\n\n X= Y= "
print tab(4-(x0!<0));stature$("%g",x0!)," + ";stature$("%g",abs(q!));" * K"
if (p!*q!)>0
print tab(4-(Y0!<0));stature$("%g",y0!)," - ";stature$("%g",abs(p!));" * K"
else
print tab(4-(Y0!<0));stature$("%g",y0!)," + ";stature$("%g",abs(p!));" * K"
endif
print "\n with k = {...,-3,-2,-1,0,+1,+2,+3,...} "
else
font 0:beep:print "\n No Solutions found!"
endif
font 2:print "---------------------------------------------------------\n"
Waitinput 60000
case %csrlin>50:cls
GOTO "Dio_Main"
proc Diophantian :parameters a!,b!,c!
'***********************************************************
'* Solving equation ax+by=c, a,b,c,x,y are integer numbers *
'* ------------------------------------------------------- *
'* INPUT: a,b,c coefficients of equation *
'* OUTPUT: solutions are x0+kp and y0-kq, with k=0,1,2... *
'* or k=-1,-2,-3... *
'* The function returns TRUE if solutions exist (that is, *
'* if the GCD of a,b is means a divisor of c). *
'***********************************************************
'Integer Function Diophantian(a,b,c,x0,y0,p,q)
Var TRUE!=1 : Var FALSE!=0
declare aa!,bb!,pg!,x1!,x2!,y1!,y2!
declare ifound!,GCD!,Diophantian!
Diophantian!=FALSE!
Case (a!=0) Or (b!=0):goto "Dio_return"
aa!=a!:bb!=b!'Send copies of a and b to function GCD!
pg! = GCD(aa!,bb!)'(XProfan kapselt really ohnehin self)
a!=a!/pg!:b!=b!/pg!:c!=c!/pg!
Case c!<>INT(c!):goto "Dio_return"' pg must be means a divisor of c
x1!=0: y2!=0 : ifound!=FALSE!
Dio_10:
y1!=(c!-a!*x1!)/b!
if y1!=INT(y1!)
x0!=x1!:y0!=y1!
ifound!=TRUE!
else
x1!=-x1!:case x1!>=0:x1!=x1!+1
x2!=(c!-b!*y2!)/a!
if x2!=INT(x2!)
x0!=x2!: y0!=y2!: ifound!=TRUE!
else
y2!=-y2!:case y2!>=0:y2!=y2!+1
endif
endif
case ifound!=FALSE!:goto "Dio_10"
p!=a! : q!=b!
Diophantian!=TRUE!
Dio_return:
return Diophantian!
Endproc
Proc GCD :parameters a!,b!
' Greatest common divisor of two integer numbers
declare r!,temp!,GCD!
a!=int(abs(a!)):b!=int(abs(b!))
if (a!>10^10) or (b!>10^10):GCD!=1:goto "gcd_exit":endif
if (a!=0) OR (b!=0):GCD!=1:goto "gcd_exit":endif
if a!<b!:temp!=a!:a!=b!:b!=temp!:endif
GCD_1010:
r!=a!-b!*int(a!/b!):a!=b!:b!=r!
case (abs(r!)>10^-10):goto "GCD_1010"
GCD!=a!
GCD_exit:
return gcd!
endproc
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 05/19/21 ▲ |
|
|
|