Numerische Integration nach der Trapezregel



  • hatte das schonmal ausprobiert da kam es irgendwie zu fehlermeldungen jetzt speziell zu der der for zeile keine fehlermeldung jedoch klappt das mit der eingabe immernoch nicht
    muss die evtl an eine andere stelle des codes?

    hier nochmal code + fehlercode

    #include <math.h>
    #include <stdio.h>

    float f(float x)
    {
    return sqrt(x) * sin(x);
    }

    float integral(float a, float b) // a, b: Integrationsgrenzen
    {
    float intervall = b-a;
    float d = intervall / 100; // 100 Trapeze, d: Breite der Trapeze

    float l = a;
    float r = a+d;
    float flaeche = 0;
    for (int i=0; i<=100; i++)
    {
    flaeche += (f(l) + f(r)) / 2 * d; // Trapezformel
    l = l + d;
    r = r + d;
    }
    return flaeche;
    }

    int main(void)
    {
    float a, b, out;
    printf("Geben Sie die untere Integrationsgrenze ein: ") ; //Ausgabe auf Bildschirm
    30 scanf("%f", &a) ; //Einlesen der 1. Zahl in die Variable a
    31 printf("Geben Sie die oberere Integrationsgrenze ein: ") ; //Ausgabe auf Bildschirm
    32 scanf("%f", &b) ; //Einlesen der 2. Zahl in die Variable b
    33 out = integral(a,b);
    34 printf("Das Integral beträgt: %f\n", out); //Ausgabedes Ergebnisses auf den Bildschirm
    35 return 0; //Rückgabecode (0=kein Fehler)
    }

    Warning e:\fachhochschule\lcc\2323.c: 18 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 illegal statement termination
    Error e:\fachhochschule\lcc\2323.c: 30 skipping /'/'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'Einlesen'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before der' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'der' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon before1.'
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before Zahl' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'Zahl' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon beforein'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'in'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before die' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'die' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon beforeVariable'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'Variable'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before a' Warning e:\\fachhochschule\\lcc\\2323.c: 31 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 31 Syntax error; missing semicolon beforeprintf'
    Error e:\fachhochschule\lcc\2323.c: 32 illegal statement termination
    Error e:\fachhochschule\lcc\2323.c: 32 skipping /'/'
    Warning e:\fachhochschule\lcc\2323.c: 32 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 32 Syntax error; missing semicolon before der' Warning e:\\fachhochschule\\lcc\\2323.c: 32 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 32 Syntax error; missing semicolon before2.'
    Error e:\fachhochschule\lcc\2323.c: 32 too many errors



  • lcc win 32 (ist vorgabe...)

    http://www.cs.virginia.edu/~lcc-win32/



  • Jenny82 schrieb:

    ...
    30 scanf("%f", &a) ; //Einlesen der 1. Zahl in die Variable a
    31 printf("Geben Sie die oberere Integrationsgrenze ein: ") ; //Ausgabe auf Bildschirm
    32 scanf("%f", &b) ; //Einlesen der 2. Zahl in die Variable b
    33 out = integral(a,b);
    34 printf("Das Integral beträgt: %f\n", out); //Ausgabedes Ergebnisses auf den Bildschirm
    35 return 0; //Rückgabecode (0=kein Fehler)
    ...

    mach links diese zahlen weg...
    du bist ja echt ein voll-NOOB, ne 😉



  • danke pale dog

    jedoch hab ich die nummerierung für euch dran geschrieben damit ihr nich nachzählen braucht ( im fehlercode is die zeile angegeben)



  • Versuchmal statt "//" zur Auskommentierung /* Dein Kommentar */ zu verwenden! 😉



  • Jenny82 schrieb:

    danke pale dog
    jedoch hab ich die nummerierung für euch dran geschrieben damit ihr nich nachzählen braucht ( im fehlercode is die zeile angegeben)

    benutz' doch die code tags.
    wenn du quelltext postest, fügst du am anfang ein *[*code] ein, und am ende ein [/code].
    ääh, vielleicht mag dein compiler keine // -kommentare?



  • danke für die tips....
    habe alles versuch/* usw . ----> kein erfolg

    habe jetzt alle kommentare gelöscht und er zeigt immernoch die folgenden fehler an:

    Warning e:\fachhochschule\lcc\2323.c: 18 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 illegal statement termination
    Error e:\fachhochschule\lcc\2323.c: 30 skipping /'/'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'Einlesen'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before der' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'der' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon before1.'
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before Zahl' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'Zahl' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon beforein'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'in'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before die' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'die' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon beforeVariable'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'Variable'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before a' Warning e:\\fachhochschule\\lcc\\2323.c: 31 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 31 Syntax error; missing semicolon beforeprintf'
    Error e:\fachhochschule\lcc\2323.c: 32 illegal statement termination
    Error e:\fachhochschule\lcc\2323.c: 32 skipping /'/'
    Warning e:\fachhochschule\lcc\2323.c: 32 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 32 Syntax error; missing semicolon before der' Warning e:\\fachhochschule\\lcc\\2323.c: 32 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 32 Syntax error; missing semicolon before2.'
    Error e:\fachhochschule\lcc\2323.c: 32 too many errors



  • Dann scheint der lcc-win32 wohl was gegen Kommentare zu haben. Kannst versuchen die Kommentare in jeweils eine eigene Zeile zu schreiben und hoffen dass das dann geparst wird. Wenn nicht lass die Kommentierung weg.



  • die folgenden fehler habe ich ohne kommentar :

    Warning e:\fachhochschule\lcc\2323.c: 18 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 illegal statement termination
    Error e:\fachhochschule\lcc\2323.c: 30 skipping /'/'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'Einlesen'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before der' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'der' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon before1.'
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before Zahl' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'Zahl' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon beforein'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'in'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before die' Error e:\\fachhochschule\\lcc\\2323.c: 30 undeclared identifier 'die' Warning e:\\fachhochschule\\lcc\\2323.c: 30 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 30 Syntax error; missing semicolon beforeVariable'
    Error e:\fachhochschule\lcc\2323.c: 30 undeclared identifier 'Variable'
    Warning e:\fachhochschule\lcc\2323.c: 30 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 30 Syntax error; missing semicolon before a' Warning e:\\fachhochschule\\lcc\\2323.c: 31 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 31 Syntax error; missing semicolon beforeprintf'
    Error e:\fachhochschule\lcc\2323.c: 32 illegal statement termination
    Error e:\fachhochschule\lcc\2323.c: 32 skipping /'/'
    Warning e:\fachhochschule\lcc\2323.c: 32 Statement has no effect
    Error e:\fachhochschule\lcc\2323.c: 32 Syntax error; missing semicolon before der' Warning e:\\fachhochschule\\lcc\\2323.c: 32 Statement has no effect Error e:\\fachhochschule\\lcc\\2323.c: 32 Syntax error; missing semicolon before2.'
    Error e:\fachhochschule\lcc\2323.c: 32 too many errors

    #include <math.h>
    #include <stdio.h>
    
    float f(float x)
    {
    return sqrt(x) * sin(x);
    }
    
    float integral(float a, float b) // a, b: Integrationsgrenzen
    {
    float intervall = b-a;
    float d = intervall / 100; // 100 Trapeze, d: Breite der Trapeze
    
    float l = a;
    float r = a+d;
    float flaeche = 0;
    for (int i=0; i<=100; i++)
    {
    flaeche += (f(l) + f(r)) / 2 * d; // Trapezformel
    l = l + d;
    r = r + d;
    }
    return flaeche;
    }
    
    int main(void)
    {
    float a, b, out;
    printf("Geben Sie die untere Integrationsgrenze ein: ") ;
    scanf("%f", &a) ;
    printf("Geben Sie die oberere Integrationsgrenze ein: ") ;
    scanf("%f", &b) ;
    out = integral(a,b);
    printf("Das Integral//Ausgabedes Ergebnisses auf den Bildschirm
    return 0;
    }
    


  • Da sind immer noch Kommentare mit drin und mindestens ein ganz fießer Syntaxfehler:

    printf("Das Integral//Ausgabedes Ergebnisses auf den Bildschirm
    

    grüße


Anmelden zum Antworten