如何解决根... [英] How to Solve a Root...

查看:59
本文介绍了如何解决根...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总是想知道电脑怎么会这样做...

我正在大学里学习微积分...我们去了牛顿的方法。

i发现这个有趣......


----------------------------- -

#include< cstdlib>

#include< iostream>

#include< cmath>

使用命名空间std;


double f1(double x);

double f2(double x,double y);


int main(int argc,char * argv [])

{

double x = 5;

cout<< f1(x)<< endl;

cout<< sqrt(x)<<结束;


系统(暂停);

返回EXIT_SUCCESS;

}


双f1(双x)

{

返回f2(x,x / 2);

}


双f2(双x,双y)

{

double z = y - (y * yx)/(2 * x) ;

如果(y == z)返回z;

否则返回f2(x,z);

}

---------------------------


适用于立方体根和其他如果你只需调整公式。

解决方案

(只是想我会分享。不涉及任何问题)




Mark写道:

总是想知道电脑怎么会这样做...
我我在大学里学习微积分......我们去了牛顿的方法。
我觉得这很有趣......

----------- -------------------
#include< cstdlib>
#include< iostream>
#include< cmath>

使用命名空间std;

double f1(double x);
double f2(double x,double y);

int main(int argc,char * argv [])
{
double x = 5;
cout<< f1(x)<< endl;
cout<< sqrt(x)<<系统(暂停);
返回EXIT_SUCCESS;
}

双f1(双x)
{
返回f2(x,x / 2);
}

双f2(双x,双y)
{
双z = y - ( y * yx)/(2 * x);
如果(y == z)返回z;


我认为直接比较花车是不好的?

否则返回f2(x,z);
}
- 如果你只是调整公式,-------------------------

将适用于立方根和其他人。



我和下一个人一样喜欢递归,但是在这个数学案例中我看到了堆栈溢出的巨大潜力。也许这应该被转换成一个循环而不是
。可能看起来更干净。


干杯,

Andre



Mark写道:

总是想知道计算机怎么会这样做......
我在大学里学习微积分...我们去了牛顿'的方法。如果您只是调整公式,
将适用于立方根和其他。




您可能想要查看Runge-Kutta方法。非常强大。我好多年前用
编码了一次......


always wondered how a computer might go about doing this...
i''m taking calculus at university... and we went over newton''s method.
i found this interesting...

------------------------------
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

double f1(double x);
double f2(double x, double y);

int main(int argc, char *argv[])
{
double x = 5;
cout << f1(x) << endl;
cout << sqrt(x) << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

double f1(double x)
{
return f2(x,x/2);
}

double f2(double x, double y)
{
double z = y - (y*y-x)/(2*x);
if( y == z ) return z;
else return f2(x,z);
}
---------------------------

will work for cube roots and others if you just tweak the formula.

解决方案

(just thought i''d share. no question involved)



Mark wrote:

always wondered how a computer might go about doing this...
i''m taking calculus at university... and we went over newton''s method.
i found this interesting...

------------------------------
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

double f1(double x);
double f2(double x, double y);

int main(int argc, char *argv[])
{
double x = 5;
cout << f1(x) << endl;
cout << sqrt(x) << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

double f1(double x)
{
return f2(x,x/2);
}

double f2(double x, double y)
{
double z = y - (y*y-x)/(2*x);
if( y == z ) return z;
I thought it was bad to directly compare floats?
else return f2(x,z);
}
---------------------------

will work for cube roots and others if you just tweak the formula.



I love recursion as much as the next guy, but in this mathematical case
I see huge potential for a stack overflow. Maybe this should be rolled
into a loop instead. Might actually look cleaner.

Cheers,
Andre



Mark wrote:

always wondered how a computer might go about doing this...
i''m taking calculus at university... and we went over newton''s method. will work for cube roots and others if you just tweak the formula.



You might want to look into the Runge-Kutta method. Quite robust. I
coded it up once many years ago...


这篇关于如何解决根...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆