⑴ c语言求导
if(fabs(dd2-dd1)>=1e-6) {dd1=dd2;goto Lab;}
会不会死循环了
⑵ C语言求导问题
用差分计算,当自变量趋于0时,前后两次差分收敛到需要精度,计算结束。
例如,一阶导数,写一个 函数 y = f(x):
float f(float x)
设 dx 初值
计算 dy
dy = f(x0) - f(x0+dx);
导数 初值
dd1=dy/dx;
Lab:;
dx = 0.5 * dx; // 减小步长
dy = f(x0) - f(x0+dx);
dd2=dy/dx; // 导数 新值
判断新旧导数值之差是否满足精度,满足则得结果,不满足则返回
if ( fabs(dd1-dd2) < 1e-06 )
else ;
⑶ c语言,求导
这位是在别人的地方来的,这是地址:
http://blog.csdn.net/qq_26816591/article/details/48690359
//一元多项式的求导
#include<stdio.h>
#include<malloc.h>//动态申请空间的函数的头文件
typedef struct node //定义节点类型
{
float coef; //多项式的系数
int expn; //多项式的指数
struct node * next; //结点指针域
}PLOYList;
void insert(PLOYList *head,PLOYList *input) //查找位置插入新链节的函数,且让输入的多项式呈降序排列
{
PLOYList *pre,*now;
int signal=0;
pre=head;
if(pre->next==NULL) {pre->next=input;} //如果只有一个头结点,则把新结点直接连在后面
else
{
now=pre->next;//如果不是只有一个头结点,则设置now指针
while(signal==0)
{
if(input->expn < now->expn)
{
if(now->next==NULL)
{
now->next=input;
signal=1;
}
else
{
pre=now;
now=pre->next;//始终让新输入的数的指数与最后一个结点中的数的指数比较,小于则插在其后面
}
}
else if( input->expn > now->expn )
{
input->next=now;
pre->next=input;
signal=1;
}//若新结点中指数比最后一个结点即now中的指数大,则插入now之前
else//若指数相等则需合并为一个结点,若相加后指数为0则释放该结点
{
now->coef=now->coef+input->coef;
signal=1;
free(input);
if(now->coef==0)
{
pre->next=now->next;
free(now);
}
}//else
} //while
}//else
}//void
PLOYList *creat(char ch) //输入多项式
{
PLOYList *head,*input;
float x;
int y;
head=(PLOYList *)malloc(sizeof(PLOYList)); //创建链表头
head->next=NULL;
scanf("%f %d",&x,&y);//实现用户输入的第一个项,包括其指数和系数
while(x!=0)//当用户没有输入结束标志0时可一直输入多项式的项,且输入一个创建一个结点
{
input=(PLOYList *)malloc(sizeof(PLOYList)); //创建新链节
input->coef=x;
input->expn=y;
input->next=NULL;
insert(head,input); //每输入一项就将其排序,是的链表中多项式呈降序排列
scanf("%f %d",&x,&y);
}
return head;
}
PLOYList *der(PLOYList *head)//多项式求导
{
PLOYList *p;
p = head -> next;
while (p)
{
p -> coef = p -> coef * p -> expn;
p -> expn = p -> expn--;
p = p -> next;
}
return head;
}//将多项式的每项系数和指数相乘得到新的系数,指数减一得到新的指数即完成求导
void print(PLOYList *fun) //输出多项式,fun指要输出的多项式链表的表头
{
PLOYList *printing;
int flag=0;
printing=fun->next;
if(fun->next==NULL)//若为空表,则无需输出
{
printf("0\n");
return;
}
while(flag==0)
{
if(printing->coef>0&&fun->next!=printing)
printf("+");
if(printing->coef==1);
else if(printing->coef==-1)
printf("-");
else
printf("%f",printing->coef);
if(printing->expn!=0) printf("x^%d",printing->expn);
else if((printing->coef==1)||(printing->coef==-1))
printf("1");
if(printing->next==NULL)
flag=1;
else
printing=printing->next;
}
printf("\n");
}
void main()
{
PLOYList *f;
printf(" 注:输入多项式格式为:系数1 指数1 系数2 指数2 …… ,并以0 0 结束:\n");
printf("请输入一个一元多项式:");
f = creat('f');
printf("这个多项式为:f(x)= ");
print(f);
printf("求导结果为:F(x)=f'(x)= ");
f=der(f);
print(f);
printf("\n\n");
}
⑷ 求一个用c语言编写的求导的程序
呵呵 求导函数 。。。。。。。。。。。。。。。。。。
C语言里有常用的函数比较简单,对于单一项目简单函数直接套用数学公式就可以了
而多项式函数就比较麻烦了 ,,还有复合函数本身求导过程就复杂。
如果你要实现任意形式的函数求导的话,必须完成正则表达函数提取出单项式,如有单项复合的情况下还要一一拆解,,直到能用数学公式求导的最基本函数才行!
还可以用同样的方法完成定积分的计算。
实现王能推导函数的过程需要多个算法的有机结合才行。。
就3步:
一:运用正则表达式算法把函数的每一项抽取出来,对应简单多项情况
二:运用正则表达式算法把函数的每一项子项抽取出来,并建立父子关系,,对于复合函数
三:用数学公式求导
用程序最难实现的就是前两相
⑸ 用C语言如何编写函数的求导
求导数有两种,一种是表达式求导,一种是数值求导。
表达式求导:需要对表达式进行词法分析,然后用常见的求导公式进行演算,求得导函数。在这方面,数学软件matrix,maple做得非常好。如果自己用C进行编程,不建议。
数值求导:利用导数的定义,用差分计算,当自变量趋于0时,前后两次差分收敛到需要精度,计算结束。这种方法可以求得某一点的导数。
例如:
求一阶导数,原函数 y = f(x), 程序中是float f(float x){ ...}
dx=0.01;//设dx初值
do{
dd1=(f(x0)-f(x0+dx))/dx;//计算导数dd1
dx=0.5*dx;//减小步长
dd2=(f(x0)-f(x0+dx))/dx;//计算导数dd2
}while(fabs(dd1-dd2)>=1e-06)//判断新旧导数值之差是否满足精度,满足则得结果,不满足则返回
⑹ c语言 多项式求导
#include<stdio.h> #include<stdlib.h> typedef struct polynode { int conf;/*常数*/ int exp;/*指数*/ struct polynode *next; }polynode; int main() { polynode *p,*q,*h; /*建立多项式*/ int conf,exp; h=(polynode*)malloc(sizeof(polynode)); q=h; scanf("%d %d",&conf,&exp); while(conf!=-1||exp!=-1) { p=(polynode*)malloc(sizeof(polynode)); p->conf=conf; p->exp=exp; q->next=p; q=p; scanf("%d %d",&conf,&exp); } q->next=NULL; \\你是这里写错了,写成NUll了 q=h; while(q->next!=NULL) /*求导*/ { q=q->next; if(q->exp>=1) { q->conf=(q->conf)*(q->exp); q->exp-=1; } else if(q->exp==0) { q=NULL; } else { printf("error"); break; } } q=h; while(q->next!=NULL)/*输出*/ { q=q->next; printf("%d %d",q->conf,q->exp); } return 0; } 改成这样就能运行了
⑺ 用c语言如何求导
用差分计算,当自变量趋于0时,前后两次差分收敛到需要精度,计算结束。
例如,一阶导数,写一个函数y=f(x):
floatf(floatx){...}
设dx初值
计算dy
dy=f(x0)-f(x0+dx);
导数初值
dd1=dy/dx;
Lab:;
dx=0.5*dx;//减小步长
dy=f(x0)-f(x0+dx);
dd2=dy/dx;//导数新值
判断新旧导数值之差是否满足精度,满足则得结果,不满足则返回
if(fabs(dd1-dd2)<1e-06){得结果dd2...}
else{dd1=dd2;gotoLab;};
⑻ C语言求解导数方程
M的倒数不就是 1/M 吗。
Y=a*M'+b*M+c*N
就是Y=a/M + b/M + c/N
⑼ 怎样用c语言实现对方程求导
求导数有两种,一种是表达式求导,一种是数值求导。 表达式求导:需要对表达式进行词法分析,然后用常见的求导公式进行演算,求得导函数。在这方面,数学软件matrix,maple做得非常好。如果自己用C进行编程,不建议。 数值求导:利用导数的定义
⑽ c语言怎么编求导
//多项式求导数
intPolyDeri(list<nodePoly>&polyFunc)
{
list<nodePoly>::iteratoriter;
for(iter=polyFunc.begin();iter!=polyFunc.end();++iter)
{
if((*iter).ex>1)
{
(*iter).coef=((*iter).coef)*((*iter).ex);
(*iter).ex=(*iter).ex-1;
}
elseif(1==(*iter).ex)
{
(*iter).ex=0;
}
elseif(0==(*iter).ex)
{
(*iter).coef=0;
}
}
returnRET_OK;
}
其中,多项式的定义是list<nodePoly>,如下:
//多项式节点结构体定义
typedefstructstuPolynomNode
{
doublecoef;
intex;
}nodePoly;
(10)c语言里怎么求导扩展阅读
c语言求导数据范围及提示DataSize&Hint
#include<iostream>
#include<cmath>
usingnamespacestd;
intmain()
{
intnum=0,i=0;
cin>>num;
for(i=2;i<=sqrt(num);i++)
{
if(num%i==0)
break;
}
if(i>sqrt(num)
cout<<num<<"为素数"<<endl;
else
cout<<num<<"不是素数"endl;
return0;
}