博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
二分法 一元非线性方程求根 C语言实现
阅读量:4156 次
发布时间:2019-05-26

本文共 780 字,大约阅读时间需要 2 分钟。

二分法 一元非线性方程求根 C语言实现

标签:计算方法实验

/*    本实验用二分法求方程f(x) = x * x * x - 2 * x - 5 = 0在区间[2, 3]的根。*/#include 
#include
double f(double x){ return x * x * x - 2 * x - 5;}int main(){ double a, b; double eps = 0.0001; //精度要求 printf("please input a b = "); //区间[a, b] scanf("%lf %lf", &a, &b); double x = (a + b) / 2.0; //x为区间中点 if(f(a) * f(b) < 0){ while(f(x) != 0){ x = (a + b) / 2; if(f(x) * f(a) < 0){ b = x; if(b - a < eps) break; } else{ a = x; if(b - a < eps) break; } } printf("\nthe root of f(x) = 0 is x = %f\n", (a + b) / 2.0); } else printf("\nno root! afresh input\n"); return 0;}

实验结果:

output

你可能感兴趣的文章
andorid里关于wifi的分析
查看>>
Spring MVC和Struts2的比较
查看>>
Hibernate和IBatis对比
查看>>
Spring MVC 教程,快速入门,深入分析
查看>>
Android 的source (需安装 git repo)
查看>>
LOCAL_PRELINK_MODULE和prelink-linux-arm.map
查看>>
Simple Guide to use the gdb tool in Android environment
查看>>
Netconsole to capture the log
查看>>
Build GingerBread on 32 bit machine.
查看>>
How to make SD Card world wide writable
查看>>
Detecting Memory Leaks in Kernel
查看>>
Linux initial RAM disk (initrd) overview
查看>>
Timestamping Linux kernel printk output in dmesg for fun and profit
查看>>
There's Much More than Intel/AMD Inside
查看>>
CentOS7 安装MySQL 5.6.43
查看>>
使用Java 导入/导出 Excel ----Jakarta POI
查看>>
本地tomcat 服务器内存不足
查看>>
IntelliJ IDAE 2018.2 汉化
查看>>
Openwrt源码下载与编译
查看>>
我和ip_conntrack不得不说的一些事
查看>>