Vorheriges Thema anzeigen :: Nächstes Thema anzeigen |
Autor |
Nachricht |
DB1BMN
Anmeldungsdatum: 17.12.2005 Beiträge: 24 Wohnort: Delmenhorst
|
Verfasst am: 03.04.2006, 14:01 Titel: Komplexe Rechnung |
|
|
Hi,
ich habe gesehen, dass man mit FB keine komplexe Rechnung machen kann, da habe ich mal eben ein paar Funktionen dafür erstellt:
Code: |
rem funktionen zur komplexen rechnung
rem by DB1BMN
rem mailto: db1bmn@gmx.de
rem url: www.mydarc.de/db1bmn
rem 1. Apr. 2006 - 3. Apr. 2006
rem komplexe zahl als vektor des R² definieren
type complex
real as single
imag as single
end type
rem betrag komplexer zahlen
declare function absc (c as complex) as single
rem argument komplexer zahlen
declare function argc (c as complex) as single
rem realteil komplexer zahlen
declare function realc (c as complex) as single
rem imaginärteil komplexer zahlen
declare function imagc (c as complex) as single
rem komplexe konjunktion
declare function compconj (c as complex) as complex
rem addition komplexer zahlen
declare function addc (c as complex, d as complex) as complex
rem muliplikation komplexer zahlen
declare function mulc (c as complex, d as complex) as complex
rem umwandlung polarform -> normalform
declare function normc (r as single, t as single) as complex
dim z as complex
dim y as complex
z.real = sqr(1/2)
z.imag = sqr(1/2)
y = z
print absc(z)
print argc(z)
z = mulc(z, y)
print realc(z)
print imagc(z)
z = compconj(z)
print realc(z)
print imagc(z)
z = addc(z, y)
print realc(z)
print imagc(z)
dim pi as single
pi = 4 * atn(1)
z = normc(1, pi/4)
print realc(z)
print imagc(z)
function absc(komplexe_zahl as complex) as single
rem betrag einer komplexen zahl
return sqr(komplexe_zahl.real^2 + komplexe_zahl.imag^2)
end function
function argc (komplexe_zahl as complex) as single
rem argument einer komplexer zahl
return atn(komplexe_zahl.imag / komplexe_zahl.real)
end function
function realc(komplexe_zahl as complex) as single
rem realteil einer komplexen zahl
return komplexe_zahl.real
end function
function imagc(komplexe_zahl as complex) as single
rem imaginärteil einer komplexen zahl
return komplexe_zahl.imag
end function
function compconj(komplexe_zahl as complex) as complex
rem komplexe konjunktion einer komplexen zahl
dim temp as complex
temp.real = komplexe_zahl.real
temp.imag = komplexe_zahl.imag * (- 1)
return temp
end function
function addc(komplexe_zahl_1 as complex, komplexe_zahl_2 as complex) as complex
rem addition einer komplexen zahl
dim temp as complex
temp.real = komplexe_zahl_1.real + komplexe_zahl_2.real
temp.imag = komplexe_zahl_1.imag + komplexe_zahl_2.imag
return temp
end function
function mulc(komplexe_zahl_1 as complex, komplexe_zahl_2 as complex) as complex
rem multiplikation einer komplexen zahl
dim temp as complex
temp.real = komplexe_zahl_1.real * komplexe_zahl_2.real - komplexe_zahl_1.imag * komplexe_zahl_2.imag
temp.imag = komplexe_zahl_1.real * komplexe_zahl_2.imag + komplexe_zahl_1.imag * komplexe_zahl_2.real
return temp
end function
function normc(betrag as single, argument as single) as complex
rem umwandlung von polarform nach normalform
dim temp as complex
temp.real = betrag * cos(argument)
temp.imag = betrag * sin(argument)
return temp
end function
sleep
|
Beste Grüße, Marek |
|
Nach oben |
|
|
raph ael
Anmeldungsdatum: 12.04.2006 Beiträge: 472
|
Verfasst am: 05.05.2006, 20:02 Titel: |
|
|
Ähh... Weißt du, du kannst "rem" mit einem Hochkomma " ' " abkürzen.
!!!Special trick!!!
Das wissen nicht viele aber... Schick mir ne' PM!!! Dann weißt du auch wie man PRINT abkürzt...
/!!!Special trick!!! _________________
Zitat: | 1000 Yottabytes sind absurd. 640 Yottabytes sollten genug für jeden sein. |
|
|
Nach oben |
|
|
Michael712 aka anfänger, programmierer
Anmeldungsdatum: 26.03.2005 Beiträge: 1593
|
Verfasst am: 05.05.2006, 20:34 Titel: |
|
|
raph ael hat Folgendes geschrieben: | Ähh... Weißt du, du kannst "rem" mit einem Hochkomma " ' " abkürzen.
!!!Special trick!!!
Das wissen nicht viele aber... Schick mir ne' PM!!! Dann weißt du auch wie man PRINT abkürzt...
/!!!Special trick!!! |
Ähm, es weiß wohl jeder, dass man Print mit "?" abkürzen kann |
|
Nach oben |
|
|
ytwinky
Anmeldungsdatum: 28.05.2005 Beiträge: 2624 Wohnort: Machteburch
|
Verfasst am: 05.05.2006, 21:56 Titel: Re: Komplexe Rechnung |
|
|
DB1BMN hat Folgendes geschrieben: | rem komplexe zahl als vektor des R² definieren |
Hmm, wenn ich komplexe Zahlen aus R² bearbeiten will, scheint es mir doch sinnvoller,
den reellen Teil als Double zu deklarieren, bei dem imaginären Teil ist Single imho ok
Der Geschwindigkeitsverlust durch die Double's fällt bei der komplexen Berechnung
sowieso nicht mehr ins Gewicht..
Das ist mein Beitrag zu 'Tripps' & 'Tricks'
@raph ael:
Ich benutze '?' seit über 20 Jahren als Print-Ersatz und schließe mich auch bezüglich des Smileys programmierer an
ytwinky _________________
v1ctor hat Folgendes geschrieben: | Yeah, i like INPUT$(n) as much as PRINT USING.. | ..also ungefähr so, wie ich GOTO.. |
|
Nach oben |
|
|
psygate
Anmeldungsdatum: 05.04.2005 Beiträge: 304 Wohnort: Wien und der Computer
|
Verfasst am: 30.07.2006, 23:12 Titel: |
|
|
Ich äh.. habe auch eine solche biblio geschrieben, kann sie nur nciht compilieren, Hilfe gesucht.
PS: Es sind alle funktionen drinne:
addition, subtraktion, multiplikation, division, potenzieren (mit komplexer hoch koplexer zahl!), potentieren ersetz das wurzelziehen usw...
Wenn mir jemand hilft, kann ich sie hochladen .
Naja, in erster Linie gehts mir darum, dass ich endlich mal eine bibliothek kompilieren kann!
PS: man sollte pi als double deklarieren, sonst summieren sich die Fehler ind en Zahlen und es kommt schmarren raus! *Erfahrungen hab*
@DB1BMN: möglicherweise können wir mit dieser Bibliothek kooperieren und zusammn arbeiten um sie zu verbessern? _________________ Danke an Volta für seine großartige MMX_fade function. *verneig*
Personal-DNA:
<script src="http://personaldna.com/h/?k=qtrCFboSuCOpFrX-OI-AADBA-f78d&t=Free-Wheeling+Leader">
</script>
Zitat: | Das Forum für den zum QBASIC kompatieblen open soure FreeBasic Kompiler. | by DJ. Peters |
|
Nach oben |
|
|
Michael Frey
Anmeldungsdatum: 18.12.2004 Beiträge: 2577 Wohnort: Schweiz
|
|
Nach oben |
|
|
psygate
Anmeldungsdatum: 05.04.2005 Beiträge: 304 Wohnort: Wien und der Computer
|
Verfasst am: 31.07.2006, 12:05 Titel: |
|
|
So, ich mach jetzt für meinen Source keine eigenen Thread auf, ich post ihn mal hier rein. Ein teil besteht aus DB1BMN's Funktionen, einen anderen Teil habe ich hinzugefügt.
Code: |
'complex library by psygate 2006
'Die Anderen Trigonometrischen funktionen lassen sich leicht ermitteln:
'tan=sin/cos
'cotan=1/tan
'secans=1/cos
'cosecans=1/sin
'TO-DO:
'arcus functions
const pi=atn(1)*4
const e=2.7182818284592
#define ln(x) log(x)
type complex
r as double
i as double
end type
type cpolar
r as double
a as double
end type
dim shared as complex c
dim shared as cpolar f
dim shared as double d
declare function cadd(a as complex,b as complex) as complex 'Addition
declare function cfunction(a as complex,b as complex) as complex 'Subtraktion
declare function cmul(a as complex,b as complex) as complex 'Multiplikation
declare function cdiv(a as complex,b as complex) as complex 'Division
declare function cpot(a as complex,b as complex) as complex 'Potenzieren (a+b*i)^(c+d*i) --> Um nur eine Komplexe hoch eine reele zahl zu bekommen setze b.i=0
declare function clog(a as complex) as complex 'Logarithmus
declare function csin(a as complex) as complex 'Sinus
declare function ccos(a as complex) as complex 'Cosinus
declare function cabs(a as complex) as double 'Betrag
declare function carg(a as complex) as double 'Argument
declare function real(a as complex) as double 'Real Teil
declare function imag(a as complex) as double 'Imaginär Teil
declare function conj(a as complex) as complex 'Konjungierte Zahl
declare function recp(a as complex) as cpolar 'Gauß'sche Darstellung -> Polarform
declare function polr(a as cpolar) as complex 'Polarform -> Gauß'sche Darstellung
'-------------------------------------------------------------------------------
function recp(a as complex) as cpolar
f.r=sqr(a.r*a.r+a.i*a.i)
f.a=sgn(a.i)*pi/2-atn(a.r/a.i)
return f
end function
function polr(a as cpolar) as complex
c.r=a.r*cos(a.a)
c.i=a.r*sin(a.a)
return c
end function
function real(a as complex) as double
return a.r
end function
function imag(a as complex) as double
return a.i
end function
function cabs(a as complex) as double
d=sqr(a.r*a.r+a.i*a.i)
return d
end function
function carg(a as complex) as double
d=atn(a.r/a.i)
return d
end function
function cadd(a as complex,b as complex) as complex
c.r=a.r+b.r
c.i=a.i+b.i
return c
end function
function csub(a as complex,b as complex) as complex
c.r=a.r-b.r
c.i=a.i-b.i
return c
end function
function cmul(a as complex,b as complex) as complex
c.r=a.r*b.r-a.i*b.i
c.i=a.i*b.r+a.r*b.i
return c
end function
function cdiv(a as complex,b as complex) as complex
c.r=a.i*b.i/(b.i*b.i+b.r*b.r)+a.r*b.r/(b.i*b.i+b.r*b.r)
c.i=a.i*b.r/(b.i*b.i+b.r*b.r)-a.r*b.i/(b.i*b.i+b.r*b.r)
return c
end function
function cpot(a as complex,b as complex) as complex
c.r=cos(ln(a.r*a.r+a.i*a.i)*b.i/2-(2*atn(a.r/a.i)-sgn(a.i)*pi)*b.r/2)*(a.r*a.r+a.i*a.i)^(b.r/2)*e^(atn(a.r/a.i)*b.i-sgn(a.i)*b.i*pi/2)
c.i=sin(ln(a.r*a.r+a.i*a.i)*b.i/2-(2*atn(a.r/a.i)-sgn(a.i)*pi)*b.r/2)*(a.r*a.r+a.i*a.i)^(b.r/2)*e^(atn(a.r/a.i)*b.i-sgn(a.i)*b.i*pi/2)
return c
end function
function clog(a as complex) as complex
c.r=ln(a.r*a.r+a.i*a.i)/2
c.i=(sgn(a.i)*pi/2-atn(a.r/a.i))
return c
end function
function csin(a as complex) as complex
c.r=sin(a.r)*e^a.i/2+sin(a.r)/(2*e^a.i)
c.i=cos(a.r)*e^a.i/2-cos(a.r)/(2*e^a.i)
return c
end function
function ccos(a as complex) as complex
c.r=cos(a.r)*((e^a.i)^2+1)/(2*e^a.i)
c.i=-sin(a.r)*((e^a.i)^2-1)/(2*e^a.i)
return c
end function
'-------------------------------------------------------------------------------
|
_________________ Danke an Volta für seine großartige MMX_fade function. *verneig*
Personal-DNA:
<script src="http://personaldna.com/h/?k=qtrCFboSuCOpFrX-OI-AADBA-f78d&t=Free-Wheeling+Leader">
</script>
Zitat: | Das Forum für den zum QBASIC kompatieblen open soure FreeBasic Kompiler. | by DJ. Peters |
|
Nach oben |
|
|
DB1BMN
Anmeldungsdatum: 17.12.2005 Beiträge: 24 Wohnort: Delmenhorst
|
Verfasst am: 23.08.2006, 23:56 Titel: |
|
|
Guten Abend,
sorry, dass ich mich jetzt erst melde, aber ich komm einfach nicht regelmäßig ins Forum.
Erst mal danke für eure Hinweise. Selbstverständlich weiß ich, dass man PRINT mit nem Fragezeichen abkürzen kann und REM durch ein Hochkomma, aber es hat sich bei mir eingebürgert, dass ich PRINT ausschreibe, dann find ich den Quelltext übersichtlicher. REM benutz ich um Programmteile zu kommentieren (beschreiben) und Hochkommata, wenn ich Programmteile unwirksam machen will. Aber das ist Geschmackssache.
Nun mal ein paar Fragen.
@ytwinky: Warum willst du den Realteil als double deklarieren, aber den imaginären bei single belassen? - Wenn schon denn schon.
@psygate: Deine Funktionen hab ich mal ebend kurz überflogen. Addition, Sytraktion, Multiplikation und Division hab ich in etwa ähnlich gelöst. Betrag und Argument wohl auch. Komplexe Exponenten und trigonometrische funktionen sehen interessant aus. Könnte man ja noch auf Logarithmen und hyperbolische Funktionen ausweiten. Darf ich fragen, womit du sonst komplexe Zahlen verrechnest? Ich arbeite gelegentlich mit MatLab.
Beste Grüße, Marek _________________
|
|
Nach oben |
|
|
dreael Administrator
Anmeldungsdatum: 10.09.2004 Beiträge: 2507 Wohnort: Hofen SH (Schweiz)
|
Verfasst am: 24.08.2006, 20:46 Titel: |
|
|
@psygate:
Kleine Optimierung: Die Konstante e musst Du nicht einmal definieren, verwende anstelle von e^x einfach die Funktion EXP(x). _________________ Teste die PC-Sicherheit mit www.sec-check.net |
|
Nach oben |
|
|
psygate
Anmeldungsdatum: 05.04.2005 Beiträge: 304 Wohnort: Wien und der Computer
|
Verfasst am: 25.08.2006, 12:49 Titel: |
|
|
danke! werd ich in der nächsten version einbauen. _________________ Danke an Volta für seine großartige MMX_fade function. *verneig*
Personal-DNA:
<script src="http://personaldna.com/h/?k=qtrCFboSuCOpFrX-OI-AADBA-f78d&t=Free-Wheeling+Leader">
</script>
Zitat: | Das Forum für den zum QBASIC kompatieblen open soure FreeBasic Kompiler. | by DJ. Peters |
|
Nach oben |
|
|
Cherry
Anmeldungsdatum: 20.06.2007 Beiträge: 249
|
Verfasst am: 02.07.2007, 10:42 Titel: |
|
|
wäre das nicht mit fake oop schöner? z.B. den Operator + overloaden, so dass man einfach comp_c = comp_a + comp_b statt comp_c = addc(comp_a, comp_b)
hm, ich werd das mal versuchen... |
|
Nach oben |
|
|
|