⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 no.5.c

📁 中南大学C语言程序设计实习 1 实验一:C语言图形模式的设置 2 实习二:一元函数的图形绘制 3 实习三:二维图形的几何变换 4 实习四:非线性方程求根的二分法 5 实习五
💻 C
字号:
#include "stdio.h"
#include "conio.h"
#define MIN -30000
#define ROOT_PRECISION 10e-5

float func1(float x, float a)
{
    return (x*x*x - a);
}

float func1_1(float x, float a)
{
    return (3*x*x);
} 

float func2(float x, float c)
{
    return (1 - c*x);
}

float func2_1(float x, float c)
{
    return (-c);
}           

float newton(float (*f)(float x, float a), float (*f_1)(float x, float c), float a, float x0)
{
    float x, ox;
    ox = x = x0;
    
    do {
        ox = x;
        x = x - f(x, a) / f_1(x, a);
    }while (x - ox > ROOT_PRECISION || ox - x > ROOT_PRECISION);
    return ox;
}

int main()
{
    float x;
    x = newton(func1, func1_1, 10, MIN);
    printf("%.5f\n", x);
    x = newton(func2, func2_1, 0.324, 3);
    printf("%.5f\n", x);
    getch();
}        
    

    
                        
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -