English
Source / code snippets

Differentialgleichungen n-ter Order solve: Størmer-Verlet Leapfrog-method

 

p.specht

Differentialgleichungen 2. or. n.ter Order solve
=====================================
the take action, with the full cover "Newton-Størmer-Verlet leapfrog method" means, finds itself in almost all Physics- and Game-Engines to Berechnung the Newtonschen Bewegungsgesetze. with others Worten: everything what explode and then runterfällt is with this deutlichen, but still not To zeitintensiven improvement the simplest all suitable Algorithms (Explizites Euler-take action) accounts. the nachstehende Program allows a judgement the Realitätsnähe, because too The analytisch-exakte Solution the task famous is. Fünfstellige accuracy reicht there well.

it deals itself circa a Rückübersetzung of Fortran-90 to XProfan-11, with all Tücken, therefore: REINE DEMO OHNE JEDWEDE GEWÄHR!
Window Title "Anfangswertproblem of/ one Differentalgleichung 2. Order solve to Størmer-Verlet"
' ---------------------------------------------------------------------------------------------
' from Fortran90 to XProfan-11 Translated 2014-08 of P. woodpecker, Wien (Österreich)
' No however geartete Gewähr! usage on alleinige menace de(s|r) users(s|in)!
' fountain: https://jean-pierre.moreau.pagesperso-orange.fr/Cplus/stormer.txt
'**********************************************************************************************
'*  Differential equation y"=f(x,y,y') by  Størmer's method  *
' (erweiterbar on allg. Verlet type, z.B. y'''[...]=f(x,y,y',y''[,y''',...])
'* --------------------------------------------------------- *
'* SAMPLE RUN (BEISPIEL)                                     *
'* resolve  y" = 8*y*y / (1+2*x) from x=0 to x=1                *

proc G :parameters x!,y!,z!'= x, y, y'

    return 8*sqr(y!)/(1+2*x!)

endproc

proc F :parameters x!,y!,z!'= x, y, y'

    return z!

endproc

'* with initial conditions: x(0)=0, y(0)=1 and y'(0)=-2      *
Declare x![4],y![4],z![4],h!' Initial conditions:
x![1]= 0
y![1]= 1
z![1]=-2' dy/dt
h!=0.01' Step
'*  Compare to exact solution   y = 1/(1+2*x)                *

Proc Fx :parameters x!' Exact Solution:

    return 1/(1+2*x!)

endproc

'* --------------------------------------------------------- *
'*   Differential equation y"=f(x,y,y') by Stormer's method  *
'* --------------------------------------------------------- *
'*        X           Y           Y exact         Error      *
'*     0.000       1.000000       1.000000     0.0000000000  *
'*     0.010       0.980392       0.980392     0.0000000001  *
'*     0.020       0.961538       0.961538     0.0000000295  *
'*     0.030       0.943396       0.943396     0.0000000457  *
'*     0.040       0.925926       0.925926     0.0000000974  *
'*     0.050       0.909091       0.909091     0.0000001285  *
'*     ...         ...            ...          ...           *
'*     0.950       0.344866       0.344828     0.0000381695  *
'*     0.960       0.342505       0.342466     0.0000388874  *
'*     0.970       0.340176       0.340136     0.0000396196  *
'*     0.980       0.337878       0.337838     0.0000403406  *
'*     0.990       0.335612       0.335570     0.0000410721  *
'*     1.000       0.333375       0.333333     0.0000418231  *
'*                                                           *
'*   F90 Release By J-P Moreau, Paris (www.jpmoreau.fr).     *
'*************************************************************
Window Style 24:font 2:set("decimals",16):Window 0,0-%maxx,%maxy-40
Declare c![4],a1!,a2!,a3!,yex!,k&,it! , x1!,y1!,z1!
a1!= 1.083333333333333333 : a2!=-2*(a1!-1) : a3!= a1!-1
clearclip
print "\n------------------------------------------------------------------------------"
print "       Differentialgleichung y''=f(x,y,y') with Störmer's method solve "
print "------------------------------------------------------------------------------\n"
print "         X                   Y                  Y exact                Error\n"
putclip " X | Y | Y_exact | Error \n"
yex!=Fx(x![1]):print tab(2);x![1],tab(22);y![1],tab(42);yex!,tab(62);er!
putclip st$(x![1])+"|"+st$(y![1])+"|"+st$(yex!)+"|"+st$(it!)+"\n"
' Runge-Kutta for ridge 2 steps:

whileloop 1,2:k&=&Loop

    RK4D2 x![k&],y![k&],z![k&],h!
    x![k&+1]=x1!
    y![k&+1]=y1!
    z![k&+1]=z1!
    yex!=Fx(x![k&+1])
    it!=abs(yex!-y![k&+1])
    print tab(2);x![k&+1],tab(22);y![k&+1],tab(42);yex!,tab(62);er!
    putclip st$(x![k&+1])+"|"+st$(y![k&+1])+"|"+st$(yex!)+"|"+st$(it!)+"\n"

endwhile

REPEAT'Main loop G10:

    whileloop 2,4:k&=&Loop

        c![k&]=G( x![5-k&],y![5-k&],z![5-k&] )

    endwhile

    y![4]=2*y![3]-y![2]+sqr(h!)*(a1!*c![2]+a2!*c![3]+a3!*c![4])
    x![4]=x![3]+h!
    yex!=Fx(x![4])
    it!=abs(yex!-y![4])
    print tab(2);x![4],tab(22);y![4],tab(42);yex!,tab(62);er!
    putclip st$(x![4])+"|"+st$(y![4])+"|"+st$(yex!)+"|"+st$(it!)+"\n"

    Whileloop 1,3:k&=&Loop'for next step umkopieren:

        x![k&]=x![k&+1]
        y![k&]=y![k&+1]

    endwhile

    if %csrlin>40:waitinput 4000:cls

        print "\n         X                   Y                  Y-exakt                Error\n"

    endif

UNTIL x![3]>1'end x value = 1

print "\n EOF"
Print " Resultate in Clipboard!"
Waitinput
END

PROC RK4D2 :parameters x!,y!,z!,h!',x1!,y1!,z1!

    declare c1!,d1!,c2!,d2!,c3!,d3!,c4!,d4!
    c1!=F(x!,y!,z!)
    d1!=G(x!,y!,z!)
    c2!=F(x!+h!/2, y!+h!/2*c1!, z!+h!/2*d1!)
    d2!=G(x!+h!/2, y!+h!/2*c1!, z!+h!/2*d1!)
    c3!=F(x!+h!/2, y!+h!/2*c2!, z!+h!/2*d2!)
    d3!=G(x!+h!/2, y!+h!/2*c2!, z!+h!/2*d2!)
    c4!=F(x!+h!,   y!+h!*c3!,   z!+h!*d3!  )
    d4!=G(x!+h!,   y!+h!*c3!,   z!+h!*d3!  )
    x1!=x!+h!
    y1!=y!+h!*(c1!+2*c2!+2*c3!+c4!)/6
    z1!=z!+h!*(d1!+2*d2!+2*d3!+d4!)/6

endproc

PROGEND
'{=============================================================================================
'    Stormer, aka Newton-Størmer-Verlet leapfrog method
' =============================================================================================
' Namensgebung: The Algorithmus self goes back on Delambre (1791), oftmals wiederentdeckt,
' u.a. 1907 through Carl Størmer, 1909 through Cowell and Cromlin, 1967 populär through Loup Verlet.
' correct The explizite Euler-method without too high additional expenditure. often in Physics-Engines
' to find. details see https://en.wikipedia.org/wiki/Verlet_integration
' =============================================================================================
' method STORMER (aka Newton-Störmer-Verlet-leapfrog method):
' resolve Y"=f(x,y,y') with given Anfangsbedingungen
' ----------------------------------------------------------------------------------
' an Differentialgleichung 2. Order (Y") can supplant go through one
' Differentialgleichungs-SYSTEM bestehend from 2 Gleichungen 1. Order!
' If means y"=f(x,y,y') given is with y(a=Anfang) and y'(a=Anfang), then can
' these Formel through Substitution u = y' transform To:
'
'                    | u'=f(x,y,u)
'                    | y'=u
'                    | with the new Anfangsbedingungen y(a), u(a)
'
' begin we The Betrachtung with jener special shape the Taylor-development,
' with the the remainder as Integral displayed becomes (Wiki: Taylorentwicklung)
'                                       x+h
'           y(x+h) = y(x) + h * y'(x) + INTEGRAL (x+h-t)*y"(t).dt
'                                        x
' through Verbringung the Nichtintegral-Terme on The left Page and Aufspaltung
' the 'Restfehler-Integrals' in two pieces it can shape too following-
' maßen displayed go:
'                                        x+h              x-h
'           y(x+h) - 2y(x) + y(x-h) = INTEGRAL ...  +  INTEGRAL ...
'                                         x                x
' for the second Integral becomes The Variable x now substituiert through:  u = 2*x-t
' then counts on reason the Kettenregel:
'           x-h                              x+h
'         INTEGRAL (x-h-t) * y"(t).dt = - INTEGRAL (x+h-u)*y"(u).You
'            x                                x
' and the Ableitung .You back-substituiert (To .-dt) supply then:
'                                    x+h
'           du=-dt ==>           = INTEGRAL (x+h-t)*y"(2x-t).dt
'                                     x
' accordingly can write:              x+h
'           y(x+h) - 2*y(x) + y(x-h) = INTEGRAL (x+h-t)*[y"(t)+y"(2x-t)].dt
'                                         x
' now use we under Info, that Yes y"(x)=f(x,y,y') counts, subesquent expression
' as Interpolationspolynom:
'                             x_n+1
'     y_n+1 - y_n + y_n-1 = INTEGRAL (x_n+1 - t)*[P(t)+P(2*x_n - 1)].dt  = ...
'                              x_n
'               x_n+1
'    ...= h^2*INTEGRAL (x_n+1 -t)*[O_00*Div(f_n)+O_11*Div(f_n)+O_22*Div(f_n)].dt ,
'                x_n
'                         1           |(-s) (m)|
' where O_mm  = -1^m * INTEGRAL (1-s)*|    +   | .ds
'                         0           |( m) (s)|
'                                               (vgl. too 'Adams-Bashford-method')
' latter bring us finally To STORMER's Formeln:
' ==================================================================================
' Explizit words:  y_n+1 -2*y_n + y_n-1 = h^2/12 * [13 * f_n - 2*f_n-1 + f_n-2]
' the interessierende   y_n+1 = h^2/12 * [13 * f_n - 2*f_n-1 + f_n-2]+ 2*y_n - y_n-1
' (f_n+1 must not famous his: Prognoserechnung with currently ergänzten Zeitreihen)
' ----------------------------------------------------------------------------------
' or implizit:        y_n+1 -2*y_n + y_n-1 = h^2/12 * [f_n+1 + 10 * f_n + f_n-1 ]
'}==================================================================================
 
XProfan 11
Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'...
05/14/21  
 



Zum Quelltext


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

1.696 Views

Untitledvor 0 min.
H.Brill12/07/23
p.specht07/01/22
E.T.11/20/21
Manfred Barei11/19/21
More...

Themeninformationen

this Topic has 1 subscriber:

p.specht (1x)


Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie