C#Newton Raphson的帮助 [英] C# Newton Raphson help

查看:102
本文介绍了C#Newton Raphson的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这是我的代码





  double  a =  1 ,Lspan =  30 ,Lcable =  33 ,fn,fdn,dfn; 








{
fn =(( 2 * a)*(Math.Sinh(Lspan /( 2 * a)))) - Lcable;

fdn =( 2 *(Math.Sinh(Lspan /( 2 * a))) - (((Lspan /( 2 * a))*(Math.Cosh(Lspan /( 2 * a))))));

dfn =(fn)/(fdn);

a + = -dfn;

}
while (dfn > 0 0000000000000000000000001 );





Console.WriteLine( {0},a);
Console.ReadKey();





我正在尝试使用newton raphsons方法来查找a的值,起始值是1,结束值应该是19。*****而不是1。******有没有人知道如何解决这个问题,它让我发疯了!

解决方案

所以,使用调试器。

手动计算第一个迭代值应该是什么,然后在循环内的第一条指令上放置一个断点。

现在运行程序。当它到达断点时,单步执行直到你到达该行:

 a + = -dfn; 

是否为dfn 超过你的终止价值?当你减去dfn时,a会有什么价值?它是否与您之前计算的值相匹配?

如果没有,请停止运行程序,并手动计算出每个中间结果:fn,fdn和dfn。如何再次运行它,并通过单步执行分配值的行来检查每个值的值。它与您手动制作的相匹配吗?



如果没有,那么你需要查看计算的各个部分并手动完成,等等。



这是一项值得开发的技能 - 但你需要在这里修理你的作业! :笑:


So this is my code


double a = 1, Lspan = 30, Lcable = 33, fn, fdn,dfn  ;

          





            do
            {
                fn = ((2 * a) * (Math.Sinh(Lspan / (2 * a)))) - Lcable;

                fdn = (2 * (Math.Sinh(Lspan / (2 * a))) - (((Lspan / (2 * a)) * (Math.Cosh(Lspan / (2 * a))))));

                dfn = (fn) / (fdn);

                a += -dfn;

            }
            while (dfn > 0.0000000000000000000000001);





            Console.WriteLine( " {0} ",a) ;
            Console.ReadKey();



I am trying to do newton raphsons method to find a value for a, the starting value is 1 and the end value should be 19.***** instead it is 1.****** does anyone know how to fix this, its driving me mad!!

解决方案

So, use the debugger.
Work out manually what the first iteration value should be, and then put a breakpoint on the first instruction inside the loop.
Now run the program. When it hits the breakpoint, single step through until you reach the line:

a += -dfn;

Is the value of "dfn" greater than your termination value? What value is going to be in "a" when you subtract "dfn"? Does it match the value you calculated before?
If not, stop running the program, and manually work out each intermediate result: "fn", "fdn", and "dfn". How run it again, and check the value of each of them by single stepping over the line that assigns the value. Does it match what you manually worked out?

If it doesn't, then you need to look at the parts of the calculation and work them out manually, and so on.

This is a skill it's worth developing - but you are going to need it here to fix your homework! :laugh:


这篇关于C#Newton Raphson的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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