编写多维数据集根函数有问题

编程入门 行业动态 更新时间:2024-10-10 23:24:57
本文介绍了编写多维数据集根函数有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用以下伪代码编写名为 double my_cbrt_1(double n)的多维数据集根函数:

I'm trying to write a cube root function named double my_cbrt_1(double n) using the following pseudocode:

x = 1 repeat 10 times: x = (2x + n / x2) / 3 return x

然后编写一个主函数,它打印n,cbrt(n)和my_cbrt_1(n)的n = 3.14159乘以10的k的k次幂,k = -100,-10,-1,0,1,10,和100.使用此C ++ 11代码(仅适用于linux2):

and then write a main which prints n, cbrt(n), and my_cbrt_1(n) for n = 3.14159 times 10 to the kth power for k = -100, -10, -1, 0, 1, 10, and 100. Use this C++11 code (which only works on linux2):

for(auto k : {-100, -10, -1, 0, 1, 10, 100}){ n = 3.14159 * pow(10.0, k); //cout goes here }

我在入门上遇到了麻烦.如果有人可以帮助我,那就太好了!

I'm having trouble getting started on this. If anyone could help me that would be great!

推荐答案

要开始使用,您可能应该一次计算单个数字的立方根,然后可以将相同的函数用于新数字

To get started, you should probably calculate the cubed root of a single number once, and then you can use that same function for new numbers

简单地实现您所获得的功能

To simply implement the function that you were given

double my_cbrt_1(double n) { double x = 1.0; for(int i=0; i<10; i++) { x = (2.0*x + n / (x*x)) / 3.0; } return x; }

更多推荐

编写多维数据集根函数有问题

本文发布于:2023-10-31 09:11:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545687.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多维   函数   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!