牛顿法求解非线性方程

算法原理:

C程序代码:

# include<stdio.h>
# include<math.h>
main(){
float f(float x0);
float f1(float x1);
float sishewuru(int m,float x2);
int i,n;
float x,y;
printf("\n the iterations and the inicial number is:");
scanf("%d,%f",&n,&x);
for(i=0;i<n;i++)
{
y=x-f(x)/f1(x);
x=y;
}
y=sishewuru(3,y);
printf("%f",y);
}
/* the function f(x)=x^3+7*x-1 */
float f(float x0){
float y;
y=pow(x0,3)+7*x0-1;
return y;
}
/* the function f(x)=3*pow(x,2)+7 */
float f1(float x1){
float y;
y=3*pow(x1,2)+7;
return y;
}

float sishewuru(int n,float x2){
int z1;
float y,z;
z1=(int)(x2*pow(10,n));
y=z1/(pow(10,n));
if(fabs(x2-y)>(5*pow(10,-n-1)))
y=(z1+1)/pow(10,n);
else
if (fabs(x2-y)==(5*pow(10,-n-1)))
  if(z1%2!=0)
    y=(z1+1)/pow(10,n);
return y;}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值