用分而治之的方法解决问题 [英] solve the problem with divide and conquer approach

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

问题描述

hi
如何计算小数点后最多4位的x数量? p,q,r,s,t,u是问题的输入

(0< = x< = 1,我们知道这个函数在0< = x< = 1下降了)

hi how i can calculate the amount of x up to 4 digits after decimal? p , q , r , s ,t , u are the inputs of problem
( 0<=x<=1 and we know this function in 0<=x<=1 is descending)

p×e^(-x)+q×sin(x)+r×cos(x)+s×tan(x)+t×x^2+u=0



请帮帮我。

非常感谢。


please help me.
thanks alot.

推荐答案

这是一个数学问题:这个函数不是线性的,还有其他的困难。所以D& C不是一个解决方案,但问题的一部分:-O



如果你正在寻找一个4位数的解决方案,我会像这样运行一个大循环:

元代码:

At first this is a mathematical issue: this function isnt linear and has other dificulties. So D&C isnt a solution but part of the problem :-O

If your are looking for a 4-digit solution, I would ran a big loop like this:
Meta code:
float results[10000];
int n = 0;
for( float step = 0; i < 1; i+=0.00001 )
{
   results[n] = callProblem( i );
}
//take a look on the sample





一些分而治之的方法





some divide and conquer approach

float x = 0;
float diff = 1;//Startvalue
while( )
{
   result = callProblem(x);

  if( result > 0 )
{
x -= diff;
diff = diff/2;
result = callProblem(x);
}
else
{
x += diff;
diff = diff/2;
result = callProblem(x);
}
}


这篇关于用分而治之的方法解决问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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