| |
|
|
p.specht
| the Newton-Raphson-take action functions too with functions in 2 Dimensionen, speak: z =Z(x,y). unfortunately is the take action insofern sooner demanding, as The undertow. partiellen Ableitungen the known function (to x and to y) ditto famous his should. with not too complicated Formeln ought to the but weg. lying though only numbers / Datensätze, z.B. with Messwerten over 2 Dimensionen to, then recommend itself others, mere numerische take action, z.B. Nelder-Mead udgl.
Info: The here einprogrammierten functions get chosen, around the Auswirkungen the heiklen electoral the Startpunktes the Result darzustellen.
Window Title "Gradientenabstieg (Newtonverfahren in 2 Dimensionen)"
AppendMenuBar 100,"Geg.: Z(x,y)=(x+sin(y))*exp(-sqr(x)*-sqr(y)) Ges.: place the local Minimus"
Window 0,0-%maxx,%maxy-40:font 2
declare z!,x!,y!,xh&,yh&,f!,g!,s!
xh&=width(%hwnd)\2:yh&=height(%hwnd)\2
g!=1.5:s!=0.1:f!=220
proc Z :parameters x!,y!
return (x!+sin(y!))*exp(-sqr(x!)-sqr(y!))
endproc
proc dZdx :parameters x!,y!
return exp(-sqr(y!)-sqr(x!))*(1-2*x!*(x!+sin(y!)))
endproc
proc dZdy :parameters x!,y!
return exp(-sqr(y!)-sqr(x!))*(cos(y!)-2*y!*(x!+sin(y!)))
endproc
' ------ Z-area present ----
cls
x!=-g!:Repeat
y!=-g!:While y!<=g!
z!=Z(x!,y!)
usepen 0,7+7*z!,rgb(0,0,400*z!)
line xh&+x!*f!+z!*7,(yh&-y!*f!-z!*11) - xh&+x!*f!,yh&-y!*f!
y!=y!+s!:endwhile
x!=x!+s!:until x!>=g!
'-------------------------------------------------------
' Gradientenabstieg
'-------------------------------------------------------
declare gstep!,xx!,yy!,xxo!,yyo!,dx!,dy!,dz!,eps!,n&,xxx!,yyy!
gstep!=0.15
whileloop 50,-50,-5:yyy!=&Loop/50
whileloop -50,50,5 :xxx!=&Loop/30
xx!=xxx!
yy!=yyy!'Startpunkt
n&=0
REPEAT
dx!=dZdx(xx!,yy!)
dy!=dZdy(xx!,yy!)
xxo!=xx!:yyo!=yy!
xx!=xx!-dx!*gstep!
yy!=yy!-dy!*gstep!
usepen 0,4,rgb(255,0,0)
line xh&+xx!*f!,(yh&-yy!*f!)-xh&+xx!*f!,yh&-yy!*f!
locate 2,2:print xx!,yy!,Z(xx!,yy!),n&;" "
inc n&
UNTIL ((xx!=xxo!) and (yy!=yyo!)) or (n&>=250)
WEND
WEND
beep
waitinput
End
|
|
|
| XProfan 11Computer: Gerät, daß es in Mikrosekunden erlaubt, 50.000 Fehler zu machen, zB 'daß' statt 'das'... | 05/28/21 ▲ |
|
|
|