文件名称:4
介绍说明--下载内容来自于网络,使用问题请自行百度
1. 实现二分法求解方程。编写并使用以下函数:
double SolveRoot(double(*pf)(double x),double a,double b,int n)
这里,pf指向一个函数f,f用来定义要求解的方程f(x)=0,a和b是未知解x的上下界(即a<=x<=b),n是循环次数。例如,如果f(x)=x*x-2,则SolveRoot (f,1,2,100)将返回1.414213562373095,即方程为x*x=2的解。二分法的原理是反复地把区间分为两个相等区间,然后用其中含有解的一半代替该区间,依次类推,得到满足精度的解。它通过检查f(a)和f(b)的符号来判断解是否在区间中。
程序运行结果为:
第一行为:SolveRoot(f,1,2,10) = 1.5
中间若干行
最后一行为:The exact SolveRoot = 1.414213562
-1. Achieve the dichotomy solve the equations. Equation f double SolveRoot (double (* pf) (double x), double a, double b, int n) here, pf points to a function f, f used to define the requirements for the solution of (x) = 0: write and use the following function , a and b are unknown solution x of the upper and lower bounds (i.e., a < = x < = b), n is the number of cycles. For example, if f (x) = x* x-2, then SolveRoot (f, 1,2,100) returns 1.414213562373095, i.e., the equation for x* x = Solution 2. Dichotomy principle is repeatedly divided into two equal sections to the interval, then the solution which contains half the place of the range, and so on, to get to meet the accuracy of the solution. It does this by checking f (a) and f (b) of the symbol to determine whether the interval Solutions. Run results: The first behavior: SolveRoot (f, 1,2,10) = 1.5 among several lines of the last acts: The exact SolveRoot = 1.414213562
double SolveRoot(double(*pf)(double x),double a,double b,int n)
这里,pf指向一个函数f,f用来定义要求解的方程f(x)=0,a和b是未知解x的上下界(即a<=x<=b),n是循环次数。例如,如果f(x)=x*x-2,则SolveRoot (f,1,2,100)将返回1.414213562373095,即方程为x*x=2的解。二分法的原理是反复地把区间分为两个相等区间,然后用其中含有解的一半代替该区间,依次类推,得到满足精度的解。它通过检查f(a)和f(b)的符号来判断解是否在区间中。
程序运行结果为:
第一行为:SolveRoot(f,1,2,10) = 1.5
中间若干行
最后一行为:The exact SolveRoot = 1.414213562
-1. Achieve the dichotomy solve the equations. Equation f double SolveRoot (double (* pf) (double x), double a, double b, int n) here, pf points to a function f, f used to define the requirements for the solution of (x) = 0: write and use the following function , a and b are unknown solution x of the upper and lower bounds (i.e., a < = x < = b), n is the number of cycles. For example, if f (x) = x* x-2, then SolveRoot (f, 1,2,100) returns 1.414213562373095, i.e., the equation for x* x = Solution 2. Dichotomy principle is repeatedly divided into two equal sections to the interval, then the solution which contains half the place of the range, and so on, to get to meet the accuracy of the solution. It does this by checking f (a) and f (b) of the symbol to determine whether the interval Solutions. Run results: The first behavior: SolveRoot (f, 1,2,10) = 1.5 among several lines of the last acts: The exact SolveRoot = 1.414213562
(系统自动生成,下载前可以参看下载内容)
下载文件列表
4/6.cpp
4/c++_ch06_06.vcxproj
4/c++_ch06_06.vcxproj.filters
4/Debug/6.obj
4/Debug/c++_ch06_06.lastbuildstate
4/Debug/c++_ch06_06.log
4/Debug/cl.command.1.tlog
4/Debug/CL.read.1.tlog
4/Debug/CL.write.1.tlog
4/Debug/link-cvtres.read.1.tlog
4/Debug/link-cvtres.write.1.tlog
4/Debug/link-rc.read.1.tlog
4/Debug/link-rc.write.1.tlog
4/Debug/link.command.1.tlog
4/Debug/link.read.1.tlog
4/Debug/link.write.1.tlog
4/Debug/vc110.idb
4/Debug/vc110.pdb
4/Debug
4
4/c++_ch06_06.vcxproj
4/c++_ch06_06.vcxproj.filters
4/Debug/6.obj
4/Debug/c++_ch06_06.lastbuildstate
4/Debug/c++_ch06_06.log
4/Debug/cl.command.1.tlog
4/Debug/CL.read.1.tlog
4/Debug/CL.write.1.tlog
4/Debug/link-cvtres.read.1.tlog
4/Debug/link-cvtres.write.1.tlog
4/Debug/link-rc.read.1.tlog
4/Debug/link-rc.write.1.tlog
4/Debug/link.command.1.tlog
4/Debug/link.read.1.tlog
4/Debug/link.write.1.tlog
4/Debug/vc110.idb
4/Debug/vc110.pdb
4/Debug
4
本网站为编程资源及源代码搜集、介绍的搜索网站,版权归原作者所有! 粤ICP备11031372号
1999-2046 搜珍网 All Rights Reserved.