+
2
|
list
|
skin
|
login
|
editor
α-wwwiki
::
derivee
user:none
(4346 bytes)
_h1 f'(x) (& [[differential]], [[curry]]) {div {@ style="color:red;text-align:center;"} !!! PAGE UNDER CONSTRUCTION !!!} _p Computing the first derivee of any function at a given point : _h3 using [[define]] {pre °° 1) defining : {define fprime (func x) •• // {/ {- {func {+ x dx} {func {- x dx}} {* 2 dx}} var x = parseFloat( x ), dx = 0.0001, xp = x+dx, xm = x-dx, dxx = 2*dx; return '{/ {- {'+func+' '+xp+'} {'+func+' '+xm+'} } '+dxx+'}' ; ••}°° -> {define fprime (func x) °° // {/ {- {func {+ x dx} {func {- x dx}} {* 2 dx}} var x = parseFloat( x ), dx = 0.0001, xp = x+dx, xm = x-dx, dxx = 2*dx; return '{/ {- {'+func+' '+xp+'} {'+func+' '+xm+'} } '+dxx+'}' ; °°} 2) calling : 21) with a predefined function : °°{define myfunc (x) return x*x*x; }°° -> {define myfunc (x) return x*x*x; } °°{fprime myfunc 2}°° -> {fprime myfunc 2} // should be 3*x^2 = 12 22) with a lambda function : °°{fprime {lambda (x) return x*x*x;} 2}°° -> {fprime {lambda (x) return x*x*x;} 2} } _h3 using [[defun]] is easier {pre 1) define : °°{defun delta (func x) •• {/ {- {func {+ x 0.0001}} {func {- x 0.0001}}} {* 2 0.0001}} ••}°° -> {defun delta (func x) °° {/ {- {func {+ x 0.0001}} {func {- x 0.0001}}} {* 2 0.0001}} °°} 2) calling : 21) with a lambda function : °°{delta {lambda (x) return x*x*x;} 2}°° -> {delta {lambda (x) return x*x*x;} 2} or with a function defined by defun : °°{defun cubic (x) ••{* x x x}••}°° -> {defun cubic (x) °°{* x x x}°°} °°{delta cubic 2}°° -> {delta cubic 2} } _h3 testing another code _p Computing for a Math function f(x) of Javascript the derivee for a given x and dx. {pre 1) defining : °° {define derivee (fun dx x) •• return (function (f) { return (function (dx) { return (function (x) { return ( f(x+dx) - f(x-dx) )/(2*dx); })(parseFloat(x)); })(parseFloat(dx)); })(function (x) { return Math[fun](x); }); ••}°° -> {define derivee (fun dx x) °° return (function (f) { return (function (dx) { return (function (x) { return ( f(x+dx) - f(x-dx) )/(2*dx); })(parseFloat(x)); })(parseFloat(dx)); })(function (x) { return Math[fun](x); }); °°} °°{derivee sin 0.01 {{lambda () return Math.PI;}}}°° -> {derivee sin 0.01 {{lambda () return Math.PI;}}} // should be d(sin(x))/dx = cos(x) for x=PI -> -1 } _p Only for memory ! _h3 Some more tests _p Open the page's code in order to analyze the following tests. {pre 1) value of the derivee of a function square(x) at a given x {define compute1 ()°° var dérivée = function(f,x,dx) { return (f(x+dx)-f(x-dx))/(2*dx); } var square = function(x){ return x*x ; }; return dérivée(square, 30, 0.0000001); °°} {compute1} // should be 60 (x^2 -> 2*x -> 60 for x=30 2) function derivee of a function square and its value at a given x {define compute2 (x)°° var dérivée = function(f,dx){ return function(x){ return (f(x+dx)-f(x-dx))/(2*dx); }; } var square = function(x){ return x*x ;} x = parseFloat(x); if (!isNaN(x)) return (dérivée(square, 0.0000001))(x); else return dérivée(square, 0.0000001); °°} {compute2} // it's a function {compute2 30} // it's a value 3) 1st, 2nd, 3rd and 4th derivatives of Math.sin at Math.PI/2 {define compute3 ()°° function D(f){ return function(dx){ return function(f){ return function(x){ return (f(x+dx)-f(x-dx))/(2*dx); }}}(0.001)(f); } var f = Math.sin; var x = Math.PI/2; var str = 'f1: ' + D(f)(x) + ' | ' + 'f2: ' + D(D(f))(x) + ' | ' + 'f3: ' + D(D(D(f)))(x) + ' | ' + 'f4: ' + D(D(D(D(f))))(x); return str; °°} {compute3} } _h3 the goal _p As it was known in [[lambdaway|../lambdaway_2.0/?view=diff_int]], the code should allow composing derivees (second, third, ...). The function "derivee" should return a function ! {pre °°{derivee {derivee {derivee func}}} -> the function thirdderivee then {thirdderivee x} -> a value°° } _p Some work to do ... Any idea ? Tell me in page [[forum]] :)