Español
Fuente/ Codesnippets

Tschebyschow-Approximation: Vereinfachung komplizierter Formeln en fixen Grenzen

 

p.specht


Título de la ventana "Tschebyschow-Approximation uno benutzerdefinierten Funktion"
' Quelle: https://jean-pierre.moreau.pagesperso-orange.fr/Basic/tchebysh_bas.txt
' Transponiert después de XProfan 11.2a (D) Demo by P.Pájaro carpintero, Vienna/Austria
' No warranty whatsoever! Ohne jegliche Gewähr! Nutzung en propio Gefahr!
'********************************************************
'* Chebyshev Approximation of a user defined real       *
'* function FUNC(X) en double precision.                *
'* ---------------------------------------------------- *
'* SAMPLE RUN:                                          *
'* (Approximate sin(x) from x=0 to x=PI).               *
'*                                                      *
'* Chebyshev coefficients (N= 10 ):                     *
'*  0.944002431536470                                   *
'* -0.000000000000000                                   *
'* -0.499403258270407                                   *
'* -0.000000000000000                                   *
'*  0.027992079617546                                   *
'* -0.000000000000000                                   *
'* -0.000596695195801                                   *
'*  0.000000000000000                                   *
'*  0.000006704175524                                   *
'*  0.000000000000000                                   *
'*      X      Chebyshev Eval.   SIN(X)                 *
'*-----------------------------------------             *
'*  0.00000000   0.00000005   0.00000000                *
'*  0.34906585   0.34202018   0.34202014                *
'*  0.69813170   0.64278757   0.64278761                *
'*  1.04719755   0.86602545   0.86602540                *
'*  1.39626340   0.98480773   0.98480775                *
'*  1.74532925   0.98480773   0.98480775                *
'*  2.09439510   0.86602545   0.86602540                *
'*  2.44346095   0.64278757   0.64278761                *
'*  2.79252680   0.34202018   0.34202014                *
'*  3.14159265   0.00000005   0.00000000                *
'*                                                      *
'*                 Basic Release By J-P Moreau, Paris.  *
'*                          (www.jpmoreau.fr)           *
'*  XProfan 11-release by P.Pájaro carpintero, Vienna / Austria    *
'* ---------------------------------------------------- *
'* REFERENCE: "Numerical Recipes, The Art of Scientific *
'*             Computing By W.H. Press, B.P. Flannery,  *
'*             S.A. Teukolsky and W.T. Vetterling,      *
'*             Cambridge University Press, 1986"        *
'*             [BIBLI 08].                              *
'********************************************************
'PROGRAM PART 1: TESTCHEBY
'DEFDBL A-H, O-Z
'DEFINT I-N
Ventana de Estilo 24:Ventana 0,0-%maxx,%maxy-40:Font 2:Conjunto("Decimals",17)
Declarar N&,Zero!,Pi!,x0!,x1!, half!,two!,A!,B!,BmA!,BpA!
Declarar i&,j&,k&,y!,xx!, func!
Declarar fac!,sum! ,  f0$,f1$ ,dx!,x!
Declarar m&,d!,dd!,y2!,sv!, chebev!
ZERO! = 0 : Pi! = 4*Arctan(1)':Imprimir Pi!:WaitInput
N& = 10
Declarar C![N&], F![N&]
X0! = ZERO!: X1! = Pi!
Gosub "ES1000"'call CHEBFT(X0,X1,C,N)
Imprimir "\n\n Tschebyschow-Koeffizienten para Grad N = "; N&; \
":\n ----------------------------------------------------"
F0$ = "###0.###############;###0.###############;###0.###############"

WhileLoop n&:i&=&Loop

    Imprimir "   C(";int(i&-1);") = ";Formato$(F0$,C![I&])

EndWhile

WaitInput 5000
DX! = (X1!-X0!) / (N&-1)
X! = X0! - DX!
Font 0
PRINT "\n\n   x:    Tschebyschow-Desarrollo:   vgl.Orig SIN(X)     "
PRINT " ------------------------------------------------------------"
F1$ = "###0.########"

WhileLoop n&:i&=&Loop

    X! = X! + DX!
    ES2000'call CHEBEV(X0,X1,C,N,X)
    Imprimir "   ";Formato$(F1$, X!),
    Imprimir Tab(20);Formato$(F1$, CHEBEV!),
    Imprimir Tab(40);Formato$(F1$, Sin(X!) )

EndWhile

Beep: WaitInput
End'of main program
'user defined function FUNC(XX)

Proc ES500

    FUNC! = Sin(XX!)

ENDPROC

ES1000:
'subroutine CHEBFT(A,B,C,N)
'********************************************************
'* Chebyshev fit: Given a real function FUNC(X), lower  *
'* and upper limits of the interval [A,B] for X, and a  *
'* maximum degree N, this routine computes the N Cheby- *
'* shev coefficients Ck, such that FUNC(X) is approxima-*
'* ted by:  N                                           *
'*         [Sum Ck Tk-1(Y)] - C1/2, where X and Y are   *
'*         k=1                                          *
'* related by:     Y = (X - 1/2(A+B)) / (1/2(B-A))      *
'* This routine is to be used with moderately large N   *
'* (e.g. 30 or 50), the array of C's subsequently to be *
'* truncated at the smaller value m such that Cm+1 and  *
'* subsequent elements are negligible.                  *
'********************************************************
HALF! = 0.5: TWO! = 2
A! = X0!: B! = X1!
BMA! = HALF! * (B! - A!): BPA! = HALF! * (B! + A!)

WhileLoop n&:k&=&Loop

    Y! = Cos(Pi! * (K&-HALF!)/N&)
    XX! = Y! * BMA! + BpA!
    ES500
    F![K&] = FUNC!

EndWhile

FAC! = TWO! / N&

WhileLoop n&:j&=&Loop

    SUM! = ZERO!

    WhileLoop n&:k&=&Loop

        SUM! = SUM! + F![K&] * Cos((Pi!*(J&-1)) * ((K&-HALF!) / N&))

    EndWhile

    C![J&] = FAC! * SUM!

EndWhile

RETORNO

Proc ES2000'function CHEBEV(A,B,C,M,X)

    '**********************************************************
    '* Chebyshev evaluation: All arguments are input. C is a *
    '* array of Chebyshev coefficients, of length M, the first*
    '* M elements of Coutput from subroutine CHEBFT (which    *
    '* must have been called with the same A and B). The Che- *
    '* byshev polynomial is evaluated at a point Y determined *
    '* from X, A and B, and the resultado FUNC(X) is returned as *
    '* the function value.                                    *
    '**********************************************************

    If ((X!-A!) * (X!-B!)) > ZERO!

        Imprimir " X liegt no en!"
        Volver

    EndIF

    M& = N&
    D! = ZERO!: Dd! = ZERO!
    Y! = (TWO!*X!-A!-B!) / (B!-A!)'change of variable
    Y2! = TWO! * Y!

    WhileLoop m&,2,-1:j&=&Loop

        SV! = D!
        D! = Y2! * D! - Dd! + C![J&]
        Dd! = SV!

    EndWhile

    CHEBEV! = Y! * D! - Dd! + HALF! * C![1]

ENDPROC

 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
22.05.2021  
 



Zum Quelltext


Título del Tema, max. 100 Signo.
 

Systemprofile:

Kein Systemprofil creado. [anlegen]

XProfan:

 Contribución  Font  Smilies  ▼ 

Bitte registro en una Contribución a verfassen.
 

Tema opciones

1.397 Views

Untitledvor 0 min.
H.Brill08.06.2024
p.specht20.11.2021
Uwe Lang20.11.2021
Manfred Barei19.11.2021
Más...

Themeninformationen

Dieses Thema ha 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Autores  |  Chat  |  Política de Privacidad  |  Descargar  |  Entrance  |  Ayuda  |  Merchantportal  |  Pie de imprenta  |  Mart  |  Interfaces  |  SDK  |  Services  |  Juegos  |  Búsqueda  |  Support

Ein Projekt aller XProfan, el lo son!


Mi XProfan
Privado Noticias
Eigenes Ablageforum
Temas-Merkliste
Eigene Beiträge
Eigene Temas
Zwischenablage
Cancelar
 Deutsch English Français Español Italia
Traducciones

Política de Privacidad


Wir uso Cookies sólo como Session-Cookies wegen el technischen Notwendigkeit y en uns hay no Cookies de Drittanbietern.

Wenn du hier en unsere Webseite klickst oder navigierst, stimmst du unserer Erfassung de Informationen en unseren Cookies en XProfan.Net a.

Weitere Informationen a unseren Cookies y dazu, como du el Kontrolle darüber behältst, findest du en unserer nachfolgenden Datenschutzerklärung.


einverstandenDatenschutzerklärung
Yo möchte no Cookie