一元多項式

代數學研究的基本對象之一。設P是一個數域,x是一個文字。形式表達式稱為係數在數域P上x的一元多項式,或稱數域P上的一元多項式。

一元多項式的定義

設a0,a1,a2,…,an-1,an都是數域F中的數,n是非負整數,那么表達式
anx +an-1x+…+a2x +a1x + a0(an≠0) (1)
叫做數域F上一個文字x的多項式或一元多項式。在多項式(1)中,a0叫做零次多項式或常數項,a1x叫做一次項,一般,aix叫做i次項,ai叫做i次項的係數。一元多項式用符號f(x),g(x),…來表示。
一元多項式的次數

一元多項式的相關概念

一元多項式的次數

anx叫做多項式:
anx +an-1x+…+a2x +a1x + a0(an≠0) (1)
的最高次項或首項。an稱為首項係數,非負整數n叫做多項式(1)的次數。
最高次項是零次項的多項式,即a(a≠0)的次數為零,叫零次多項式。
係數全為零的多項式沒有次數,這個多項式叫零多項式,零多項式總可記為0。
如a+b是關於a的一次多項式;3x+2x-5是關於x的二次多項式;x+y是關於x的三次多項式。

一元多項式的相等

若是數域P上兩個一元多項式f(x)和g(x)有完全相同的項,或者只差一些係數為零的項,那么f(x)和g(x)叫做相等,記作f(x)=g(x).
如:1+0x+5x+0x=1+0x+5x=1+5x
而3+1x+2x=3+x+2x≠3+x+x
按上述定義可知:兩個多項式
f(x)= a0+a1x+a2x+…+an-1x+anx
g(x) =b0+b1x+b2x+…+bn-1x+bnx
a0=b0,a1=b1,a2=b2,…,an-1=bn-1,an=bn

一元多項式的恆等

(1) 對於兩個次數都不超過n次的多項式f(x)及g(x),如果對於變數x的n+1個不同的數都有相同的值,,那么這兩個多項式恆等。
(2) 如果多項式f(x)與g(x)對於變數的x的無限多個數都有相同的值,那么它們是恆等的。

運算

#include
#include
#define A1(a,b,c,d,e) gotoxy(a,b);printf("c%d=",d);scanf("%f",e);
#define A2(a,b,c,d,e) gotoxy(a,b);printf("e%d=",d);scanf("%f",e);
#define B1 do { printf("\n(y/N)?")
#define B2 ch2=bioskey(0); printf("[%c]",ch2)
#define B3 if((ch2=="Y")||(ch2=="y")) tc(head1->next,head2->next,r); }
#define B4 while((ch2=="y")||(ch2=="Y"))
struct ma
{ float c;
float e;
struct ma *next; }
main()
{ struct ma *head1,*head2,*p,*q,*r,*rm;
float s1[100][3],s2[100][3],mid1,mid2,mid3;
int i,j,t,num1,num2;
char ch,ch1,ch2,ch11,ch21;
struct ma *add();
struct ma *mul();
void tc();
void output();
loop1: t=0; ch="y";
clrscr();
printf;
scanf("%d",#1);
q=head1=(struct ma*)malloc(sizeof(struct ma));
(*q).next=NULL;
if(num1>0)
{ printf;
for(i=1;i<=num1;i++)
{ if(i%3==1) t++;
if(i%3==1) { A1(1,t+2,c,i,∣1); A2(13,t+2,e,i,∣2);}
else if(i%3==2) { A1(28,t+2,c,i,∣1); A2(39,t+2,e,i,∣2);}
else { A1(53,t+2,c,i,∣1); A2(65,t+2,e,i,∣2);}
s1[i][1]=mid1;s1[i][2]=mid2;}
for(i=1;i<=num1;i++)
for(j=i;j<=num1;j++)
if(s1[j][2]
{ mid3=s1[j][2];s1[j][2]=s1[i][2];s1[i][2]=mid3;
mid3=s1[j][1];s1[j][1]=s1[i][1];s1[i][1]=mid3;}
for(i=1;i<=num1;i++)
{ p=(struct ma*)malloc(sizeof(struct ma));
(*p).c=s1[i][1];(*p).e=s1[i][2];
(*q).next=p; q=p; }
(*p).next=NULL; }
printf
scanf("%d",#2);
q=head2=(struct ma*)malloc(sizeof(struct ma));
(*q).next=NULL;
if(num2>0)
{ printf
for(i=1;i<=num2;i++)
{ if(i%3==1) t++;
if(i%3==1) { A1(1,t+4,c,i,∣1); A2(13,t+4,e,i,∣2);}
else if(i%3==2) { A1(28,t+4,c,i,∣1); A2(39,t+4,e,i,∣2);}
else { A1(53,t+4,c,i,∣1); A2(65,t+4,e,i,∣2);}
s2[i][1]=mid1;s2[i][2]=mid2;}
for(i=1;i<=num2;i++)
for(j=i;j<=num2;j++)
if(s2[j][2]
{ mid3=s2[j][2];s2[j][2]=s2[i][2];s2[i][2]=mid3;
mid3=s2[j][1];s2[j][1]=s2[i][1];s2[i][1]=mid3; }
for(i=1;i<=num2;i++)
{ p=(struct ma*)malloc(sizeof(struct ma));
(*p).c=s2[i][1];(*p).e=s2[i][2];
(*q).next=p; q=p; }
(*p).next=NULL; }
while(ch=="Y"||ch=="y")
{ printf;
printf;
ch=bioskey(0); printf("[%c]",ch);
printf; output((*head1).next);
printf; output((*head2).next);
switch(ch)
{ case '1': { printf;
if((num1==0)&&(num2==0)) r=NULL;
else if(num1==0) r=(*head2).next;
else if(num2==0) r=(*head1).next;
else { ch1="";r=add(head1,head2,ch1);}
output(r);
B1;B2;B3 B4;
break;}
case '2': { printf;
if((num1==0)&&(num2==0)) r=NULL;
else if(num1==0) { r=(*head2).next;
while(r!=NULL) { r->c*=-1;r=r->next;}
r=(*head2).next;}
else if(num2==0) r=(*head1).next;
else {ch1="-";r=add(head1,head2,ch1);}
output(r);B1;B2;B3 B4;
while((ch2=="y")||(ch2=="Y"));
break;}
case '3': { printf;
if((num1==0)||(num2==0)) r=NULL;
else r=mul(head1,head2);
output(r);B1;B2;B3 B4;
break;}
case '0': exit(0);
case '9': { while(head1!=NULL) {free(head1);head1=(*head1).next;}
while(head2!=NULL) {free(head2);head2=(*head2).next;}}goto loop1;
default: break;}
printf;
ch=bioskey(0); printf("[%c]",ch);
} }
struct ma *add( struct ma *head1,struct ma *head2,char ch1)
{ struct ma *head3,*p,*q,*r,*s;
head3=r=s=(struct ma*)malloc(sizeof(struct ma));
p=head1->next; q=head2->next;
do { r=(struct ma*)malloc(sizeof(struct ma));
(*s).next=r;
s=r;
if(p->e>q->e)
{ if(ch1=="") (*r).c=q->c;
else (*r).c=-(q->c); (*r).e=q->e; q=(*q).next;}
else if(p->e e) { (*r).c=p->c ; (*r).e=p->e; p=(*p).next; }
else { if(ch1=="") (*r).c=(p->c)+(q->c);
else (*r).c=(p->c)-(q->c);
(*r).e=(p->e); p=(*p).next;q=(*q).next;}
}while((p!=NULL)&&(q!=NULL));
while(q!=NULL)
{ r=(struct ma*)malloc(sizeof(struct ma));
(*s).next=r; s=r;
if(ch1=="") (*r).c=q->c ;
else (*r).c=-(q->c);(*r).e=q->e; q=(*q).next;}
while(p!=NULL)
{ r=(struct ma*)malloc(sizeof(struct ma));
(*s).next=r; s=r;
(*r).c=p->c ; (*r).e=p->e;p=(*p).next; }
(*r).next=NULL;
s=r=(*head3).next;
while(r->next!=NULL)
if(r->e==(r->next)->e)
{ r->c+=(r->next)->c; s=r->next;
r->next=(r->next)->next; free(s); s=r; }
else { r=r->next; s=s->next; }
s=r=(*head3).next;
return(r);
}
struct ma *mul(struct ma *head1,struct ma *head2)
{ struct ma *head3,*head4,*p,*q,*r,*s,*r1,*s1;
struct ma *w[100];
int t=0;
head3=r=s=(struct ma*)malloc(sizeof(struct ma));
head4=r1=s1=(struct ma*)malloc(sizeof(struct ma));
p=head1->next; q=head2->next;
while(p!=NULL)
{ s=(struct ma*)malloc(sizeof(struct ma));
s->c=(p->c)*(q->c);
s->e=(p->e)+(q->e);
r->next=s;
r=s;
p=p->next;}
s->next=NULL; s=r=head3->next; w[0]=head3;
p=head1->next; q=q->next;
while(q!=NULL)
{ while(p!=NULL)
{ s1=(struct ma*)malloc(sizeof(struct ma));
s1->c=(p->c)*(q->c);s1->e=(p->e)+(q->e);
r1->next=s1;
r1=s1;
p=p->next;
}
s1->next=NULL;r1=s1=head4->next;
t++;
w[t]=(struct ma*)malloc(sizeof(struct ma));
w[t]->next=add(w[t-1],head4,'+');
while(head3->next!=NULL) {r=r->next;free(s);head3->next=s=r;}
s=r=head3;
while(head4->next!=NULL) {r1=r1->next;free(s1);head4->next=s1=r1;}
s1=r1=head4;
p=head1->next; q=q->next;
}
return(w[t]->next);}
void tc(struct ma *p,struct ma *q, struct ma *r)
{ char ch1,ch2;
float x;
float qzhi(struct ma *head,float x);
void qdao();
printf;
printf;
ch1=bioskey(0);printf("[%c]",ch1);
printf;
printf;
ch2=bioskey(0);printf("[%c]",ch2);
switch(ch1)
{ case '1': { if(ch2=="z")
{ printf;
scanf("%f",&x);
printf;}
if(ch2=="d") qdao(p); break;}
case '2': { if(ch2=="z")
{ printf;
scanf("%f",&x);
printf;}
if(ch2=="d") qdao(q); break;}
case '3': { if(ch2=="z")
{ printf;
scanf("%f",&x);
printf;}
if(ch2=="d") qdao(r); break;} } }
float qzhi(struct ma *head,float x)
{ float value=0;
while(head!=NULL)
{ value+=(head->c)*pow(x,head->e);head=head->next;}
return(value);
}
void qdao(struct ma *head)
{ struct ma *p,*q,*r,*t;
p=head;
t=r=q=(struct ma *)malloc(sizeof(struct ma));
while(p!=NULL)
{ q=(struct ma *)malloc(sizeof(struct ma));
r->next=q;r=q;
q->c=(p->c)*((p->e));q->e=(p->e)-1;
p=p->next;}
q->next=NULL;
printf;
output(t->next);
p=t;
while(t!=NULL) { p=t->next;free(t);t=p;}
}
void output(struct ma *r)
{ int l=0;
struct ma *t,*s,*head;
t=r;
while(r->next!=NULL)
if(r->e==(r->next)->e)
{ r->c+=(r->next)->c; s=r->next;
r->next=(r->next)->next; free(s); s=r; }
else { r=r->next; s=s->next; }
s=r=t;
head=(struct ma*)malloc(sizeof(struct ma));
head->next=r;
s=head;
while(r!=NULL)
{ if((r->c)==0) {s->next=r->next; free(r);r=s->next;}
else { s=s->next;r=r->next;}}
s=r=head->next;
while(r!=NULL)
{ if(r->c==1) { l++;
if(r->e==1) printf("x");
else if(r->e<0) printf("x^(%.0f)",r->e);
else if(r->e==0) printf("1");
else printf("x^%.0f",r->e);}
else if(r->c==-1) { l++;
if(r->e==1) printf("-x");
else if(r->e<0) printf("-x^(%.0f)",r->e);
else if(r->e==0) printf("-1");
else printf("-x^%.0f",r->e);}
else { l++;
if(r->e==1) printf("%4.1fx",r->c);
else if(r->e<0) printf("%4.1fx^(%.0f)",r->c,r->e);
else if(r->e==0) printf("%4.1f",r->c);
else printf("%4.1fx^%.0f",r->c,r->e); }
if(((*r).next!=NULL)&&((r->next)->c>0)) printf(" +");
r=r->next; }
if(l==0) printf("0");
}

相關詞條

相關搜尋

熱門詞條

聯絡我們