program LnxTox; type funktie = function(x : double) : double; var x : double; function origineel(x : double) : double; far; { The original problem: ln(x)^x = x^ln(x) Logarithm both sides: x*ln(ln(x)) = ln(x)^2 Substitute y = ln(x): exp(y)*ln(y) = y^2 } begin origineel := exp(x)*ln(x) - sqr(x); { Trial values: x = 1 ==> e.ln(1) - sqr(1) = 0 - 1 < 0 x = e ==> e^e.ln(e) - sqr(e) = e^e - e^2 > 0 because e > 2 ==> e^e > e^2 Hence the minimum is between x = 1 and x = e } end; function afgeleide(x : double) : double; far; begin afgeleide := exp(x)/x + exp(x)*ln(x) - 2*x; end; const nauw : double = 1.E-13; function Newton(P,eps : double; verloop, helling : funktie) : double; { The Newton-Rhapson method is a numerical algorithm for finding zeros p of a function f(x) . The gist of the method is to draw successive tangent lines and determine where these lines intersect the x-axis: y - f(p_n) = f'(p_n).(x - p_n) where y = 0 and x = p_(n+1) ==> p_(n+1) = p_n - f(p_n)/(f'(p_n) } var x : double; begin x := P; while abs(verloop(x)) > eps do x := x - verloop(x) / helling(x); Newton := x; end; begin Writeln; Writeln(' Newton:'); x := Newton((1+exp(1))/2, nauw, origineel, afgeleide); Writeln(' x = ',x,' giving: '); Writeln(' y = ',origineel(x),' = exp(x)*ln(x) - sqr(x) = 0'); Writeln; Writeln(' Solution:'); Writeln(' x = ',exp(x),' := exp(x) = exp(',x,')'); x := exp(x); Writeln(' Giving:'); Writeln(' ln(',x,')^(',x,') = '); Writeln(' (',x,')^ln(',x,')'); Writeln(' with Error:'); Write(' exp(x*ln(ln(x))) - exp(sqr(ln(x))) = '); Writeln((exp(x*ln(ln(x))) - exp(sqr(ln(x))))); Writeln; end.