二分求函数零点

二分法求函数的零点

总时间限制: 
1000ms

内存限制: 
65536kB
描述

有函数:

f(x) = x5 - 15 * x4+ 85 * x3- 225 * x2+ 274 * x - 121

已知 f(1.5) > 0 , f(2.4) < 0 且方程 f(x) = 0 在区间 [1.5,2.4] 有且只有一个根,请用二分法求出该根。

输入
无。
输出
该方程在区间[1.5,2.4]中的根。要求四舍五入到小数点后6位。
样例输入
样例输出
不提供‘四舍五入’【代码】
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cmath>
 5 using namespace std;
 6 double f(double);
 7 int main()
 8 {
 9     double l=1.5,r=2.4,mid;
10     while(r-l>=1e-7)//1*10的7次方
11     {
12          mid=l+(r-l)/2;
13         if(f(l)*f(mid)<0)r=mid;//零点在左区间
14         else
15         l=mid;//否则零点位置缩小在右区间
16     }
17     printf("%.6lf",mid+0.0000005);//精确到后六位
18 }
19 double f(double x)
20 {
21     double ans;
22     ans=pow(x,5)-15*pow(x,4)+85*pow(x,3)-225*pow(x,2)+274*x-121;
23     return ans;
24 }

时间: 2024-07-29 03:27:43

二分求函数零点的相关文章

Hdu 2899 - Strange fuction 二分/三分求函数极值点

Strange fuction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4527    Accepted Submission(s): 3251 Problem Description Now, here is a fuction: F(x) = 6 * x^7+8*x^6+7*x^3+5*x^2-y*x (0 <= x <=

02:二分法求函数的零点

http://noi.openjudge.cn/ch0111/02/ 02:二分法求函数的零点 总时间限制:  1000ms 内存限制:  65536kB 描述 有函数: f(x) = x5 - 15 * x4+ 85 * x3- 225 * x2+ 274 * x - 121 已知 f(1.5) > 0 , f(2.4) < 0 且方程 f(x) = 0 在区间 [1.5,2.4] 有且只有一个根,请用二分法求出该根. 输入 无. 输出 该方程在区间[1.5,2.4]中的根.要求四舍五入到小

二分求幂,快速求解a的b次幂

一个引子 如何求得a的b次幂呢,那还不简单,一个for循环就可以实现! void main(void) { int a, b; int ans = 1; cin >> a >> b; for (int i = 1; i <= b; i++) { ans *= a; } cout << ans; } 那么如何快速的求得a的b次幂呢?上面的代码还可以优化吗? 当然是ok的!下面就介绍一种方法-二分求幂. 二分求幂 所谓二分求幂,即是将b次幂用二进制表示,当二进制位k位

HDU - 1588 Gauss Fibonacci (矩阵快速幂+二分求等比数列和)

Description Without expecting, Angel replied quickly.She says: "I'v heard that you'r a very clever boy. So if you wanna me be your GF, you should solve the problem called GF~. " How good an opportunity that Gardon can not give up! The "Prob

hdu 3641 数论 二分求符合条件的最小值数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*==================================================== 二分查找符合条件的最小值 ======================================================*/ ll solve() { __int64 low = 0, high = INF, mid ; while(low <=

15.求函数:sin(x)=x/1! - x3/3! + x5/5! -x7/7! +…,最后一项精度不低于0.000001

#include <iostream> using namespace std: int main() {     double x,sinx=0.0,jbf,j=1.0;     cin>>x;     jbf=x;     int k=1,l=1;     double n=1;     while(j>=1e-6)     {         j=jbf/n;         sinx=sinx+k*j;         jbf=jbf*x*x;         k=-

二分求幂(快速求幂,二进制求幂)

二分求幂, 非递归求法(二进制求法): 比如 2^5就是5个2相乘,按照5的二进制求 3^10就是8个3相乘,再2个3相乘. 处理幂的二进制,具体实现代码如下: long long quickmulti(long long a,long long b) { long long res=1; while(b) { if(b&1) //如果最后一位为1,则res*=a; res*=a; a*=a; //a*=a b>>=1; //b%=2 } return res; }

给定N个整数的序列,求函数的最大值

题目:给定N个整数的序列,求函数的最大值. 算法1: int maxSubseqSum1(int A[],int N) { int ThisSum,maxSum=0; int i,j,k; for(i=0;i<N;i++)//i是子列左端位置 { for(j=i;i<N;j++)//j是子列右端位置 { ThisSum=0;//ThisSum是从A[i]到A[j]的子列和 for(k=i;k<=j;k++) ThisSum+=A[k]; if(ThisSum>MaxSum)//如果

bzoj1692: [Usaco2007 Dec]队列变换(hash+二分求LCP)

以前一直用SA求LCP,今天学习了一波hash+二分求LCP的姿势,也是nlogn而且常数更小了. hash+二分可以logn比较两个后缀的字典序大小,求出LCP然后比较LCP后一个字符的字典序 #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #define ull unsigned long long using namespace std; ull mul[1