<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Optimales epsilon]]></title><description><![CDATA[<p>Hallo,</p>
<p>für numerisches Ableiten braucht man ja eine geeignete Schrittweite h. Dafür verwende ich diese Funktion (frei nach <a href="http://en.wikipedia.org/wiki/Numerical_differentiation#Practical_considerations_using_floating_point_arithmetic" rel="nofollow">Wikipedia</a>):</p>
<pre><code>template &lt;typename T&gt; T get_optimal_epsilon(T const &amp;x)
{
	return std::sqrt(std::numeric_limits&lt;T&gt;::epsilon())*std::abs(x);
}
</code></pre>
<p>Worauf im Artikel aber nicht eingegangen wird: Je näher <code>x</code> an 0 ist, desto schlechter wird das epsilon - für <code>x == 0</code> ist epsilon ebenfalls 0, was natürlich keinen Sinn mehr ergibt.</p>
<p>Wie kann/soll/muss man die Funktion erweitern damit dieser Fall vernünftig abgedeckt wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/326477/optimales-epsilon</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 23:47:45 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/326477.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 20 Jun 2014 09:30:36 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 09:30:36 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>für numerisches Ableiten braucht man ja eine geeignete Schrittweite h. Dafür verwende ich diese Funktion (frei nach <a href="http://en.wikipedia.org/wiki/Numerical_differentiation#Practical_considerations_using_floating_point_arithmetic" rel="nofollow">Wikipedia</a>):</p>
<pre><code>template &lt;typename T&gt; T get_optimal_epsilon(T const &amp;x)
{
	return std::sqrt(std::numeric_limits&lt;T&gt;::epsilon())*std::abs(x);
}
</code></pre>
<p>Worauf im Artikel aber nicht eingegangen wird: Je näher <code>x</code> an 0 ist, desto schlechter wird das epsilon - für <code>x == 0</code> ist epsilon ebenfalls 0, was natürlich keinen Sinn mehr ergibt.</p>
<p>Wie kann/soll/muss man die Funktion erweitern damit dieser Fall vernünftig abgedeckt wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404682</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404682</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 20 Jun 2014 09:30:36 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 10:06:02 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Wie kann/soll/muss man die Funktion erweitern damit dieser Fall vernünftig abgedeckt wird?</p>
</blockquote>
<p>Der Fall ist schon vernünftig abgedeckt. 0 kann exakt dargestellt werden, daher braucht man auch kein epsilon, daher finde ich epsilon = 0 für x == 0 vernünftig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404688</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404688</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Fri, 20 Jun 2014 10:06:02 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 11:19:23 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>Der Fall ist schon vernünftig abgedeckt. 0 kann exakt dargestellt werden, daher braucht man auch kein epsilon, daher finde ich epsilon = 0 für x == 0 vernünftig.</p>
</blockquote>
<p>Ne das ist für numerisches Ableiten nicht vernüntig (und darum gehts ja hier und in dem Wikipedia Artikel). Die Berechnungsvorschrift dafür lautet ja:</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mfrac><mrow><mi>d</mi></mrow><mrow><mi>d</mi><mi>x</mi></mrow></mfrac><mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo><mo>≈</mo><mfrac><mrow><mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo><mo>−</mo><mi>f</mi><mo>(</mo><mi>x</mi><mo>−</mo><mi>h</mi><mo>)</mo></mrow><mrow><mi>h</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">\frac{d}{dx}f(x) \approx \frac{f(x) - f(x - h)}{h}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:1.01em;"></span><span class="strut bottom" style="height:1.355em;vertical-align:-0.345em;"></span><span class="base textstyle uncramped"><span class="mord reset-textstyle textstyle uncramped"><span class="sizing reset-size5 size5 reset-textstyle textstyle uncramped nulldelimiter"></span><span class="mfrac"><span class="vlist"><span style="top:0.345em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle cramped"><span class="mord scriptstyle cramped"><span class="mord mathit">d</span><span class="mord mathit">x</span></span></span></span><span style="top:-0.22999999999999998em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle textstyle uncramped frac-line"></span></span><span style="top:-0.394em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord scriptstyle uncramped"><span class="mord mathit">d</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="sizing reset-size5 size5 reset-textstyle textstyle uncramped nulldelimiter"></span></span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">x</span><span class="mclose">)</span><span class="mrel">≈</span><span class="mord reset-textstyle textstyle uncramped"><span class="sizing reset-size5 size5 reset-textstyle textstyle uncramped nulldelimiter"></span><span class="mfrac"><span class="vlist"><span style="top:0.345em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle cramped"><span class="mord scriptstyle cramped"><span class="mord mathit">h</span></span></span></span><span style="top:-0.22999999999999998em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle textstyle uncramped frac-line"></span></span><span style="top:-0.485em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord scriptstyle uncramped"><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">x</span><span class="mclose">)</span><span class="mbin">−</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">x</span><span class="mbin">−</span><span class="mord mathit">h</span><span class="mclose">)</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span>​</span></span></span><span class="sizing reset-size5 size5 reset-textstyle textstyle uncramped nulldelimiter"></span></span></span></span></span></p>
<p>wobei h ein möglichst optimales epsilon sein sollte um den Fehler klein zu halten. Wenn h jetzt Null ist habe ich 0/0, also einen undefinierten Ausdruck -&gt; ganz schlecht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404708</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404708</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 20 Jun 2014 11:19:23 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 13:54:44 GMT]]></title><description><![CDATA[<p><s>Errechnet man sich das h nicht durch gegebene Parameter?<br />
Z.B. willst du für einen Bereich [a, b) ableiten (oder integrieren) und zwar mit n Punkten, dann könntest du h = (b-a)/n setzen.</s></p>
<p>Edit: das war Bullshit</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404715</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404715</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 20 Jun 2014 13:54:44 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 13:10:06 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Errechnet man sich das h nicht durch gegebene Parameter?<br />
Z.B. willst du für einen Bereich [a, b) ableiten (oder integrieren) und zwar mit n Punkten, dann könntest du h = (b-a)/n setzen.</p>
</blockquote>
<p>Äh nein, was für Parameter? Die Ableitung (!= integrieren) berechnet man ja an einer Stelle (nicht in einem Interval). In C++ ausgedrückt:</p>
<pre><code>double f(double x) { return x*x*x; } // f(x) = x^3

double derivative(std::function&lt;double(double)&gt; const &amp;f_, double x_, double epsilon_)
{
    return (f_(x_) - f_(x_ - epsilon_))/epsilon_;
}

int main()
{
    std::cout &lt;&lt; derivative(f, 2.0, 1.0e-7); // Ableitung von f an der Stelle 2.0 mit einem epsilon von 1.0e-7
}
</code></pre>
<p>Problem dabei ist das epsilon, das ja in Abhängigkeit des Wertes x unterschiedlich groß sein muss um optimal genaue Ergebnisse zu erhalten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404733</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404733</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 20 Jun 2014 13:10:06 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 13:24:42 GMT]]></title><description><![CDATA[<p>für x=0 kannst du dann das Maschinen-Epsilon nehmen:</p>
<pre><code>template &lt;typename T&gt; T get_optimal_epsilon(T const &amp;x) 
{ 
    return x==0 ?
       std::numeric_limits&lt;T&gt;::epsilon() :
       std::sqrt(std::numeric_limits&lt;T&gt;::epsilon())*std::abs(x); 
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2404739</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404739</guid><dc:creator><![CDATA[oenone]]></dc:creator><pubDate>Fri, 20 Jun 2014 13:24:42 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 13:55:27 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Errechnet man sich das h nicht durch gegebene Parameter?<br />
Z.B. willst du für einen Bereich [a, b) ableiten (oder integrieren) und zwar mit n Punkten, dann könntest du h = (b-a)/n setzen.</p>
</blockquote>
<p>Äh nein, was für Parameter? Die Ableitung (!= integrieren) berechnet man ja an einer Stelle (nicht in einem Interval).</p>
</blockquote>
<p>Ja verwechselt mim Integrieren. War etwas durcheinander, weil wir grad in der Uni ne ähnliche Aufgabe halt mit Integralen machten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404749</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404749</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Fri, 20 Jun 2014 13:55:27 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 14:31:28 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Ja verwechselt mim Integrieren. War etwas durcheinander, weil wir grad in der Uni ne ähnliche Aufgabe halt mit Integralen machten.</p>
</blockquote>
<p>Np, immerhin hast du integrieren und nicht &quot;aufleiten&quot; gesagt. Da rastet unser Prof immer aus <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>oenone schrieb:</p>
<blockquote>
<p>für x=0 kannst du dann das Maschinen-Epsilon nehmen:</p>
<pre><code>template &lt;typename T&gt; T get_optimal_epsilon(T const &amp;x) 
{ 
    return x==0 ?
       std::numeric_limits&lt;T&gt;::epsilon() :
       std::sqrt(std::numeric_limits&lt;T&gt;::epsilon())*std::abs(x); 
}
</code></pre>
</blockquote>
<p>He, scheint zu klappen. Danke <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
<p>Mal noch ne Frage, optimiert der Compiler das <code>std::sqrt(std::numeric_limits&lt;T&gt;::epsilon())</code> eigentlich weg (ist ja ne konstante) oder sollte ich das lieber in einer static Variable ablegen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404755</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404755</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 20 Jun 2014 14:31:28 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 14:34:27 GMT]]></title><description><![CDATA[<p>Dumme Frage aber:<br />
Was soll <code>sqrt(eps)</code> sein / bezwecken? <code>eps</code> ist ja schon der kleinste Wert...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404757</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404757</guid><dc:creator><![CDATA[Apfelkuchen um 4]]></dc:creator><pubDate>Fri, 20 Jun 2014 14:34:27 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 14:39:23 GMT]]></title><description><![CDATA[<p>Wurzel aus 0 &lt; Zahl &lt; 1 wird größer? Habe aber auch den Sinn nicht verstanden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404759</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404759</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Fri, 20 Jun 2014 14:39:23 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 14:41:34 GMT]]></title><description><![CDATA[<p>nwp3 schrieb:</p>
<blockquote>
<p>Wurzel aus 0 &lt; Zahl &lt; 1 wird größer? Habe aber auch den Sinn nicht verstanden.</p>
</blockquote>
<p>Oh, wie dumm, natürlich nicht. Kommt vom ganzen Apfelkuchen!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404760</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404760</guid><dc:creator><![CDATA[Apfelkuchen um 4]]></dc:creator><pubDate>Fri, 20 Jun 2014 14:41:34 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 15:00:03 GMT]]></title><description><![CDATA[<p>oenone schrieb:</p>
<blockquote>
<p>für x=0 kannst du dann das Maschinen-Epsilon nehmen:</p>
<pre><code>template &lt;typename T&gt; T get_optimal_epsilon(T const &amp;x) 
{ 
    return x==0 ?
       std::numeric_limits&lt;T&gt;::epsilon() :
       std::sqrt(std::numeric_limits&lt;T&gt;::epsilon())*std::abs(x); 
}
</code></pre>
</blockquote>
<p>Naja, irgendwie sollte die Funktion schon den Anschein von Stetigkeit bewahren, oder?</p>
<p>Wikipedia bezieht sich an der Stelle auf Numerical Recipes in C: <a href="http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf" rel="nofollow">http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf</a> Abschnitt 5.7. Ich würd dort mal nachlesen und versuchen, das nachzuvollziehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404761</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404761</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Fri, 20 Jun 2014 15:00:03 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 15:17:51 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Wikipedia bezieht sich an der Stelle auf Numerical Recipes in C: <a href="http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf" rel="nofollow">http://www2.units.it/ipl/students_area/imm2/files/Numerical_Recipes.pdf</a> Abschnitt 5.7. Ich würd dort mal nachlesen und versuchen, das nachzuvollziehen.</p>
</blockquote>
<p>Ja, das kenn ich schon, leider steht da nix genaueres zu dem Thema außer <em>&quot;except near x = 0 where some other estimate of the typical x scale should be used&quot;</em>. Was für eine Schätzung benutzt werden sollte lassen sie aber einfach mal unter den Tisch fallen...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404763</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404763</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 20 Jun 2014 15:17:51 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 15:20:43 GMT]]></title><description><![CDATA[<p>Apfelkuchen um 4 schrieb:</p>
<blockquote>
<p>Dumme Frage aber:<br />
Was soll <code>sqrt(eps)</code> sein / bezwecken? <code>eps</code> ist ja schon der kleinste Wert...</p>
</blockquote>
<p>Nein, ist es nicht.</p>
<blockquote>
<p>Machine epsilon (the difference between 1 and the least value greater than 1 that is representable).</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2404765</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404765</guid><dc:creator><![CDATA[dat epsilon]]></dc:creator><pubDate>Fri, 20 Jun 2014 15:20:43 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 15:27:06 GMT]]></title><description><![CDATA[<p>happystudent schrieb:</p>
<blockquote>
<p>Ja, das kenn ich schon, leider steht da nix genaueres zu dem Thema außer <em>&quot;except near x = 0 where some other estimate of the typical x scale should be used&quot;</em>. Was für eine Schätzung benutzt werden sollte lassen sie aber einfach mal unter den Tisch fallen...</p>
</blockquote>
<p>Interessant dabei finde ich vor allem, dass das x in der Formel eigentlich nicht für das Argument steht, sondern für die Krümmung der Funktion, und das Argument nur aus pragmatischen Gründen benutzt wird, weil man meistens die Krümmung nicht kennt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404767</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404767</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Fri, 20 Jun 2014 15:27:06 GMT</pubDate></item><item><title><![CDATA[Reply to Optimales epsilon on Fri, 20 Jun 2014 16:27:28 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Interessant dabei finde ich vor allem, dass das x in der Formel eigentlich nicht für das Argument steht, sondern für die Krümmung der Funktion, und das Argument nur aus pragmatischen Gründen benutzt wird, weil man meistens die Krümmung nicht kennt.</p>
</blockquote>
<p>Ja, es ist eine Approximation des wirklich besten epsilons... Problem ist auch dass es nicht nur für x exakt 0 Probleme gibt, sondern schon in der näheren Umgebung von 0...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2404782</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2404782</guid><dc:creator><![CDATA[happystudent]]></dc:creator><pubDate>Fri, 20 Jun 2014 16:27:28 GMT</pubDate></item></channel></rss>