//************************************************************************// // DERIVAC.C // // Derivacia funkcie podle zadannej funkcie // // // // 2.9.1997 // //************************************************************************// #include "mbooldif.h" #include "glob.h" #include "util.h" //************************************************************************// // Pripravy derivaciu podla premennej vysledok rozklada do K,K0,K1 // // 2.9.1997 // //************************************************************************// int derivac_dF(zapis_NDF *h_fnc, int prem, zapis_NDF *K, zapis_NDF *K0, zapis_NDF *K1) { int i; // devcica char nadpis[80]; // taku premennu nemam znuluj(K,1);znuluj(K1,1);znuluj(K0,1); if (( prem >= h_fnc->pv_NDF ) || ( prem < 0 )) return(FALSE); K->pv_NDF=h_fnc->pv_NDF; K0->pv_NDF=h_fnc->pv_NDF; K1->pv_NDF=h_fnc->pv_NDF; for (i=1; i<=h_fnc->poc_NDF; i++) { if ( h_fnc->pNDF[i][prem] == nic ) { // Neobsahuje prem vobec dalsie_NDF( K,0 ); strcpy( K->pNDF[ K->poc_NDF ], h_fnc->pNDF[i] ); K->pNDF[ K->poc_NDF ][ prem ]=nic; } // Obsahuje a,b,c if ( h_fnc->pNDF[i][prem] == jclen ) { dalsie_NDF( K1,0 ); strcpy( K1->pNDF[ K1->poc_NDF ], h_fnc->pNDF[i] ); K1->pNDF[ K1->poc_NDF ][ prem ]=nic; } // Obsahuje A,B,C if ( h_fnc->pNDF[i][prem] == nclen ) { dalsie_NDF( K0,0 ); strcpy( K0->pNDF[ K0->poc_NDF ], h_fnc->pNDF[i] ); K0->pNDF[ K0->poc_NDF ][ prem ]=nic; } } // end for(i=1; sprintf( nadpis,"\n dF/d%s = (K+K)\n \n K = ", index ); uloz_NDF( K, nadpis, TmpSubor[3] ); uloz_NDF( K0, " K= ", TmpSubor[3] ); uloz_NDF( K1, " K= ", TmpSubor[3] ); return(TRUE); } //************************************************************************// // Robi negaciu znaku nclen->jclen a naopak // // 3.9.1997 // //************************************************************************// char neguj( char clen ) { if ( clen == nclen ) return( jclen ); if ( clen == jclen ) return( nclen ); return( clen ); } //************************************************************************// // Podla toho aka pozicia vyrobi z neho znak a,b,c alebo A,B,C // // 3.9.1997 // //************************************************************************// char bool_znak( char clen, int pozic ) { if ( clen == jclen ) return( 'a'+pozic ); if ( clen == nclen ) return( ''+pozic ); return(' '); } //************************************************************************// // toto je pre K negacia vztahu (ab+cd) = (A+B)(C+D) // // z toho tazim a tak to robim // // 3.9.1997 // //************************************************************************// char *K_negovane( zapis_NDF *K ) { int x,y; char deriv_ret[max_ret]; char pom[max_ret]; strcpy( deriv_ret, "(" ); for (y=1; y<=K->poc_NDF; y++ ) { strcat( deriv_ret, "("); for (x=0; xpv_NDF; x++ ) // je to a,b,c alebo A,B,C if (( K->pNDF[y][x] == jclen ) || ( K->pNDF[y][x] == nclen )) { strchar( deriv_ret, bool_znak( neguj( K->pNDF[y][x] ), x ) ); strchar( deriv_ret, '+' ); } // end for(x=1; x<= if ( deriv_ret[ strlen( deriv_ret ) -1 ] == '+' ) strdel( deriv_ret, strlen( deriv_ret ) -1 ); strchar( deriv_ret, ')' ); } // end for(y=1;y<=K strchar( deriv_ret, ')' ); strcpy( pom, deriv_ret ); odstran_zatvorky( pom,1 ); // negujem nic takze ma vzniknut 1 if( strlen( pom ) == 0 ) { strcpy( deriv_ret, "(" ); // bol to clen v ktorom sa nachadzala len premenna podla ktorej sa derivovalo if( K->poc_NDF != 0 ) strcat( deriv_ret, vstup_0 ); // tu nebolo nic else strcat( deriv_ret, vstup_1 ); strcat( deriv_ret, ")" ); } return( deriv_ret ); } //************************************************************************// // Sucin clenov // // 3.9.1997 // //************************************************************************// char *K_sucin( zapis_NDF *K ) { int x,y; char deriv_ret[max_ret]; char pom[max_ret]; strcpy( deriv_ret, "(" ); for (y=1; y<=K->poc_NDF; y++ ) { for (x=0; xpv_NDF; x++ ) // je to a,b,c alebo A,B,C if (( K->pNDF[y][x] == jclen ) || ( K->pNDF[y][x] == nclen )) strchar( deriv_ret, bool_znak( K->pNDF[y][x], x ) ); strchar( deriv_ret, '+' ); } if ( deriv_ret[ strlen( deriv_ret ) -1 ] == '+' ) strdel( deriv_ret, strlen( deriv_ret ) -1 ); // chce nasobit nicim strchar( deriv_ret, ')' ); strcpy( pom, deriv_ret ); odstran_zatvorky( pom,1 ); // nasobim nicim takze ma vzniknut 0 if( strlen( pom ) == 0 ) { strcpy( deriv_ret, "(" ); // bol to clen v ktorom sa nachadzala len premenna podla ktorej sa derivovalo if( K->poc_NDF != 0 ) strcat( deriv_ret, vstup_1 ); // tu nebolo nic else strcat( deriv_ret, vstup_0 ); strcat( deriv_ret, ")" ); } return( deriv_ret ); } //************************************************************************// // Vysledkom tejto srandy by mala byt derivacia podla premennej // // 3.9.1997 // //************************************************************************// char *zderivuj_dF( zapis_NDF *K, zapis_NDF *K0, zapis_NDF *K1 ) { char deriv_ret[max_ret]; FILE *tmp,*fopen(); if (( Rezim == VYUK ) || ( Rezim == PREV)) tmp=fopen( strspoj( temp,TmpSubor[5]) ,"a+t" );// zapisuj inam, aby uzivatel nevidel else tmp=fopen( strspoj( temp,TmpSubor[3]) ,"a+t" ); // ak je to pre premennu ktora nieje vo f(), vtedy je K0={} K1={} // blbost co ?, aj to sa stava if ( ( K1->poc_NDF == 0 ) && ( K0->poc_NDF == 0 ) && ( K->poc_NDF == 0 ) ) { deriv_ret[0]='\0'; fprintf(tmp,"\n"); fprintf(tmp,"\n dF = {}\n\r"); fclose(tmp); return( deriv_ret ); } strcpy( deriv_ret, K_negovane(K) ); // df()= Kneg fprintf(tmp,"\n"); fprintf(tmp,"\n = %s", deriv_ret ); strcat( deriv_ret, " ( " ); // df()= Kneg( strcat( deriv_ret, K_negovane(K1) ); // df()= Kneg( K1neg fprintf(tmp,"\n ( = %s", deriv_ret ); strcat( deriv_ret, " " ); // dame medzeru strcat( deriv_ret, K_sucin(K0) ); // df()= Kneg( K1neg K0 fprintf(tmp,"\n (K = %s", deriv_ret ); strcat( deriv_ret, " + " ); // df()= Kneg( K1neg K0 + strcat( deriv_ret, K_sucin(K1) ); // df()= Kneg( K1neg K0 + K1 fprintf(tmp,"\n (K+K = %s", deriv_ret ); strcat( deriv_ret, " " ); // dame medzeru strcat( deriv_ret, K_negovane(K0) ); // df()= Kneg( K1neg K0 + K1 K0neg strcat( deriv_ret, " )" ); // df()= Kneg( K1neg K0 + K1 K0neg ) fprintf(tmp,"\n (K+K) = %s", deriv_ret ); fclose(tmp); return( deriv_ret ); } /*---------------------------------END--------------------------------------*/