// Svmult() multiplies mathematically the matrix of 'sylvester' with the matrix of 'vector' void Svmult(Sylvester * sylvester, Vector * vector, Vector ** fin){ if(vector->dim!=sylvester->dim){ printf("Multiplication impossible due to different matrix dimensions!\n"); deleteVector(vector); return; } int i=0,j=0; char v='x'; if(sylvester->hidden=='x'){v='y';} Sylvester * temp=NULL; copysylvester(&temp, sylvester); for(i=0;i<temp->dim;i++){ for(j=0;j<temp->dim;j++){ multiply1polyonym(&(temp->matrix[i][j]), &(temp->matrix[i][j]),(vector->matrix[j]).matrix[0]); } } printVector(vector); createZeroVector(fin, vector->dim, v); for(i=0;i<temp->dim;i++){ for(j=0;j<temp->dim;j++){ add1polyonyms(&((*fin)->matrix[i]), &((*fin)->matrix[i]), &(temp->matrix[i][j])); } } printVector(*fin); destroysylvester(&temp); deleteVector(vector); deleteVector(*fin); }
//Multiplies 2 polyonyms to create their product polyonym void mult_polyonym1polyonym(Polyonym ** trgt, Polyonym * polyonym1,Polyonym * polyonym2){ int i=0,j=0; Polyonym temp; temp.matrix=NULL; (*trgt)=NULL; (*trgt)=malloc(sizeof(Polyonym)); if((*trgt)==NULL){perror("mult trgt malloc!");exit(0);} (*trgt)->var=polyonym1->var; (*trgt)->d = polyonym1->d + polyonym2->d; if( (polyonym1->d==0 && polyonym1->matrix[0]==0) || (polyonym2->d==0 && polyonym2->matrix[0]==0) ){ (*trgt)->d=0; } (*trgt)->matrix=NULL; (*trgt)->matrix=malloc(sizeof(double)*((*trgt)->d+1)); if((*trgt)->matrix==NULL){perror("mult trgt matrix malloc!");exit(0);} while(i<=(*trgt)->d){ (*trgt)->matrix[i]=0; i++; } i=0; while(i<=polyonym1->d){ multiply1polyonym(&temp, polyonym2,polyonym1->matrix[i]); j=0; while(j<=temp.d){ (*trgt)->matrix[j+i]=(*trgt)->matrix[j+i] + temp.matrix[j]; j++; } i++; } free(temp.matrix); }