当前位置:网站首页>平方根立方根
平方根立方根
2022-07-23 05:47:00 【蓝色卡布达】
前言
平方根
1.二分法
代码如下(示例):
double SQRT_Binary(double n)
{
double l = 0, r = n;
if(n<0) l=n,r=0;
while(l<r)
{
double mid = (l + r) / 2;
if(mid * mid > n)
//if(mid*mid*mid)>n 立方根
//if(mid*mid*mid<E||mid*mid*mid>-E) return mid;小于某个阈值输出
//
r = mid;
else if(mid * mid < n)
l = mid;
else return mid;
}
}
2.牛顿迭代法
代码如下(示例):

double SQRT_Newton(double n)
{
double x0 = n;
double x1;
while(1)
{
//x1 = -(x0 * x0 - n) / (2 * x0) + x0;
x1 = (x0 * x0 + n) / (2 * x0);
//x1=(x0*x0*x0+n)/(3*x0*x0)
double val = x1 * x1 - n;
if(val <= inf && val >= -inf)
return x1;
x0 = x1;
}
return 0;
}
/
边栏推荐
- @RequiredArgsConstructor注解使用
- 学习日记——(路由与交换技术)动态路由(rip协议)和静态路由
- Explain various network protocols in detail
- C custom set
- LSM-tree(Log Structured-Merge Tree)的理解
- Super easy to use packet capturing tool tcpdump
- Pod 拓扑约束
- PDF Online preview, use of pdf.js
- Gameframework: package resources, publish packages with the app, package and generate folder instructions, upload resources to the server, download resources, gamefreamworklist DAT and gameframeworkve
- OSPF comprehensive experiment
猜你喜欢

Instant messaging websocket

HCIP---OSPF细节讲解

How to write a web page with a common text editor

Learning diary (routing and switching technology) -- floating static routing and default routing

Telnet 配置实例学习记录

HCIP---条件匹配和OSPF协议

OSPF综合实验

Explanation of websocket protocol

C (CSharp) wechat official account development - basic configuration

Learning diary - (routing and switching technology) layer 3 switch
随机推荐
静态路由原理与配置
Routing and switching technology - static routing
Unity3d: ugui source code, rebuild optimization
Unity3d+moba+ skill indicator (II)
Explain TCP segmentation and IP fragmentation in detail
Hcip - first experiment
Unity shader missing problem
Explain the flow control mechanism and congestion control mechanism of TCP in detail
sftp部署配置
Unity used trilib plug-in under URP pipeline to load model material incorrectly
HCIP---MGRE综合实验
简洁描述raft与paxos在设计上的共同点和不同点
PostgreSQL k8s部署模板
以go语言为例类比侦探推理来讲解【性能分析】
Explain various network protocols in detail
路由与交换技术——静态路由
DHCP second experiment
Unity3d+gameframework: resource analysis, resource dependency, circular dependency detection
Knowledge points and skills of Wireshark network analysis is so simple
MySQL性能优化,索引优化