Click here to Skip to main content
15,915,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So this is my code


C#
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!!
Posted

1 solution

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:
C#
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:
 
Share this answer
 
Comments
BillWoodruff 28-Nov-13 17:18pm    
Amen 5 !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900