Schön. Hast du dich schonmal mit der OGL-Funktionalität beschäftigt?
Algorithmen Teil V: Mathe-Wahnsinn & Co
-
p. specht -
17. Juni 2012 um 19:52 -
Geschlossen
-
-
- Gerade eben
- Anzeige
Hallo!
Wenn du gerade an deiner Website arbeitest oder dein aktuelles Hosting überdenkst: Wir betreiben mit NetzLiving eine Hosting-Plattform, die speziell auf Performance, Sicherheit und einfache Verwaltung ausgelegt ist.
- ✔️ Schnelle Ladezeiten (optimiert für WordPress, WoltLab & Co.)
- ✔️ Deutsche Server & DSGVO-konform
- ✔️ Persönlicher Support (kein 0815-Ticket-System)
-
Abt. Augenschinderei 8O nun auch vierdimensional
================================
Schon interessanter - naja, relativ gesehen zum obigen Machwerk jedenfalls...
Mach dass mal in OGL
Code
Alles anzeigenif 0 $MAKE CL endif ' Bildschirmschoner Nr 5043 ' (N) Noware 2012-8 P. Specht Ohne jegliche Gewähr! WindowStyle 64 | 16:Window 0,0-%maxx,%maxy-40 var xm&=%maxx\2:var ym&=(height(%HWnd))\2:Font 2 Randomize:var col&=rnd(8^8):usepen 0,1,16777215 set("decimals",16):var f!=pi()/180 declare x!,y!,z!,w!,a!,b!,c!,d!,sa!,sb!,sc!,ca!,cb!,cc!,sd!,cd! declare p$,p$[],p![], n&,i&,k0&,x0!,y0!,z0!,w0!,u0!,v0!,eye! declare k$,k$[],k&[],m&,j&,k1&,x1!,y1!,z1!,w1!,u1!,v1!,zoom!,cs! ' 4D-Eckpunkte x!,y!,z!,v! ' 0 1 2 3 4 5 6 7 p$= "-1,-1,-1,-1 , -1,-1, 1,-1, -1, 1,-1,-1 , -1, 1, 1,-1 , 1,-1,-1,-1 , 1,-1, 1,-1 , 1, 1,-1,-1 , 1, 1, 1,-1" ' 8 9 10 11 12 13 14 15 p$=p$+", -1,-1,-1,1 , -1,-1, 1,1, -1, 1,-1,1 , -1, 1, 1,1, 1,-1,-1,1 , 1,-1,1,1 , 1, 1,-1, 1, 1, 1, 1,1" ' Kanten Von-Punkt Bis-Punkt ' 0 1 2 3 4 5 6 7 8 9 10 11 k$= "0,1 , 1,3 , 3,2 , 2,0 , 4,5 , 5,7 , 7,6 , 6,4 , 1,5 , 0,4 , 2,6 , 3,7 " ' 12 13 14 15 16 17 18 19 20 21 22 23 k$=k$+", 8,9 , 9,11, 11,10, 10,8, 12,13, 13,15, 15,14, 14,12, 9,13, 8,12, 10,14, 11,15" ' 24 25 26 27 28 29 30 31 k$=k$+", 0,8 , 1,9 , 3,11 , 2,10 , 4,12 , 5,13 , 7,15 , 6,14" p$[]=explode(p$,","):n&=sizeof(p$[]):clear p![] setsize p![],n&:p![]=val(p$[&index]):clear p$[] k$[]=explode(k$,",") :m&=sizeof(k$[]):clear k&[] setsize k&[],m&:k&[]=val(k$[&index]):clear k$[] Declare Bitmap% WHILELOOP 0,360 * 20 ' Umdrehungen Case Bitmap% : DeleteObject Bitmap% Bitmap% = create("hNewPic", %maxx,%maxy,col&) StartPaint Bitmap% TextColor rgb(255,0,0),-1 DrawText 1,1,"Ende ESC" line 0,ym& - 2*xm&,ym&:line xm&,2*ym& - xm&,0 eye!=40 cs!=cos(&Loop*f!) zoom!=5*width(%HWnd)*(cs!*cs!+0.3) a!=f!*&LOOP/2 b!=f!*(10+&LOOP)/2 c!=f!*(20+&LOOP) ' Grad d!=f!*&LOOP ' Für alle Kanten: whileLoop 0,(m&-1)\2 : j&=2*&Loop k0&=4*k&[j&] : k1&=4*k&[j&+1] x!=p![k0&] : y!=p![k0&+1] : z!=p![k0&+2] : w!=p![k0&+3] rotate a!,b!,c!,d! : x0!=x! : y0!=y! : z0!=z! : w0!=w! u0!=zoom!*w0!*x0! / (z0!-eye!) : v0!=zoom!*y0!*w0! / (z0!-eye!) x!=p![k1&] : y!=p![k1&+1] : z!=p![k1&+2] : w!=p![k1&+3] rotate a!,b!,c!,d! : x1!=x! : y1!=y! : z1!=z! : w1!=w! u1!=zoom!*w1!*x1! / (z1!-eye!) : v1!=zoom!*w1!*y1! / (z1!-eye!) usepen 0,10,rgb(240,240,240) line xm&+u0!,(ym&-v0!) - (xm&+u1!),ym&-v1! drawtext xm&+u0!,ym&-v0!,str$(k0&\3) drawtext xm&+u1!,ym&-v1!,str$(k1&\3) endwhile Endpaint DrawPic Bitmap%, 0, 0; 0 WaitInput 1 Case %Key=27:BREAK ENDWHILE DeleteObject Bitmap% WaitInput END proc rotate parameters a!,b!,c!,d! declare xx!,yy!,zz!,ww! sa!=sin(a!):sb!=sin(b!):sc!=sin(c!):sd!=sin(d!) ca!=cos(a!):cb!=cos(b!):cc!=cos(c!):cd!=cos(d!) xx!=x!*ca!+y!*sa! yy!=x!*sa!-y!*ca! zz!=z! ww!=w! x!=xx! y!=yy!*cb!+zz!*sb! z!=yy!*sb! -zz!*cb! w!=ww! xx!=x!*cc!+z!*sc! yy!=y! zz!=x!*sc!-z!*cc! ww!=w! x!=xx! y!=yy! z!=zz!*cos(d!) + ww!*sin(d!) w!=abs(zz!*sin(d!) - ww!*cos(d!)) 'w!=w!*w! endproc -
Abt. HUND IN DER PFANNE

=================
Sieben Jahre glaubte ich, daß Profan kein PEEK und POKE kennt :s18:. Doch heute um 18:04 Uhr und 14 Sekunden kam ich drauf, daß überall wo "Bereichsvariable" im Helpfile steht, in der Regel auch einfach eine Memoryadresse einsetzbar ist. Das ist allerdings nur für einen einzigen Befehl (FLOAT) dokumentiert :abgelehnt:. Naja... :ätsch!:Code
Alles anzeigenWindowTitle "P, Specht´s 7 Jahre verzögertes AHA-Erlebnis" Cls : font 2 : var c$ = "" var MeineVariable%=123456789 var ab! = 12.34 var def! = 56.78 var ghi! = 90.12 print print " Adresssprung Adresse Wert NameAddy Variablenbezeichner" print print " ",addr(MeineVariable%)," ",long(addr(MeineVariable%),0), print long(addr(MeineVariable%)-4,0);tab(56);string$( long(addr(MeineVariable%)-4,0),0 ) print " ",addr(ab!)," ",float(addr(ab!),0), long(addr(ab!),8);tab(56);string$( long(addr(ab!)-4,0),0 ) print "+ ";addr(def!)-addr(ab!)," = ",addr(def!)," ",float(addr(def!),0),long(addr(def!),8);tab(56); whileLoop 0,7 c$=char$(long(addr(ab!),8),&Loop,1); if c$=chr$(0):print "*"; else : print c$; : endif endwhile :print print "+ ";addr(ghi!)-addr(def!)," = ",addr(ghi!)," ",float(addr(ghi!),0),long(addr(ghi!),8);tab(56); whileLoop 0,7 c$=char$(long(addr(def!),8),&Loop,1); if c$=chr$(0):print "*"; else : print c$; : endif endwhile :print waitInput -
Abt. Horner-Schema
=============
Wer aus der Schule noch die Schrecken der Polynome in Erinnerung hat, sollte sich in Gedanken beim englischen Mathematiker William George Horner aus Bristol (UK) für eine starke schematische Vereinfachung bedanken. Gänzlich verliert die Sache ihre Schrecken, wenn man auch noch die Erfindungen der Herren W. Schickard, B. Pascal, Ch. Babbage und (parallel dazu) W. Leibnitz, welche in Zahnrad-betriebenen sog. "Rechenmaschinen" aus Holz und Messing gipfelten, sein Eigen nennt: Da wird die rasche numerische Polynomauswerung zum Kinderspiel. Man folge lediglich sehr genau den nachstehenden Anweisungen:Code
Alles anzeigenwindowtitle " HORNER-SCHEMA " ' Orig.-Quelle: E.Floegel: Pascal-Handbuch S. 76 ' Nach Profan transkribiert, Fehler abgefangen und adaptiert 2012 P. Specht ' (D) Nur für Demonstrationszwecke - ohne jedwede Gewähr! windowstyle 1048 : font 2 : randomize window %maxx\4,0-%maxx\2,%maxy-41 set("decimals",15):declare x!,y!,z!,i&,n&,a![],a$ grad: Cls rnd(8^8) print print " Numerische Polynomauswertung mittels Horner-Schema" print print " Grad des Polynoms: ";n& locate %csrlin-1,21 input a$ case a$>"":n&=val(a$) setsize a![],n&+1 neukoeff: print print " Bitte Koeffizienten eingeben: " print whileloop n&,0,-1 print " Koeff. von x^";str$(&Loop); print " = a[';str$(&Loop);'] "; case &Loop<10:print " "; print "= "; case a![&Loop]>0:print tab(28);a![&Loop]; print locate %csrlin-1,28 input a$ case a$>"":a![&Loop]=val(a$) endwhile xwert: print print " Auswertung an der Stelle x = "; case x!>0:print x!; print locate %csrlin-1,31 input a$ case a$>"":x!=val(a$) y!=0 whileloop n&,0,-1 y!=y!*x!+a![&Loop] endwhile print "------------------------------------------------------------------------" print " Polynomwert an Stelle ";x!;" ist : "; if abs(y!)>10^6 print format$("%e",y!) else print y! endif y!=0 print "------------------------------------------------------------------------" print " Für anderes x berechnen? "; input a$ a$=lower$(a$) case ord(a$)=ord("j"):goto "xwert" case val(a$)<>0:beep case val(a$)<>0:goto "xwert" print " Für andere Koeffizienten bei Grad ";n&;" berechnen? "; input a$ a$=lower$(a$) if ord(a$)=ord("j") cls rnd(8^8) goto "neukoeff" endif print " Anderes Polynom berechnen? "; input a$ a$=lower$(a$) case ord(a$)=ord("j"):goto "grad" print beep print " Wiedersehen! " waitinput 5000 -
Abt. Diskrete Fourieranalyse
==================
Im Bereich Digital Signal Processing (DSP) gibt es clevere Algorithmen, um einen Wellenzug in seine Grund- und Oberwellenanteile zu zerlegen. Stehen dabei nur bestimmte Stützstellen zur Verfügung, an denen das zu zerlegende Signal gemessen wurde, spricht man von Diskreter Fourierzerlegung. Details dazu, samt auf PC-Prozessoren optimierte Algorithmen, finden sich etwa hier oder z.B. hier.In reinem XProfan ist die Sache naturgemäß langsamer, auch wenn der nachfolgende Algorithmus zu den schnelleren gezählt wird (Noch flotter geht es dann mit dem FFT (Fast Fourier Transform)-Algorithmus, für dessen sog. "Butterfly"-Operationen die FloatingPoint Unit des PC sogar besonders schnelle Befehle bereithält - siehe die angegebene Literur).
Code
Alles anzeigenWindowTitle " FOURIERANALYSE DISKRETER MESSWERTE am Beispiel Sägezahn" ' (D) XProfan-Demo 2012-08 by P. Specht, Wien ' Keinerlei Gewähr; Anwendung auf eigene Gefahr! ' Orig.Quelle: A. Ralston - H. Wilf: Mathematische ' Methoden für Digitalrechner, Oldenburg Verlag windowstyle 1048:font 2:randomize:cls rnd(8^8) window %maxx/4,0 - %maxx/2,%maxy-42 declare tm&,f![],dy!,np&,nh&,i& : var pi!=pi() declare z!,s1!,c1!,c!,s!,q!,u0!,u1!,u2!,a!,b!,kln&,p& set("decimals",15) '{ Hauptteil print "\n Gesamtzahl der Frequenzen bzw. Harmonischen: "; input nh& : np&=2*nh&+1 print " Dazu sind mindestens ";np&;" Funktionswerte erforderlich.\n" f![0] = -1 : dy! = 2 / np& Print " Beispiel: Sägezahnfunktion" whileloop np&-1 f![&Loop] = f![&Loop-1] + dy! print &Loop, f![&Loop] endwhile waitInput : cls rnd(8^8) f![0]=0 : tm&=&Gettickcount Fourier print "\n",int(&GetTickCount-tm&,s!),"ms" waitinput:cls rnd(8^8) print f![0] = -1 : dy! = 2 / np& Print " Beispiel: Rechteckfunktion" whileloop np&-1 f![&Loop] = -1 + 2*(&Loop>=(np&\2)) print &Loop, f![&Loop] endwhile waitInput : cls rnd(8^8) f![0]=0 : tm&=&Gettickcount Fourier print "\n",int(&GetTickCount-tm&,s!),"ms" waitinput:cls rnd(8^8) '} proc Fourier z!=2/np& : c1!=cos(z!*pi!) : s1!=sin(z!*pi!) : c!=1 : s!=0 : p&=0 print "\n N Sin Cos " print "=======================================" repeat u1!=0 : u2!=0 : kln&=np&-1 repeat u0!=f![kln&]+2*c!*u1!-u2! u2!=u1! u1!=u0! dec kln& until kln&=0 a!=z!*(f![0]+c!*u1!-u2!) b!=z!*s!*u1! case p&=0:a!=a!/2 print p&,tab(25);a!,tab(60); b! q!=c1!*c! - s1!*s! s!=c1!*s! + s1!*c! c!=q! inc p& until p&=nh&+1 endproc -
Abt. Wichtige Links
============
Link: RGH betr. Zahlenbereich Single/Double bei X2Link: Der von XPIA und XPSE verwendete Freeware-Compiler JWasm
(Programmierer: Japhet) ist seit kurzem in neuer Version verfügbar:
JWasm v2.7a stable vom 21.07.2012 (Verbessertes INVOKE !)
JWasm v2.8rc5 (Release Candidate 5) Stand: 11.08.2012
(Verbesserung bei 64bit-Programmen, GccWin64.mak Kompatiblität)Empfehlung: Anthony Ralston, Herbert S. Wilf - Mathematical Methods for Digital Computers
-
Nun wissen wir also, daß es seine "Richtigkeit" hat, wenn einige Codes von dir nicht bei jedem laufen. Mit der nächsten Version wird alles besser

Gruß Volkmar
-
Abt. Softwarepatente auf Kreiszeichenverfahren
==============================Code
Alles anzeigenif 0 $MAKE CL endif WindowTitle "MIDPOINT CIRCLE ALGORITHM" ' (D-O) Demoware-only, 2012-08 by P. Specht, Wien. Ohne jedwede Gewähr. ' Es bestehen Patentrechte von IBM aus 1982 beim Europäischen Patentamt ! ' Quelle: http://de.wikipedia.org/wiki/Rasterung_von_Kreisen#Midpoint-Algorithmus WindowStyle 1048 Window 0,0-%maxx,%maxy Font 2 : Randomize : cls' rgb(246,246,246) 'var xm%=%maxx\2:var ym%=%maxy declare error% While 1 usepen 0,2,rgb(rnd(256),rnd(256),rnd(256)) circle rnd(%maxx),rnd(%maxy),rnd(100), waitinput 1 case %key=27:end EndWhile proc circle : parameters cx%,cy%,radius%,colr% declare x%,y%,error% error% = -1*radius% x% = radius% y% = 0 // The following while loop may be altered to 'while (x > y)' for a // performance benefit, as long as a call to 'plot4points' follows // the body of the loop. This allows for the elimination of the // '(x != y)' test in 'plot8points', providing a further benefit. // For the sake of clarity, this is not shown here. while (x% >= y%) plot8points(cx%,cy%,x%,y%) inc error%,y% inc y% inc error%,y% // The following test may be implemented in assembly language in // most machines by testing the carry flag after adding 'y' to // the value of 'error' in the previous step, since 'error' // nominally has a negative value. if (error% >= 0) dec error%,x% dec x% dec error%,x% endif endwhile endproc proc plot8points : parameters cx%,cy%,x%,y% plot4points(cx%,cy%,x%,y%) case x%-y%: plot4points(cx%,cy%,y%,x%) endproc proc plot4points : parameters cx%,cy%,x%,y% setPixl cx%+x%, cy%+y% case x%: setPixl cx% - x%, cy% + y% case y%: setPixl cx% + x%, cy% - y% case x%*y%: setPixl cx%-x%,cy%-y% endproc // The '(x != 0 && y != 0) ' test in the last line of this function // may be omitted for a performance benefit if the radius of the // circle is known to be non-zero. proc setpixl parameters x%,y% rectangle x%-10,(y%-10) - (x%+1),y%+1 ' ellipse x%-1,(y%-1) - (x%+1),y%+1) ' ellipse, rectangle, line etc. bringen hier unterschiedliche effekte, ' und zwar, anders als setpixel, gleich in der gewünschten Pixelgröße endproc -
Abt. Lange Integerzahlen halbieren
======================
Anm.d.Verf.: Das Ganze soll nur eine Vorbereitung auf die russische Multiplikationsmethode werden.Code
Alles anzeigenif 0 $MAKE CL endif WindowTitle "Langzahl halbieren" Windowstyle 1048 Window 0,0-%maxx,%maxy-42 font 2 randomize declare m$,c$,c%,a%,r%,a$,tm&,vz%,anz%,manuell% eingabe: print "\n Bitte Lange Integerzahl eingeben [<return> für Zufall]: "; input m$ if m$="" m$=if(rnd(2),chr$(45)," ") +chr$(49+rnd(9)) anz%=1024+rnd(6000) whileloop 2,anz% m$=m$+chr$(48+rnd(10)) endwhile cls print m$ else manuell%=1 endif nochmal: anz%=len(m$) tm&=&gettickcount m$=trim$(m$) if left$(m$,1)="-" vz%=-1 m$=mid$(m$,2,len(m$)-1) endif r%=0 a$="" whileloop len(m$) c$ = mid$(m$,&loop,1) c%=10*r%+val(c$) a%=c%\2 a$=a$+str$(a%) r%=c%-2*a% endwhile a$=a$+":" a$=translate$(a$,"0"," ") a$=trim$(a$) a$=translate$(a$," ","0") a$=left$(a$,len(a$)-1) if vz%= -1 a$="-"+a$ endif locate 1,1 ' print ' case r% mod 2:a$=a$+".5" tm&=&gettickcount-tm& case manuell%: cls print " ";a$;" " print " ";anz%,"Stellen, ",tm&,"ms" case manuell% :Waitinput if anz%=0 cls:print manuell%=0 goto "eingabe" endif m$=a$ goto "nochmal" -
Abt. Lange Integerzahlen verdoppeln
=======================Code
Alles anzeigenif 0 $MAKE CL endif WindowTitle "Langzahl verdoppeln" ' (CL) Copyleft 2012-08 P. Specht ' Keine Garantie, Gewähr oder sonstwas. Nichtmal denken! Windowstyle 1048 Window 0,0-%maxx,%maxy-42 font 2 randomize declare m$,c$,c%,a%,r%,a$,tm&,vz%,anz%,manuell% eingabe: print "\n Bitte Integer-Langzahl eingeben [<return> für Zufall]: "; input m$ if m$="" m$=if(rnd(2),chr$(45)," ") +chr$(49+rnd(9)) anz%=1024+rnd(6000) whileloop 2,anz% m$=m$+chr$(48+rnd(10)) endwhile cls print m$ else manuell%=1 endif nochmal: anz%=len(m$) tm&=&gettickcount m$=trim$(m$) if left$(m$,1)="-" vz%=-1 m$=mid$(m$,2,len(m$)-1) endif a$="" r%=0 whileloop len(m$),1,-1 c$ = mid$(m$,&loop,1) c%=val(c$) a%=2*c%+r% r%=0 if a%>9 a%=a%-10 r%=1 endif a$=str$(a%)+a$ endwhile case r%=1:a$="1"+a$ a$=a$+":" a$=translate$(a$,"0"," ") a$=trim$(a$) a$=translate$(a$," ","0") a$=left$(a$,len(a$)-1) if vz%= -1 a$="-"+a$ endif locate 1,1 ' print ' case r% mod 2:a$=a$+".5" tm&=&gettickcount-tm& case manuell%: cls print " ";a$;" " print " ";anz%,"Stellen, ",tm&,"ms" case manuell% :Waitinput if anz%=0 cls:print manuell%=0 goto "eingabe" endif m$=a$ goto "nochmal" -
He, das ist toll! Nur XProfans Input-Befehl macht schnell schlapp...

Geht das auch für Floats? -
Floats sind letztlich gekappte Lange Ganzzahlen plus ein Teil, der sich merkt wohin eigentlich das Komma verschoben gehört (Exponent + := Komma nach rechts, eventuell mit Nullen bis zum Komma auffüllen, Exponent - := Komma nach links). Die russische Methode erfordert aber, daß man weiß, ob eine Gerade oder Ungerade Zahl vorliegt, und das ist nur an der rechtesten Stelle erkennbar. Wenn die Float-Zahl aber z.B. an der 16. Stelle von links gekappt wurde, erkennt man das womöglich nicht mehr. Also: Mit der Originalen Russischen Methode geht´s nicht, sondern die FPU nutzt eine stark geänderte Variante davon, den Booth-Algorithmus. Weitere Details z.B. hier (S.104).
Oder meintest Du eine Beschleunigung, bei der man die volle Ganzzahlbreite (14 Stellen) von Floats nutzt? Das geht natürlich auch. Wer Geschwindigkeit bei beliebiger Genauigkeit braucht, der sollte sich die Freeware-Mathe-Programmiersprache "R" auf seinen Rechner holen - nutzt alle CPU-Cores. Ich hier will ja bloß zu Demonstrationszwecken die (an sich händische) Methode der 'Russischen Bauern-Multiplikation' nachbauen. Dazu wären soviele Stellen gar nicht notwendig, wie nachstehendes Machwerk beweist:
Code
Alles anzeigenWindowTitle "Russische Multiplikation" declare md&,mr&,sum&,probe! print "\n Multiplikand =",:input md& print "\n Multiplikator =",:input mr& print "\n Produkt =", probe!=md&*mr& if md&>mr&:sum&=md&:md&=mr&:mr&=sum&:sum&=0:endif case md& mod 2:sum&=mr& Repeat md&=md&\2 : mr&=2*mr& case md& mod 2:sum&=sum&+mr& until md&=0 print sum& print "\n Konventionell: ";probe! WaitinputP.S.: Im Spätmittelalter wurden bis zu acht verschiedene Multiplikationsmethoden gelehrt, siehe hier.
-
Ich meinte das Erstere.

Toller Buchlink! Ich glaube, meine Kinder sind froh, nur eine Methode lernen zu müssen.

-
Abt. Russische Bauernmultiplikation für lange positive Zahlenstrings
==========================================
Für Profan-X2 bitte die Teile mit der Variablen Probe! herausnehmen!Code
Alles anzeigenif 0 $MAKE CL endif WindowTitle "Russische Bauernmultiplikation" ' (CL) Copyleft 2012-08 by P<punkt>Specht<at>gmx.at ' Keine wie auch immer geartete Gewähr! WindowStyle 1048:Font 2:Randomize Cls 15790320+rgb(rnd(15),rnd(15),rnd(15)) Declare R#:Struct R=Left&,Top&,Right&,Bottom&:Dim R#,R External("user32.dll","SystemParametersInfoA",48,0,R#,0) With R#:Window .Left&,.Top&- .Right&,.Bottom&:EndWith Dispose R# Declare md$,mr$,sum$,probe! Set("decimals",18) Nochmal: print "\n Multiplikand =",:input md$ print "\n Multiplikator =",:input mr$ print "\n Produkt =", probe!=val(md$)*val(mr$) if md$>mr$:sum$=md$:md$=mr$:mr$=sum$:sum$="":endif sum$="" case val(right$(md$,1)) mod 2:sum$=mr$ Repeat md$ = Halbiere(md$) mr$ = Verdopple(mr$) case val(right$(md$,1)) mod 2 : sum$ = Addiere(sum$,mr$) Until val(left$(md$,2))=0 print sum$;" " if probe!<10^15 print "\n Probe (Float) = ";probe! else print "\n Probe (Float)= ";format$("%e",probe!) endif WaitInput case %csrlin>35:Cls 15790320+rgb(rnd(15),rnd(15),rnd(15)) goto "Nochmal" proc Verdopple parameters m$ declare c$,c%,a%,r%,a$,tm&,vz%,anz%,manuell% manuell%=1 anz%=len(m$) tm&=&gettickcount m$=trim$(m$) if left$(m$,1)="-" vz%=-1 m$=mid$(m$,2,len(m$)-1) endif a$="" r%=0 whileloop len(m$),1,-1 c$ = mid$(m$,&loop,1) c%=val(c$) a%=2*c%+r% r%=0 if a%>9 a%=a%-10 r%=1 endif a$=str$(a%)+a$ endwhile case r%=1:a$="1"+a$ a$=a$+":" a$=translate$(a$,"0"," ") a$=trim$(a$) a$=translate$(a$," ","0") a$=left$(a$,len(a$)-1) case vz%= -1:a$="-"+a$ return a$ endproc proc Halbiere : parameters m$ declare c$,c%,a%,r%,a$,tm&,vz%,anz%,manuell% anz%=len(m$) tm&=&gettickcount m$=trim$(m$) if left$(m$,1)="-" vz%= -1 m$=mid$(m$,2,len(m$)-1) endif r%=0 a$="" whileloop len(m$) c$ = mid$(m$,&loop,1) c%=10*r%+val(c$) a%=c%\2 a$=a$+str$(a%) r%=c%-2*a% endwhile a$=a$+":" a$=translate$(a$,"0"," ") a$=trim$(a$) a$=translate$(a$," ","0") a$=left$(a$,len(a$)-1) case vz%= -1:a$="-"+a$ return a$ endproc proc Addiere : parameters a$,b$ declare S$,la&,lb&,l&,a&,b&,c&,s&,i&,si$,carry&,lc& a&=0:b&=0:S$="":S&=0:c&=0:carry&=0:lc&=0 'last carry la&=len(A$):lb&=len(B$):l&=la& If lb&>la&:l&=lb&:A$=Mkstr$(" ",lb&-la&)+A$ Else :B$=Mkstr$(" ",la&-lb&)+B$:Endif Whileloop 0,l&-1 i&=l&-&Loop a&=val(Mid$(A$,i&,1)) b&=val(Mid$(B$,i&,1)) c&=carry&+a&+b& s&=c& mod 10 carry&= c& \ 10 lc&=carry& si$=str$(s&):s$=si$+s$ EndWhile s$=if(lc&,str$(lc&)," ")+s$ s$=s$+":" s$=translate$(s$,"0"," ") s$=trim$(s$) s$=translate$(s$," ","0") s$=left$(s$,len(s$)-1) return s$ EndProc -
Abt. Dreiecks-Umkreis zeigen
==================Code
Alles anzeigenWindowtitle "Umkreis berechnen" ' (CL) Copyleft 2012-08 P. Specht ' {z.B. zur Vorbereitung für die Flip-Operation der Delauney-Triangulation } Declare x!,y!,x0!,y0!,x1!,y1!,x2!,y2!,xu!,yu!,error%,nenn!,r! Declare y01!,yy2!,yy0!,xx0!,yy1!,xx1!,xx2!,x10!,x02!,x21! Declare xu0!,yu0!,xxu0!,yyu0! Font 2 : Randomize : var xm!=%maxx/2:var ym!=%maxy/2 Window 0,0 - %maxx,%maxy Cls rgb(246,246,246) AppendMenuBar 10,"Bitte mit Maus Dreieckspunkte klicken..." nochmal: WaitMouse x0!=%mousex y0!=%mousey usepen 0,2,0 point x0!,y0! WaitMouse x1!=%mousex y1!=%mousey usepen 0,2,0 point x1!,y1! usepen 0,1,0 line x0!,y0! - x1!,y1! WaitMouse x2!=%mousex y2!=%mousey usepen 0,2,0 point x2!,y2! usepen 0,1,0 line x0!,y0! - x2!,y2! line x1!,y1! - x2!,y2! y01!=y0!-y1! yy2!=y2!*y2! yy0!=y0!*y0! xx0!=x0!*x0! yy1!=y1!*y1! xx1!=x1!*x1! xx2!=x2!*x2! x10!=x1!-x0! x02!=x0!-x2! x21!=x2!-x1! nenn!=(2*(x10!*y2!+x02!*y1!+(x21!)*y0!)) ifnot (nenn!=0) or (y01!=0) xu!=(y01!*yy2!-(yy0!-yy1!+xx0!-xx1!)*y2!-y0!*yy1!+\ (xx0!+yy0!-xx2!)*y1!+(xx2!-xx1!)*y0!) / nenn! 'xu!=((y0!-y1!)*y2!*y2!-(y0!*y0!+x0!*x0!-y1!*y1!-x1!*x1!)*y2!-y0!*y1!*y1!+\ '(x0!*x0!+y0!*y0!-x2!*x2!)*y1!+(x2!*x2!-x1!*x1!)*y0!) / \ '(2*((x1!-x0!)*y2!+(x0!-x2!)*y1!+(x2!-x1!)*y0!)) yu!=x10!/y01!*(xu!-(x0!+x1!)/2)+(y0!+y1!)/2 usepen 0,5,255 point xu!,yu! xu0!=xu!-x0! xxu0!=xu0!*xu0! yu0!=yu!-y0! yyu0!=yu0!*yu0! r!=sqrt(xxu0!+yyu0!) if r!<10000 usepen 0,1,255 circle xu!,yu!,r! endif endif goto "nochmal" proc point parameters x!,y! rectangle x!+2,(y!+2) - (x!-2),y!-2 endproc proc circle : parameters cx%,cy%,radius% declare x%,y%,error% error% = -1*radius% x% = radius% y% = 0 while (x% >= y%) plot8points(cx%,cy%,x%,y%) inc error%,y% inc y% inc error%,y% if (error% >= 0) dec error%,x% dec x% dec error%,x% endif endwhile endproc proc plot8points : parameters cx%,cy%,x%,y% plot4points(cx%,cy%,x%,y%) case x%-y%: plot4points(cx%,cy%,y%,x%) endproc proc plot4points : parameters cx%,cy%,x%,y% setPixl cx%+x%, cy%+y% case x%: setPixl cx% - x%, cy% + y% case y%: setPixl cx% + x%, cy% - y% case x%*y%: setPixl cx%-x%,cy%-y% endproc proc setpixl parameters x%,y% setpixel x%,y%,255 endproc -
Abt. Viele kleine 2x2-Matrizen rasch und genau invertieren
=====================================
...kommt als Problem nirgendwo vor. Zumindest nicht daß ich wüsste. Und weils keiner braucht, landet das Programm daher auf unserer Müllkippe hier.
GrussP.S.: Eventuell doch: In der Fehlerabschätzung zu Gesichtserkennungsverfahren. Aber das hat mit XProfan ungefähr garnix zu tun, u.a. weil derjenige, dessen Gesicht erkannt werden soll bis zum Ergebnis der Profan-Auswertung schon einen Vollbart hat. Naja. Zumindest hat aber dieser Text nun ein P.S. Aus Tradition. Jawoll aber auch!!!
Code
Alles anzeigenWindowtitle "2x2-Matrix schnell invertieren" declare z&,s&,m![1,1],inv![1,1],m$[],s$,det! Cls ' a c b d " s$="10 2 40.2 -18" m$[]=explode(s$," ") m![]=val(m$[&index]) clear m$[] show m![] invt m![] show inv![] waitinput invt inv![] show inv![] waitinput end proc invt : parameters m![] ' det = a*d-b*c det!=m![0,0]*m![1,1]-m![1,0]*m![0,1] ' (d/det -b/det , -c/det a/det) inv![1,1]=m![1,1] *-1/det! inv![0,1]=m![0,1]* 1/det! inv![1,0]=m![1,0]* 1/det! inv![0,0]=m![0,0]*-1/det! endproc proc show : parameters m![] whileloop 0,1:z&=&Loop:whileloop 0,1:s&=&Loop print m![z&,s&],:endwhile:print:endwhile:print endproc -
Abt. Beinahe-konvexe Hülle mittel Schiebelehrenprinzip und 8 Messrichtungen
================================================
Braucht auch keiner, ist aber lustig anzusehen. Man könnte eine Dimension hinzufügen und einen Gesichtsform-Analysator damit bauen. *)
GrussCode
Alles anzeigenif 0 $MAKE CL endif WindowTitle "Beinahe-Konvexe Hülle (Schiebelehreprinzip mit 8 Richtungen)" WindowStyle 1048:Font 2:Randomize Window 0,0-%maxx,%maxy declare xm&,ym&,xm2&,ym2&,colr&,n&,x![],y![],i&,j&,k&,ri& declare xmax&,xmin&,ymax&,ymin&,xmax!,xmin!,ymax!,ymin! declare xpymax&,xpymin&,xmymax&,xmymin&,xpymax!,xpymin!,xmymax!,xmymin! declare xp2ymax&,xp2ymin&,xm2ymax&,xm2ymin&,xp2ymax!,xp2ymin!,xm2ymax!,xm2ymin! declare x2pymax&,x2pymin&,x2mymax&,x2mymin&,x2pymax!,x2pymin!,x2mymax!,x2mymin! xm&=%maxx\2:ym&=%maxy\2:xm2&=%maxx\4:ym2&=%maxy\4 colr&=rgb(220,220,220)+rgb(rnd(36),rnd(36),rnd(36)) n&=200:ri&=-1 machsnochmalsam: case n&<34:ri&=1 if n&>1000:ri&=-1:cls:endif n&=n&+ri&*n&/10:setsize x![],n&:setsize y![],n& x![]=rnd(ym&)-xm2&:y![]=rnd(ym&)-ym2&:usepen 0,1,0 ' : *&index\n& xmax!=10^-38:xmin!=10^38:ymax!=10^-38:ymin!=10^38 xpymax!=10^-38:xpymin!=10^38:xmymax!=10^-38:xmymin!=10^38 xp2ymax!=10^-38:xp2ymin!=10^38:xm2ymax!=10^-38:xm2ymin!=10^38 x2pymax!=10^-38:x2pymin!=10^38:x2mymax!=10^-38:x2mymin!=10^38 WhileLoop 0,n&-1:i&=&Loop case ri&=1:rectangle xm&+x![i&]+2,(ym&-y![i&]+2) - (xm&+x![i&]-2),ym&-y![i&]-2 if xmax!<x![i&]:xmax!=x![i&]:xmax&=i&:endif if xmin!>x![i&]:xmin!=x![i&]:xmin&=i&:endif if ymax!<y![i&]:ymax!=y![i&]:ymax&=i&:endif if ymin!>y![i&]:ymin!=y![i&]:ymin&=i&:endif if xpymax!<(x![i&]+y![i&]):xpymax!=x![i&]+y![i&]:xpymax&=i&:endif if xpymin!>(x![i&]+y![i&]):xpymin!=x![i&]+y![i&]:xpymin&=i&:endif if xmymax!<(x![i&]-y![i&]):xmymax!=x![i&]-y![i&]:xmymax&=i&:endif if xmymin!>(x![i&]-y![i&]):xmymin!=x![i&]-y![i&]:xmymin&=i&:endif if xp2ymax!<(x![i&]+2*y![i&]):xp2ymax!=x![i&]+2*y![i&]:xp2ymax&=i&:endif if xp2ymin!>(x![i&]+2*y![i&]):xp2ymin!=x![i&]+2*y![i&]:xp2ymin&=i&:endif if xm2ymax!<(x![i&]-2*y![i&]):xm2ymax!=x![i&]-2*y![i&]:xm2ymax&=i&:endif if xm2ymin!>(x![i&]-2*y![i&]):xm2ymin!=x![i&]-2*y![i&]:xm2ymin&=i&:endif if x2pymax!<(x![i&]*2+y![i&]):x2pymax!=x![i&]*2+y![i&]:x2pymax&=i&:endif if x2pymin!>(x![i&]*2+y![i&]):x2pymin!=x![i&]*2+y![i&]:x2pymin&=i&:endif if x2mymax!<(x![i&]*2-y![i&]):x2mymax!=x![i&]*2-y![i&]:x2mymax&=i&:endif if x2mymin!>(x![i&]*2-y![i&]):x2mymin!=x![i&]*2-y![i&]:x2mymin&=i&:endif EndWhile 'Cls colr& locate 1,1:print n&;" " usepen 0,2,255 line xm&+x![xmin&],(ym&-y![xmin&]) - (xm&+x![x2mymin&]),ym&-y![x2mymin&] line xm&+x![x2mymin&],(ym&-y![x2mymin&]) - (xm&+x![xmymin&]),ym&-y![xmymin&] line xm&+x![xmymin&],(ym&-y![xmymin&]) - (xm&+x![xm2ymin&]),ym&-y![xm2ymin&] line xm&+x![xm2ymin&],(ym&-y![xm2ymin&]) - (xm&+x![ymax&]),ym&-y![ymax&] line xm&+x![ymax&],(ym&-y![ymax&]) - (xm&+x![xp2ymax&]),ym&-y![xp2ymax&] line xm&+x![xp2ymax&],(ym&-y![xp2ymax&]) - (xm&+x![xpymax&]),ym&-y![xpymax&] line xm&+x![xpymax&],(ym&-y![xpymax&]) - (xm&+x![x2pymax&]),ym&-y![x2pymax&] line xm&+x![x2pymax&],(ym&-y![x2pymax&]) - (xm&+x![xmax&]),ym&-y![xmax&] line xm&+x![xmax&],(ym&-y![xmax&]) - (xm&+x![x2mymax&]),ym&-y![x2mymax&] line xm&+x![x2mymax&],(ym&-y![x2mymax&]) - (xm&+x![xmymax&]),ym&-y![xmymax&] line xm&+x![xmymax&],(ym&-y![xmymax&]) - (xm&+x![xm2ymax&]),ym&-y![xm2ymax&] line xm&+x![xm2ymax&],(ym&-y![xm2ymax&]) - (xm&+x![ymin&]),ym&-y![ymin&] line xm&+x![ymin&],(ym&-y![ymin&]) - (xm&+x![xp2ymin&]),ym&-y![xp2ymin&] line xm&+x![xp2ymin&],(ym&-y![xp2ymin&]) - (xm&+x![xpymin&]),ym&-y![xpymin&] line xm&+x![xpymin&],(ym&-y![xpymin&]) - (xm&+x![x2pymin&]),ym&-y![x2pymin&] line xm&+x![x2pymin&],(ym&-y![x2pymin&]) - (xm&+x![xmin&]),ym&-y![xmin&] ' pointtext 'WaitInput 500 'case %key=27:end goto "machsnochmalsam"
____
*) wenn man mehr Grips hätte als ich, die Fischer-Roppert-Transformation kapieren würde und CUDA könnte... -
In die Richtung gehen deine aktuellen "Forschungen" also. Aber wie du schon sagtest, für sowas ist XProfan dann nicht schnell genug.

-
Abt. Nudelmathematik
==============
ist nichts unanständiges. Der Springer-Verlag hat immerhin Buchpreise und Nudelpackungen als Preis ausgelobt, wenn man es schafft, seine Lieblings-Nudel in mathematischer Form zu beschreiben. Wer will, kann sich ja mal dran versuchen. -
Abt. 3x3-Matrix invertieren mit Determinantenmethode
==================================
Was einige Beiträge vorher mit 2x2-Matrizen geschah, kann auch auf 3x3 Matrizen noch mit Geschwindigkeits- und Genauigkeitsvorteilen angewendet werden. Ab 4x4 wird die Sache angeblich aber unwirtschaftlich, da sind die üblichen Verfahren (Gauß-Jordan etc) bereits überlegen, sagen Fachleute. Ich werde das gelegentlich prüfen ; - )
GrussCode
Alles anzeigenWindowTitle "3x3-Matrixinversion per Division der Adjungierten durch Determinante" ' (CL) Copyleft 2012-08 by P.Specht@gmx.at ' Genauigkeit bei Verwendung von DoublePrecision: 12 signifikante Stellen. (~ 8*10^-13) Font 2:Randomize:Cls rnd(8^8):set("decimals",12):set("numwidth",23) proc Show : parameters M![] whileloop 0,n&:i&=&Loop:whileLoop 0,n&:j&=&Loop print M![i&,j&],:endwhile :print:endwhile endproc ' EINGABETEIL Var n&=3:dec n&:Declare M![n&,n&], Inv![2,2],Det!,s$,m$[],i&,j& print "Eingabe: Matrixelemente zeilenweise:\n" ' 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 s$ = " 11.11, 44.44, 99.99, 22.22, 77.77, 66.66, 33.33, 88.88, 0.100000000001" 'Testeingabe: Linear_abhängige_Zeilen: ' 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 ' s$ = " 11.11, 44.44, 99.99, 22.22, 77.77, 66.66, 22.22, 77.77, 66.66" ' Allfällige weitere Testeingaben des Anwenders: ' 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 ' s$ = " 0, 44.44, 99.99, 22.22, 77.77, 66.66, 33.33, 88.88, 0" ' Hier wird die zeilenweise Form in die spaltenweise Datenhaltung von XProfan gewandelt: m$[]=explode(s$,",") whileloop 0,n&:i&=&Loop:whileloop 0,n&:j&=&Loop m![j&,i&]=val(m$[3*j&+i&]):endwhile :endwhile :clear m$[] Show M![] print "\nDeterminante = ";Det3x3(M![]) print "\nAdjungierte[]:\n" Show Adjoint3x3(M![]): print print "\nInvertierte[]: "; Inv![] = Invt3x3(M![]) if Inv![0,0]<>-1*10^-38 print:print Show Inv![] : print print "\nZur Probe: Invertierte rückinvertieren:\n" Inv![] = Invt3x3(Inv![]) : Show Inv![] : print else Print "\nEINE INVERTIERUNG IST BEI DIESEN EINGABEDATEN LEIDER NICHT MÖGLICH! " endif WaitInput End ' ________________________________________ proc Invt3x3 parameters A![] declare Invt![2,2],Adju![2,2],Det! Det!=Det3x3(A![]) if Det!<>0 Adju![]=Adjoint3x3(A![]) whileloop 0,2:i&=&Loop:whileloop 0,2:j&=&Loop invt![i&,j&] = adju![i&,j&] / Det! :endwhile : endwhile else sound 2300,300:beep print " E R R O R: DETERMINANTE = NULL!" erase invt![] invt![0,0]=-1*10^-38 endif return Invt![] endproc proc Det3x3 :parameters A![] return a![0,0]*(a![1,1]*a![2,2]-a![1,2]*a![2,1]) \ - a![0,1]*(a![1,0]*a![2,2]-a![1,2]*a![2,0]) \ + a![0,2]*(a![1,0]*a![2,1]-a![1,1]*a![2,0]) endproc proc Adjoint3x3 : parameters A![] Declare Adju![2,2] ' = 3x3-Matrix ! ' Beschleunigung durch Variablenfassung der jeweils ' doppelt vorkommenden Produkte wäre noch möglich! ' Zeile 0 adju![0,0]=a![1,1]*a![2,2]-a![1,2]*a![2,1] adju![0,1]=a![0,2]*a![2,1]-a![0,1]*a![2,2] adju![0,2]=a![0,1]*a![1,2]-a![0,2]*a![1,1] ' Zeile 1 adju![1,0]=a![1,2]*a![2,0]-a![1,0]*a![2,2] adju![1,1]=a![0,0]*a![2,2]-a![0,2]*a![2,0] adju![1,2]=a![0,2]*a![1,0]-a![0,0]*a![1,2] ' Zeile 2 adju![2,0]=a![1,0]*a![2,1]-a![1,1]*a![2,0] adju![2,1]=a![0,1]*a![2,0]-a![0,0]*a![2,1] adju![2,2]=a![0,0]*a![1,1]-a![0,1]*a![1,0] return adju![] endproc -
Jetzt mitmachen!
Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!