<?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[Numerische Integral- und Differentialberechnung]]></title><description><![CDATA[<p>Hallo Leute! Ich hoffe ich schreib in den richtigen Thread. Sorry wenn nicht.</p>
<p>Ich hab 2 Probleme. Eines mit meiner Integralfunktion und eines mit meiner Differentialfunktion. Ich hab 3 Funktionen f,g,h für die ich die y-Werte berechnen soll. Das funktioniert noch ganz gut. Aber wenn ich die y-Werte für die erste Ableitung und für die Stammfunktion berechne funktioniert das nur mehr für meine f Funktion. g und h werden mit falsch berechnet. Hat jemand eine Lösung für meine Anliegen?</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">double f(const double x)
{
     return 4.0*pow(x,3.0)+3.0*(x*x);
}

double g(const double x)
{
    return (exp(-x))*(sin(40*x));
}

double h(const double x)
{
    return x*(sin(40.0/x));
}

vector&lt;double&gt; fvonx(double (* const func)(double), const vector&lt;double&gt; x)
{
    vector&lt;double&gt; res;
    for(unsigned int i=0; i&lt;x.size(); i++)
    {
       double tmp=0;
       tmp=func(x.at(i));
       res.push_back(tmp);
    }
   return res;
}

vector&lt;double&gt; integrate(double (* const func)(double), const double a, const vector&lt;double&gt; b, const int N)

{

    vector&lt;double&gt; res;
    for (unsigned int i=0; i&lt;b.size();i++)
    {
        double h = (b.at(i) - a)/N;
        double sum = 0.5* h * (func(a) + func(b.at(i)));
        for (unsigned int j = 0; j &lt; N; j++)
        {
            sum += h * func(a + h*j);
        }
        res.push_back(sum);

    }
     return res;

}

vector&lt;double&gt; different(double (* const func)(double), const vector&lt;double&gt; x, const double eps)
{
    vector&lt;double&gt; res;
    for(unsigned int i=0; i&lt;x.size(); i++)
    {
        double h=0.1;
        double f1,f2;
        do
        {
            f2=f1;
            f1=(func(x.at(i)+h)-func(x.at(i)-h))/(2.0*h);
            h-=0.0001;
        }while((fabs(f1-f2))&gt;eps);

        res.push_back(f1);
    }

return res;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/303405/numerische-integral-und-differentialberechnung</link><generator>RSS for Node</generator><lastBuildDate>Mon, 10 Aug 2026 11:53:08 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/303405.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 13 May 2012 09:47:42 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 09:47:42 GMT]]></title><description><![CDATA[<p>Hallo Leute! Ich hoffe ich schreib in den richtigen Thread. Sorry wenn nicht.</p>
<p>Ich hab 2 Probleme. Eines mit meiner Integralfunktion und eines mit meiner Differentialfunktion. Ich hab 3 Funktionen f,g,h für die ich die y-Werte berechnen soll. Das funktioniert noch ganz gut. Aber wenn ich die y-Werte für die erste Ableitung und für die Stammfunktion berechne funktioniert das nur mehr für meine f Funktion. g und h werden mit falsch berechnet. Hat jemand eine Lösung für meine Anliegen?</p>
<p>Hier mein Code:</p>
<pre><code class="language-cpp">double f(const double x)
{
     return 4.0*pow(x,3.0)+3.0*(x*x);
}

double g(const double x)
{
    return (exp(-x))*(sin(40*x));
}

double h(const double x)
{
    return x*(sin(40.0/x));
}

vector&lt;double&gt; fvonx(double (* const func)(double), const vector&lt;double&gt; x)
{
    vector&lt;double&gt; res;
    for(unsigned int i=0; i&lt;x.size(); i++)
    {
       double tmp=0;
       tmp=func(x.at(i));
       res.push_back(tmp);
    }
   return res;
}

vector&lt;double&gt; integrate(double (* const func)(double), const double a, const vector&lt;double&gt; b, const int N)

{

    vector&lt;double&gt; res;
    for (unsigned int i=0; i&lt;b.size();i++)
    {
        double h = (b.at(i) - a)/N;
        double sum = 0.5* h * (func(a) + func(b.at(i)));
        for (unsigned int j = 0; j &lt; N; j++)
        {
            sum += h * func(a + h*j);
        }
        res.push_back(sum);

    }
     return res;

}

vector&lt;double&gt; different(double (* const func)(double), const vector&lt;double&gt; x, const double eps)
{
    vector&lt;double&gt; res;
    for(unsigned int i=0; i&lt;x.size(); i++)
    {
        double h=0.1;
        double f1,f2;
        do
        {
            f2=f1;
            f1=(func(x.at(i)+h)-func(x.at(i)-h))/(2.0*h);
            h-=0.0001;
        }while((fabs(f1-f2))&gt;eps);

        res.push_back(f1);
    }

return res;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2211021</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211021</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sun, 13 May 2012 09:47:42 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 10:03:36 GMT]]></title><description><![CDATA[<p>Versuchst du, die Funktionen in der Laufzeit abzuleiten??<br />
Leite sie doch einfach ab und mach dann die Ableitungsfunktionen als separate Funktionen.</p>
<p>z. B. f(x) = 4x³ + 3x² -&gt; f'(x) = 12x² + 6x</p>
<pre><code class="language-cpp">double fAbleit(double x)
{
    return 12 * x * x + 6 * x;
}
</code></pre>
<p>Ich hoffe du weißt, dass die Ableitung der Sinus-Funktion die Kosinus-Funktion ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211027</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211027</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sun, 13 May 2012 10:03:36 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 10:07:32 GMT]]></title><description><![CDATA[<p>Kannst du genauer sagen, was du mit 'falsch' meinst? Jedenfalls kommt mir <code>sin(40*x)</code> verdächtig vor. Sieht so aus, als würdest du in Grad (oder gar Neugrad?) denken, anstatt im Bogenmaß. Ist es das, was du meinst?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211029</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211029</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 13 May 2012 10:07:32 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 10:10:00 GMT]]></title><description><![CDATA[<p>Das würde schon funktionieren, denk ich, aber ich weiß nicht ob ich das darf. In der Uni haben wir diese beiden Formeln vorgegeben bekommen. Für meine f Funktion gehts ja auch...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211030</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211030</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sun, 13 May 2012 10:10:00 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 10:13:04 GMT]]></title><description><![CDATA[<p>Das mit Radiant und Grad hab ich mir schon gedacht aber es sind beide Werte anders als in meinem Code.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211032</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211032</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sun, 13 May 2012 10:13:04 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 12:00:20 GMT]]></title><description><![CDATA[<p>Nochmal: Beschreib bitte dein Problem genauer! &quot;Kommt falsch raus&quot; ist keine brauchbare Fehlerbeschreibung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211063</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211063</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Sun, 13 May 2012 12:00:20 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 13:06:40 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Nochmal: Beschreib bitte dein Problem genauer! &quot;Kommt falsch raus&quot; ist keine brauchbare Fehlerbeschreibung.</p>
</blockquote>
<p>also die beiden funktionen g und h liefern mir für g'(x) und G(x) und h'(x) und H(x) falsche Ergebnisse. Ich habe die Ergebnisse mit einem Taschenrechner überprüft und sie sind falsch. Beispielsweise erhalte ich für H(x) bei jedem Wert den ich integriere NAN.<br />
Das was mich verwirrt ist, dass ich für f(x), f'(x) und F(x) die richtigen Ergebnisse bekomme.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211077</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sun, 13 May 2012 13:06:40 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 15:08:50 GMT]]></title><description><![CDATA[<p>In <code>integrate</code> sollte die <code>for (unsigned int j = 0; j &lt; N; j++)</code> Schleife besser bei 1 anfangen, sonst geht <code>f(a)</code> 1.5 mal statt 0.5 mal in die Summe ein.</p>
<p>In <code>different</code> rechnest du mit <code>f2</code> , ohne jemals einen definierten Wert zugewiesen zu haben (d.h. du rechnest mit einer komplett zufälligen Zahl).</p>
<p>Und schliesslich das <code>h-=0.0001</code> ist einigermassen fragwürdig, wieso nicht einfach <code>h = h / 2</code> ?</p>
<blockquote>
<p>Beispielsweise erhalte ich für H(x) bei jedem Wert den ich integriere NAN.</p>
</blockquote>
<p>Probier mal ein Intervall ala [1, 2] - irgendwas wo die Null nicht drinnen liegt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211100</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211100</guid><dc:creator><![CDATA[hustbaer]]></dc:creator><pubDate>Sun, 13 May 2012 15:08:50 GMT</pubDate></item><item><title><![CDATA[Reply to Numerische Integral- und Differentialberechnung on Sun, 13 May 2012 15:42:32 GMT]]></title><description><![CDATA[<p>hustbaer schrieb:</p>
<blockquote>
<p>In <code>integrate</code> sollte die <code>for (unsigned int j = 0; j &lt; N; j++)</code> Schleife besser bei 1 anfangen, sonst geht <code>f(a)</code> 1.5 mal statt 0.5 mal in die Summe ein.</p>
<p>In <code>different</code> rechnest du mit <code>f2</code> , ohne jemals einen definierten Wert zugewiesen zu haben (d.h. du rechnest mit einer komplett zufälligen Zahl).</p>
<p>Und schliesslich das <code>h-=0.0001</code> ist einigermassen fragwürdig, wieso nicht einfach <code>h = h / 2</code> ?</p>
<blockquote>
<p>Beispielsweise erhalte ich für H(x) bei jedem Wert den ich integriere NAN.</p>
</blockquote>
<p>Probier mal ein Intervall ala [1, 2] - irgendwas wo die Null nicht drinnen liegt.</p>
</blockquote>
<p>Vielen Dank. Das behebt mein Problem!</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2211116</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2211116</guid><dc:creator><![CDATA[priesn]]></dc:creator><pubDate>Sun, 13 May 2012 15:42:32 GMT</pubDate></item></channel></rss>