<?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[Wert eines Arrays verändert sich ohne Veränderung]]></title><description><![CDATA[<p>S und U sollen jeweils Arrays von Double-Arrays sein. Ich will also 0...t Arrays, die wiederum jeweils Länge (2^t) haben.<br />
Da ich die Länge manuell eingegeben haben will, muss ich mir die dynamisch definieren.<br />
Wäre cool wenn ihr mir schonmal sagen ob ich die richtig definiert habe.<br />
Solange ich nur S definiere klappt auch alles aber, sobald ich U definiere ändern sich Wert in S.<br />
Ich hänge euch unten mal den Output an, in dem man sieht, dass bevor ich U definiere alles stimmt, dann aber S[2][2] plötzlich verrückt spielt.</p>
<p>Liebe Grüße</p>
<pre><code class="language-cpp">if (kind==&quot;American&quot;) {

			double** S = new double*[t+1];
			for(e=0; e&lt;=t; e++){
				S[e]= new double[2^e];
			}
			S[0][0]=S0;

		if (art==&quot;Call&quot;) {
			for (time=1; time&lt;=t; time++) 
			{
				for (a=0; a&lt;pow(2.0,time); a++)  
				{
					if (a % 2 == 0)
					{
				S[time][a]=S[time-1][a/2]*(1+u);
					}
						else S[time][a]=S[time-1][(a-1)/2]*(1+d);
						cout &lt;&lt; &quot;S&quot; &lt;&lt; t &lt;&lt; a &lt;&lt; &quot;:&quot; &lt;&lt; S[t][a] &lt;&lt; endl;
				}
			}

			double** U = new double*[t+1];
			for(c=0; c&lt;=t; c++){
				U[c]= new double[2^c];
			}
			cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
				for (a=0; a &lt; pow(2.0,t); a++) {
			cout &lt;&lt; &quot;S&quot; &lt;&lt; t &lt;&lt; a &lt;&lt; &quot;:&quot; &lt;&lt; S[t][a] &lt;&lt; endl;
				}
</code></pre>
<p>Zinssatz: Up: Down: S0: Strike: Zeitschritte:0 0.2 -0.1 1 1 2<br />
European oder American ?American<br />
Call oder Put?Call<br />
S20:0<br />
S21:0<br />
S20:1.44<br />
S21:1.08<br />
S22:1.08<br />
S23:0.81<br />
U wurde definiert<br />
S20:1.44<br />
S21:1.08<br />
S22:2.2264e-308<br />
S23:0.81</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/304036/wert-eines-arrays-verändert-sich-ohne-veränderung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 02:54:37 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/304036.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 28 May 2012 15:17:43 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:19:55 GMT]]></title><description><![CDATA[<p>S und U sollen jeweils Arrays von Double-Arrays sein. Ich will also 0...t Arrays, die wiederum jeweils Länge (2^t) haben.<br />
Da ich die Länge manuell eingegeben haben will, muss ich mir die dynamisch definieren.<br />
Wäre cool wenn ihr mir schonmal sagen ob ich die richtig definiert habe.<br />
Solange ich nur S definiere klappt auch alles aber, sobald ich U definiere ändern sich Wert in S.<br />
Ich hänge euch unten mal den Output an, in dem man sieht, dass bevor ich U definiere alles stimmt, dann aber S[2][2] plötzlich verrückt spielt.</p>
<p>Liebe Grüße</p>
<pre><code class="language-cpp">if (kind==&quot;American&quot;) {

			double** S = new double*[t+1];
			for(e=0; e&lt;=t; e++){
				S[e]= new double[2^e];
			}
			S[0][0]=S0;

		if (art==&quot;Call&quot;) {
			for (time=1; time&lt;=t; time++) 
			{
				for (a=0; a&lt;pow(2.0,time); a++)  
				{
					if (a % 2 == 0)
					{
				S[time][a]=S[time-1][a/2]*(1+u);
					}
						else S[time][a]=S[time-1][(a-1)/2]*(1+d);
						cout &lt;&lt; &quot;S&quot; &lt;&lt; t &lt;&lt; a &lt;&lt; &quot;:&quot; &lt;&lt; S[t][a] &lt;&lt; endl;
				}
			}

			double** U = new double*[t+1];
			for(c=0; c&lt;=t; c++){
				U[c]= new double[2^c];
			}
			cout &lt;&lt; &quot;Hallo&quot; &lt;&lt; endl;
				for (a=0; a &lt; pow(2.0,t); a++) {
			cout &lt;&lt; &quot;S&quot; &lt;&lt; t &lt;&lt; a &lt;&lt; &quot;:&quot; &lt;&lt; S[t][a] &lt;&lt; endl;
				}
</code></pre>
<p>Zinssatz: Up: Down: S0: Strike: Zeitschritte:0 0.2 -0.1 1 1 2<br />
European oder American ?American<br />
Call oder Put?Call<br />
S20:0<br />
S21:0<br />
S20:1.44<br />
S21:1.08<br />
S22:1.08<br />
S23:0.81<br />
U wurde definiert<br />
S20:1.44<br />
S21:1.08<br />
S22:2.2264e-308<br />
S23:0.81</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216341</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216341</guid><dc:creator><![CDATA[LarsMaurath]]></dc:creator><pubDate>Mon, 28 May 2012 15:19:55 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:29:08 GMT]]></title><description><![CDATA[<p>Nimm std::vector, std::array, Smartpointer oder was immer für ein Container aus der Standardbibliothek dir passend erscheint. Bei deiner jetzigen Methode, alles von Hand mit new zu machen, sind Fehler, im wahrsten Sinne des Wortes, vorprogrammiert.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216349</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216349</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 28 May 2012 15:29:08 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:29:36 GMT]]></title><description><![CDATA[<p>Ist schwierig da den Fehler zu sehen weil ich gar nicht genau weiss, was du da machen moechtest. Aber hier mal ein par Tipps:</p>
<p>- Benutze keine rohen Arrays (das ist C), sonder benutze std::vector oder std::array<br />
- Gib deinen Variabeln sinnvolle Namen.<br />
- Wenn du &quot;2^e&quot; schreibst, dann ist das nicht &quot;2 hoch e&quot; in C++. Nutze die Funktion pow(..) aus &lt;cmath&gt;</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216350</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216350</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Mon, 28 May 2012 15:29:36 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:38:12 GMT]]></title><description><![CDATA[<p>Danke schonmal für die Tipps !<br />
Das mit 2^e, etc. hab ich übersehen, klar das muss pow(2.0,e) heißen.<br />
Ich glaub es liegt erstmal an dieser ganzen dynamischen Allokation.<br />
Ich weiß da gar nicht genau was ich mache.</p>
<p>Ich will eigentlich einen dynamisch allokierten 2-dimensionalen Vektor, also t+1 Vektoren (0...t), dessen jeweilige Länge unterschiedlich sind und zwar 2^t.</p>
<p>Es geht um das Binomialmodell (CRR-Modell) zum Errechnen von Optionspreisen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216357</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216357</guid><dc:creator><![CDATA[LarsMaurath]]></dc:creator><pubDate>Mon, 28 May 2012 15:38:12 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:45:01 GMT]]></title><description><![CDATA[<p>LarsMaurath schrieb:</p>
<blockquote>
<p>Ich will eigentlich einen dynamisch allokierten 2-dimensionalen Vektor, also t+1 Vektoren (0...t), dessen jeweilige Länge unterschiedlich sind und zwar 2^t.</p>
</blockquote>
<p>Jetzt rate mal, was std::vector ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216362</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216362</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 28 May 2012 15:45:01 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:45:27 GMT]]></title><description><![CDATA[<p>Dann nimmt std::vector. Damit kannst du wunderbar dynamische Arrays anlegen ohne new, delete und Pointer zu brauchen.</p>
<p>Hier ein Beispiel:</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;vector&gt;

using std::vector;

int main()
{
	int t;
	std::cin &gt;&gt; t;
	vector&lt;vector&lt;double&gt; &gt; table( t );
	for ( size_t i = 0; i &lt; table.size(); ++i )
		table[i] = vector&lt;double&gt;( pow( 2.0, static_cast&lt;double&gt;(i) ) );
}
</code></pre>
<p>Das sollte glaube ich in etwa ein 2D-Array geben wie du es moechtest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216365</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216365</guid><dc:creator><![CDATA[icarus2]]></dc:creator><pubDate>Mon, 28 May 2012 15:45:27 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 15:57:23 GMT]]></title><description><![CDATA[<p>Vielen, vielen Dank !<br />
Funktioniert einwandfrei !<br />
Kannst du mir noch sagen, warum ich hier nicht dynamisch Speicher frei machen muss ?<br />
Ich dachte sobald mein benötigter Speicher von ner Variablen abhängt die noch nicht fest steht muss ich das benutzen ?<br />
Vielen Dank !</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216375</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216375</guid><dc:creator><![CDATA[LarsMaurath]]></dc:creator><pubDate>Mon, 28 May 2012 15:57:23 GMT</pubDate></item><item><title><![CDATA[Reply to Wert eines Arrays verändert sich ohne Veränderung on Mon, 28 May 2012 16:00:57 GMT]]></title><description><![CDATA[<p>LarsMaurath schrieb:</p>
<blockquote>
<p>Vielen, vielen Dank !<br />
Funktioniert einwandfrei !<br />
Kannst du mir noch sagen, warum ich hier nicht dynamisch Speicher frei machen muss ?<br />
Ich dachte sobald mein benötigter Speicher von ner Variablen abhängt die noch nicht fest steht muss ich das benutzen ?<br />
Vielen Dank !</p>
</blockquote>
<p>Das macht der vector alles automatisch. delete brauchst du dann und nur dann, wenn du new benutzt hast. Das heißt, so gut wie nie. Und falls du denkst du brauchst doch einmal new, dann frag hier noch mal, denn höchstwahrscheinlich brauchst du es nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2216381</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2216381</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Mon, 28 May 2012 16:00:57 GMT</pubDate></item></channel></rss>