<?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[Standartabweichung, was mache ich falsch?]]></title><description><![CDATA[<p>Hallo, ich habe für mehrere größere Funktionen zwei Algorhythmen zu Berechung des Mittelwertes/ der Standartabweichung geschrieben.</p>
<pre><code>#include &lt;iostream&gt; 
#include &lt;cmath&gt; 

using namespace std;

double stdd(const double* values, const double&amp; size, const double&amp; mean){

	double result=0;

	for(int j=0; j &lt; size; j++){ 

		result+= pow((values[j]-mean),2) ;			

	}

	result=result/size; 

	result=sqrt(result);	                

	return result;

}

double mean(const double* values, const double&amp; size){

	double result=0;

	for(int j=0; j &lt; size; j++){ 

		result+=values[j];

	}

	result=result/size;

	return result;

}

int main(){

double array1[]={1,4,7,2,6,7,5,5,1,2,3,5,7,8,4,6,3,5,8,0,8};	
double* p1=&amp;array1[0];

double mean1=mean(p1,21);

cout &lt;&lt; mean1 &lt;&lt; endl;

double std1=stdd(p1,21,mean1);

cout &lt;&lt; std1 &lt;&lt; endl;

}
</code></pre>
<p>Leider stimmt irgendetwas mit der berechneten Standartabweichung nicht. Wenn ich die Werte für das obige Array manuell nachrechne, erhalte ich für<br />
mean1=4.6190;<br />
std1=2.41968;</p>
<p>Begehe ich irgendwo einen Rundungsfehler, dadurch dass ich 'float' als variablentypen gewählt habe?</p>
<p>Vielen Dank im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/261543/standartabweichung-was-mache-ich-falsch</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 07:28:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/261543.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 19 Feb 2010 23:46:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Standartabweichung, was mache ich falsch? on Fri, 19 Feb 2010 23:46:37 GMT]]></title><description><![CDATA[<p>Hallo, ich habe für mehrere größere Funktionen zwei Algorhythmen zu Berechung des Mittelwertes/ der Standartabweichung geschrieben.</p>
<pre><code>#include &lt;iostream&gt; 
#include &lt;cmath&gt; 

using namespace std;

double stdd(const double* values, const double&amp; size, const double&amp; mean){

	double result=0;

	for(int j=0; j &lt; size; j++){ 

		result+= pow((values[j]-mean),2) ;			

	}

	result=result/size; 

	result=sqrt(result);	                

	return result;

}

double mean(const double* values, const double&amp; size){

	double result=0;

	for(int j=0; j &lt; size; j++){ 

		result+=values[j];

	}

	result=result/size;

	return result;

}

int main(){

double array1[]={1,4,7,2,6,7,5,5,1,2,3,5,7,8,4,6,3,5,8,0,8};	
double* p1=&amp;array1[0];

double mean1=mean(p1,21);

cout &lt;&lt; mean1 &lt;&lt; endl;

double std1=stdd(p1,21,mean1);

cout &lt;&lt; std1 &lt;&lt; endl;

}
</code></pre>
<p>Leider stimmt irgendetwas mit der berechneten Standartabweichung nicht. Wenn ich die Werte für das obige Array manuell nachrechne, erhalte ich für<br />
mean1=4.6190;<br />
std1=2.41968;</p>
<p>Begehe ich irgendwo einen Rundungsfehler, dadurch dass ich 'float' als variablentypen gewählt habe?</p>
<p>Vielen Dank im Voraus!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858462</guid><dc:creator><![CDATA[Martin2000]]></dc:creator><pubDate>Fri, 19 Feb 2010 23:46:37 GMT</pubDate></item><item><title><![CDATA[Reply to Standartabweichung, was mache ich falsch? on Sat, 20 Feb 2010 00:21:54 GMT]]></title><description><![CDATA[<p>Du scheinst ein wenig verwirrt zu sein. Zum einen programmierst du C++ und gar kein ANSI C. Andererseits nimmst du doch kein float, sondern double. Und dann ist der Code total schrecklich formatiert (warum diese ganzen extra Leerzeilen?) Und dann ist die Länge doch gar keine Fließkommazahl, warum nimmst du also double (und dann noch unnötigerweise als const-reference?) und nicht size_t.</p>
<p>Bei mir kommen die Werte<br />
4.61905<br />
2.41968<br />
raus</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858472</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858472</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Sat, 20 Feb 2010 00:21:54 GMT</pubDate></item><item><title><![CDATA[Reply to Standartabweichung, was mache ich falsch? on Sat, 20 Feb 2010 00:22:10 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-1819.html" rel="nofollow">rüdiger</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-10.html" rel="nofollow">ANSI C</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858473</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858473</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Sat, 20 Feb 2010 00:22:10 GMT</pubDate></item><item><title><![CDATA[Reply to Standartabweichung, was mache ich falsch? on Sat, 20 Feb 2010 01:02:04 GMT]]></title><description><![CDATA[<p>Ich danke vielmals für Deine Hilfsbereitschaft, Rüdiger! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /><br />
In der Tat bin ich verwirrt, den Matlab gibt für selbige Werte nämlich<br />
mean=4.6190<br />
std=2.4794 aus.<br />
Da dieses Programm intern auch mit double-arrays rechnet, frage ich mich, was hier falsch läuft? Ist Matlab hier nicht korrekt oder begehe ich einen Denkfehler?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858476</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858476</guid><dc:creator><![CDATA[Martin2000]]></dc:creator><pubDate>Sat, 20 Feb 2010 01:02:04 GMT</pubDate></item><item><title><![CDATA[Reply to Standartabweichung, was mache ich falsch? on Sat, 20 Feb 2010 01:43:07 GMT]]></title><description><![CDATA[<p>Die Varianz ist definiert als</p>
<p><span class="katex-display"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mfrac><mrow><mn>1</mn></mrow><mrow><mi>n</mi><mo>−</mo><mn>1</mn></mrow></mfrac><mo>⋅</mo><msubsup><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></msubsup><mrow><mo>(</mo><msub><mi>x</mi><mi>i</mi></msub><mo>−</mo><mover accent="true"><mrow><mi>x</mi></mrow><mo>¯</mo></mover><msup><mo>)</mo><mn>2</mn></msup></mrow></mrow><annotation encoding="application/x-tex">\frac{1}{n-1}\cdot\sum\limits_{i=1}^n{(x_i - \bar{x})^2}
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:1.6513970000000002em;"></span><span class="strut bottom" style="height:2.929066em;vertical-align:-1.277669em;"></span><span class="base displaystyle textstyle uncramped"><span class="mord reset-textstyle displaystyle textstyle uncramped"><span class="sizing reset-size5 size5 reset-textstyle textstyle uncramped nulldelimiter"></span><span class="mfrac"><span class="vlist"><span style="top:0.686em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle textstyle cramped"><span class="mord textstyle cramped"><span class="mord mathit">n</span><span class="mbin">−</span><span class="mord mathrm">1</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.677em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle textstyle uncramped"><span class="mord textstyle uncramped"><span class="mord mathrm">1</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="mbin">⋅</span><span class="mop op-limits"><span class="vlist"><span style="top:1.1776689999999999em;margin-left:0em;"><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">i</span><span class="mrel">=</span><span class="mord mathrm">1</span></span></span></span><span style="top:-0.000005000000000143778em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span><span class="op-symbol large-op mop">∑</span></span></span><span style="top:-1.2500050000000003em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathit">n</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="mord displaystyle textstyle uncramped"><span class="mopen">(</span><span class="mord"><span class="mord mathit">x</span><span class="vlist"><span style="top:0.15em;margin-right:0.05em;margin-left:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle cramped"><span class="mord mathit">i</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="mbin">−</span><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="mord displaystyle textstyle cramped"><span class="mord mathit">x</span></span></span><span style="top:0em;margin-left:0.05556em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="accent-body"><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="mclose"><span class="mclose">)</span><span class="vlist"><span style="top:-0.413em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped"><span class="mord mathrm">2</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></span></span></span></span></p>
<p>Und die Standardabweichung als Wurzel davon. Dieses <strong>n-1</strong> ist wesentlich.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858485</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858485</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Sat, 20 Feb 2010 01:43:07 GMT</pubDate></item><item><title><![CDATA[Reply to Standartabweichung, was mache ich falsch? on Sat, 20 Feb 2010 12:02:35 GMT]]></title><description><![CDATA[<p>Es sieht immer besser aus, wenn man die Begriffe des eigenen Tätigkeitsumfeldes richtig schreibt:<br />
<a href="http://de.wiktionary.org/wiki/Algorithmus" rel="nofollow">http://de.wiktionary.org/wiki/Algorithmus</a><br />
<a href="http://de.wiktionary.org/wiki/Standard" rel="nofollow">http://de.wiktionary.org/wiki/Standard</a></p>
<p>Zum Programm:<br />
Mit <code>cout.precision(16);</code> kommt bei mir</p>
<p>4.619047619047619<br />
2.419684955411905</p>
<p>raus. Evtl. musst Du bei Matlab mal die Anzahl der Nachkommastellen erhöhen. Mit Matlab kenne ich mich aber nicht aus.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/12954">@nexus</a>: Laut wikipedia werden sowohl n-1 als auch n im Nenner verwendet:<br />
<a href="http://de.wikipedia.org/wiki/Empirische_Varianz" rel="nofollow">http://de.wikipedia.org/wiki/Empirische_Varianz</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1858558</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1858558</guid><dc:creator><![CDATA[gastgast]]></dc:creator><pubDate>Sat, 20 Feb 2010 12:02:35 GMT</pubDate></item></channel></rss>