home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------- */
- /* NLINTEST.C */
- /* (c) 1992 Klaus Röbenack & DMV-Verlag */
- /* Lösung nichtlinearer Gleichungen (Demo) */
- /* ------------------------------------------------- */
-
- #include <stdio.h>
- #include <conio.h>
- #include <math.h>
- #include "nlin.c"
-
- /* ------------------------------------------------- */
- /* Beispiel für eine Funktion */
-
- float funktion (float x)
- {
- return (x-exp(x/10)-5);
- }
-
- /* ------------------------------------------------- */
- /* Ableitung der Funktion */
-
- float ableitung (float x)
- {
- return (1-exp(x/10)/10);
- }
-
- /* ------------------------------------------------- */
- /* Für direkte Iteration */
-
- float funktion2 (float x)
- {
- return (exp(x/10)+5);
- }
-
- /* ------------------------------------------------- */
- /* Hilfsfunktionen für Ausgabe */
-
- void output (float xn)
- {
- gotoxy (3,8);
- cprintf ("X : %25.15f",xn);
- gotoxy (3,9);
- cprintf ("Y : %25.15f",funktion(xn));
- getchar();
- }
-
- void fenster1(str1, str2, str3, xu, xo)
- char *str1, *str2, *str3;
- float *xu, *xo;
- {
- window(35,12,78,22); textcolor(BLACK);
- textbackground(CYAN); clrscr();
- gotoxy(3,2); cputs(str1);
- gotoxy(3,4); cputs(str2); cscanf("%f",xu);
- if (*str3!=0) {
- gotoxy(3,5); cputs(str3); cscanf("%f",xo);
- };
- }
-
- void fenster2(str1, xu, xo)
- char *str1;
- float *xu, *xo;
- {
- fenster1(str1,"Schranke 1 : ","Schranke 2 : ",xu,xo);
- }
-
- /* ------------------------------------------------- */
-
- void main(void)
- {
- char c;
- float x1, x2, xn;
-
- do {
- window(1,1,80,25); textbackground(RED); clrscr();
- window(5,5,65,20); textcolor(YELLOW);
- textbackground(BLUE); clrscr();
- gotoxy(5,2);
- cputs ("*** LÖSUNG NICHTLINEARE GLEICHUNGEN ***");
- gotoxy(5,3);
- cputs
- (" Implementierte Funktion: f(x)=x-exp(x/10)-5");
- gotoxy(9,5); cputs ("I ... Iterations-Verfahren");
- gotoxy(9,6); cputs ("N ... Newton-Verfahren");
- gotoxy(9,7); cputs ("R ... Regula-Falsi");
- gotoxy(9,8);
- cputs ("H ... Halbierungs-Verfahren");
- gotoxy(9,9); cputs ("S ... Sehnen-Verfahren");
- gotoxy(9,10);cputs ("P ... Pegasus-Verfahren");
- gotoxy(9,12);cputs ("ESC ... Ende");
- textcolor(YELLOW);
- gotoxy(9,14);cputs ("Bitte wählen Sie !");
- textcolor(WHITE);
- c=getch();
- switch(c) {
- case 'I':
- case 'i': {
- fenster1("*** Direkte Iteration ***",
- "Startwert : ","",&x1,&x2);
- xn=IterationsVerfahren(funktion2,x1);
- output(xn);
- break;
- };
- case 'N':
- case 'n': {
- fenster1("*** Newton ***","Startwert : ","",
- &x1,&x2);
- xn=NewtonVerfahren(funktion,ableitung,x1);
- output(xn);
- break;
- };
- case 'R':
- case 'r': {
- fenster1("*** Regula-Falsi ***","Startwert 1 : ",
- "Startwert 2 : ",&x1,&x2);
- xn=SekandenVerfahren(funktion,x1,x2);
- output(xn);
- break;
- };
- case 'H':
- case 'h': {
- do {
- fenster2("*** Halbierung des Intervalls ***",
- &x1,&x2);
- } while(funktion(x1)*funktion(x2) >= 0);
- xn=HalbierungsVerfahren(funktion,&x1,&x2);
- output(xn);
- break;
- };
- case 'S':
- case 's': {
- do {
- fenster2("*** Sehnen-Verfahren ***",&x1,&x2);
- } while(funktion(x1)*funktion(x2) >= 0);
- xn=SehnenVerfahren(funktion,&x1,&x2);
- output(xn);
- break;
- };
- case 'P':
- case 'p': {
- do {
- fenster2("*** Pegasus-Algorithmus ***",
- &x1,&x2);
- } while(funktion(x1)*funktion(x2) >= 0);
- xn=PegasusVerfahren(funktion,&x1,&x2);
- output(xn);
- break;
- };
- };
- } while(c!=27);
- window(1,1,80,25);
- clrscr();
- }
- /* ------------------------------------------------- */
- /* Ende von NLINTEST.C */
-
-
-
-
-
-
-