让写作成为一种习惯,作文库欢迎您!
当前位置:首页 > > 学科 > > 数学 >

迭代函数在高中数学中的应用论文,用迭代法解一个一元三次方程

2024-04-26 08:20:16数学访问手机版285

#include <stdio.h>
#include <math.h>
/* 函数*/
double func(double x)
{
    return x*x*x-2*x*x+10*x-20.0;
}


/* 迭代函数*/
double func1(double x)
{


    return 3*x*x-4*x+10;
}


/* 迭代函数*/
int Newton(double *x,double precision,int maxcyc)
{
    double x1,x0;
    int k;
    x0=*x;
    for(k=0;k<maxcyc;k++)
    {
    if(func1(x0)==0.0)
    {
    printf(迭代过程中导数为0 n);
    return 0;
    }
    x1=x0-func(x0)/func1(x0);
    if(fabs(x1-x0)<precision || fabs(func(x1)<precision))
    {
    *x=x1;
    return 1;
    }
    else    x0=x1;
    }
    printf(迭代次数超过预期n);
    return 0;
}


main()
{
    double x=1.5;  //x0 
 double precision=0.00005; // 精度
    int maxcyc=20;    //迭代次数
 if(Newton(&x,precision,maxcyc))
  printf(It's %lf,x);
    else
  printf(false);
}