<?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[Komplex &amp;quot;i&amp;quot;]]></title><description><![CDATA[<p>Hallo erstmal,</p>
<p>würde Hilfe bezüglich eines Programms brauchen:<br />
Kann mir vlt jmd sagen wie man die komplexe Zahl &quot;i&quot; in c++ implementiert. und nur &quot;i&quot; alleine. Würde es zum lösen in der zeitabhängigen schrödingergleichung brauchen.<br />
ich habe es mit</p>
<pre><code>complex&lt;double&gt; aa(0,1);
</code></pre>
<p>versucht, aber wenn ich die zahl quadriere,(zb.:</p>
<blockquote>
<p>aa.imag()*aa.imag()</p>
</blockquote>
<p>) kommt &quot;1&quot; statt &quot;-1&quot; heraus.<br />
danke für die hilfe schon mal!!</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/291070/komplex-quot-i-quot</link><generator>RSS for Node</generator><lastBuildDate>Mon, 17 Aug 2026 23:12:47 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/291070.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 10 Aug 2011 07:42:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 07:42:46 GMT]]></title><description><![CDATA[<p>Hallo erstmal,</p>
<p>würde Hilfe bezüglich eines Programms brauchen:<br />
Kann mir vlt jmd sagen wie man die komplexe Zahl &quot;i&quot; in c++ implementiert. und nur &quot;i&quot; alleine. Würde es zum lösen in der zeitabhängigen schrödingergleichung brauchen.<br />
ich habe es mit</p>
<pre><code>complex&lt;double&gt; aa(0,1);
</code></pre>
<p>versucht, aber wenn ich die zahl quadriere,(zb.:</p>
<blockquote>
<p>aa.imag()*aa.imag()</p>
</blockquote>
<p>) kommt &quot;1&quot; statt &quot;-1&quot; heraus.<br />
danke für die hilfe schon mal!!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104252</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104252</guid><dc:creator><![CDATA[Sagandscha]]></dc:creator><pubDate>Wed, 10 Aug 2011 07:42:46 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 07:44:17 GMT]]></title><description><![CDATA[<p>Quadrieren geht ja auch mit</p>
<pre><code class="language-cpp">aa*aa
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2104253</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104253</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Wed, 10 Aug 2011 07:44:17 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 07:54:13 GMT]]></title><description><![CDATA[<p>danke,<br />
so krieg ich zwar &quot;-1&quot; heraus, aber ich habe noch immer das problem, dass ich &quot;i&quot; alleine nicht in die formel implementieren kann...<br />
wenn ich also</p>
<pre><code>complex&lt;double&gt; aa(0,1.);

phi[i].real()= exp([b]aa[/b]*x*y)*exp(-((x-x0)*(x-x0))/(2*s*s));
</code></pre>
<p>bekomme ich eine fehlermeldung...<br />
und wenn ich es nur den imaginärteil nehme stimmt die formel nicht...<br />
oder bin ich komplett verkehrt!?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104258</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104258</guid><dc:creator><![CDATA[Sagandscha]]></dc:creator><pubDate>Wed, 10 Aug 2011 07:54:13 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 07:59:14 GMT]]></title><description><![CDATA[<p>Was für eine Fehlermeldung?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104263</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104263</guid><dc:creator><![CDATA[Eisflamme]]></dc:creator><pubDate>Wed, 10 Aug 2011 07:59:14 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:01:15 GMT]]></title><description><![CDATA[<p>real() liefert den Realteil deiner komplexen Zahl als Kopie. Dem etwas zuweisen zu wollen ist recht sinnlos. Lass das doch einfach weg.<br />
Außerdem liefert exp(aa*x*y) als Ergebnis ja wieder eine complex&lt;&gt;.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104265</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104265</guid><dc:creator><![CDATA[Braunstein]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:01:15 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:01:18 GMT]]></title><description><![CDATA[<blockquote>
<p>|21|error: no match for 'operator*' in 'std::operator* [with _Tp = double](((const std::complex&lt;double&gt;&amp;)((const std::complex&lt;double&gt;<em>)(&amp;aa))), ((const double&amp;)((const double</em>)(&amp;q)))) * i'|</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2104266</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104266</guid><dc:creator><![CDATA[Sagandscha]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:01:18 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:08:44 GMT]]></title><description><![CDATA[<p>Braunstein schrieb:</p>
<blockquote>
<p>real() liefert den Realteil deiner komplexen Zahl als Kopie. Dem etwas zuweisen zu wollen ist recht sinnlos. Lass das doch einfach weg.<br />
Außerdem liefert exp(aa*x*y) als Ergebnis ja wieder eine complex&lt;&gt;.</p>
</blockquote>
<p>mhm... aber es kommt auch bei</p>
<pre><code>phi[i].imag()= exp(aa*q*i)*exp(-((i-x0)*(i-x0))/(2*sigma*sigma));
</code></pre>
<p>oder</p>
<pre><code>phi[i]= exp(aa*q*i)*exp(-((i-x0)*(i-x0))/(2*sigma*sigma));
</code></pre>
<p>die fehlermeldung:</p>
<blockquote>
<p>|21|error: no match for 'operator*' in 'std::operator* [with _Tp = double](((const std::complex&lt;double&gt;&amp;)((const std::complex&lt;double&gt;<em>)(&amp;aa))), ((const double&amp;)((const double</em>)(&amp;q)))) * i'|</p>
</blockquote>
<p>und ich brauche für später sowohl den imaginär- als auch den komplexteil.</p>
<p>(ich bin ein richtiger programmier anfänger...habe daher auch probleme die fehlermeldungen zu verstehen!)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104274</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104274</guid><dc:creator><![CDATA[Sagandscha]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:08:44 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:12:19 GMT]]></title><description><![CDATA[<p>So nebenbei: Mit (x-x0)*(x-x0) rechnest Du x-x0 2mal aus. Das kannst Du vermeiden, indem Du dir eine Funktion zum Quadrieren schreibst:</p>
<pre><code class="language-cpp">typedef std::complex&lt;double&gt; cmplxd;

inline cmplxd square(cmplxd x) { return x*x; }
</code></pre>
<p>und die dann einfach so aufrufst</p>
<pre><code class="language-cpp">square(x-x0)
</code></pre>
<p>Und selbst da wird dann ein Produkt doppelt ausgerechnet (x.real()*x.imag()). Das kann man dann noch so vermeiden:</p>
<pre><code class="language-cpp">inline double square(double x) { return x*x; }
inline cmplxd square(cmplxd x) {
  return cmplxd(
    square(x.real())-square(x.imag()),
    2*x.real()*x.imag()
  );
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2104278</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104278</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:18:48 GMT]]></title><description><![CDATA[<p>Reduzier mal bitte deine Formel auf das &quot;aa * q *i&quot;, und schau, ob die Fehlermeldung immernoch kommt. Danach zeig uns mal den nötigen Code, d.h. die Definitionen von aa, q und i. Dieses gecaste in dem Ausdruck der Fehlermeldung macht mich stutzig.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104281</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104281</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:18:48 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:36:39 GMT]]></title><description><![CDATA[<p>Sagandscha schrieb:</p>
<blockquote>
<blockquote>
<p>|21|error: no match for 'operator*' in 'std::operator* [with _Tp = double](((const std::complex&lt;double&gt;&amp;)((const std::complex&lt;double&gt;<em>)(&amp;aa))), ((const double&amp;)((const double</em>)(&amp;q)))) * i'|</p>
</blockquote>
<p>(ich bin ein richtiger programmier anfänger...habe daher auch probleme die fehlermeldungen zu verstehen!)</p>
</blockquote>
<p>Ich übersetze mal: Der Compiler hat versucht für</p>
<pre><code>irgendwas_vom_typ_complex_double * i
</code></pre>
<p>den passenden Multiplikationsoperator rauszusuchen, um dieses Produkt auswerten zu können. Das ist ihm nicht gelungen. Ich rate mal, dass hier 'i' eine int-Variable ist. Leider kannst Du complex&lt;double&gt;-Werte nur mit anderen double-Werten multiplizieren. Das ist eine Macke des C++ Standards. Du musst also i durch ein double ersetzen:</p>
<pre><code>irgendwas_vom_typ_complex_double * double(i)
</code></pre>
<p>Probier das mal.</p>
<p>Der entsprechende Operator ist leider folgendermaßen als freies Template implementiert worden:</p>
<pre><code class="language-cpp">// Operator aus der Standardbibliothek
template&lt;class T&gt;
complex&lt;T&gt; operator*(complex&lt;T&gt;, T const&amp;);
</code></pre>
<p>Beachte: Das T taucht hier 2mal auf. Für den ersten Parameter müsste man T=double verwenden, für den zweiten dann T=int. Das ist ein Widerspruch, und somit wird dieses Funktionstemplate einfach ignoriert. Da nichts anderes Passendes übrig bleibt, bekommst Du diese Fehlermeldung. Machst Du aus dem zweiten Operand ein double, kann der Compiler mit T=double diesen Operator finden und anwenden.</p>
<p>Heutzutage ist man da schlauer und man würde die &quot;Template Argument Deduction&quot; für den zweiten Parameter mit einem Trick unterdrücken:</p>
<pre><code class="language-cpp">// Wie man es hätte besser machen können:
template&lt;class T&gt;
complex&lt;T&gt; operator*(complex&lt;T&gt;, typename identity&lt;T&gt;::type const&amp;);
</code></pre>
<p>wobei das typename identity-Zeug drum herum den Typ nicht wirklich verändert. Damit wird nur verhindert, dass der Compiler sich den zweiten Parameter überhaupt anguckt, wenn er sich fragt, was T hier sein soll. Mit diesem Ansatz würde der int implizit zu double konvertiert werden und dann mit dem complex&lt;double&gt; multipliziert werden.</p>
<p>Der Vollständigkeit wegen:</p>
<pre><code class="language-cpp">template&lt;class T&gt; struct identity { typedef T type; };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2104285</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104285</guid><dc:creator><![CDATA[krümelkacker]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:36:39 GMT</pubDate></item><item><title><![CDATA[Reply to Komplex &amp;quot;i&amp;quot; on Wed, 10 Aug 2011 08:38:49 GMT]]></title><description><![CDATA[<p>habe es soweit umgeschrieben... und es läuft...<br />
danke euch vielmals für die schnelle hilfe!</p>
<pre><code class="language-cpp">#include&lt;iostream&gt;
#include&lt;complex&gt;
#include&lt;fstream&gt;
using namespace std;

int main(){

const int n=1000;
const double dt=0.01;
double ii=0;
double q=0;
double x0=100.;
double sigma=25.;
complex&lt;double&gt; phi[n];
complex&lt;double&gt; aa(0,1.);
ofstream raus(&quot;daten.dat&quot;);

for(int i=0; i&lt;n; i++){
    ii=i;
phi[i]= exp(aa*q*ii)*exp(-((i-x0)*(i-x0))/(2*sigma*sigma));
}

for(int j=0; j&lt;10; j++){
raus&lt;&lt;j&lt;&lt;&quot;\t&quot;&lt;&lt;phi[j].real()&lt;&lt;&quot;\t&quot;&lt;&lt;phi[j].imag()&lt;&lt;&quot;\t&quot;&lt;&lt;norm(phi[j])&lt;&lt;&quot;\n&quot;;
}

}
</code></pre>
<p>werde es abe noch umschreiben... die grundfunktion geht ja jetzt!<br />
danke euch!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2104292</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2104292</guid><dc:creator><![CDATA[Sagandscha]]></dc:creator><pubDate>Wed, 10 Aug 2011 08:38:49 GMT</pubDate></item></channel></rss>