Newton Method error.

  • [INDENT]Getting an error on the line where you calculate "diff".
    I am certain the equations are correct.


    E1 is in Radians and MA(k) and EA(k) are in Degrees.
    e(k) is no Units.


    Error code:

    Quote

    Invalid procedure call or argument.


    Code:

    What am I doing wrong?[/INDENT]

  • Re: Newton Method error.


    Untested Observation...


    That "Math.Sin(E1).." and the corresponding call to "Math.Cos..." look like they're trying to reference the .NET System.Math Namespace but you have not included anything to show that your project has a reference to that Namespace.


    You could try using the Excel Worksheet Functions SIN() & COS() - just replace the 'Math.' with 'WorksheetFunction.'

  • Do Loop are changing inside the Loop itself


    I think the reason this will not work is the variables for the Do Loop are changing inside the Loop itself and Excel does not like that.
    Is there any other Loops that may work in this case?


    Code
    E1 = Pi / 4 'Initialize
                diff = 1 'Initialize
                Do While Math.Abs(diff) > 0.00001
                    diff = (E1 - e(k) * Math.Sin(E1) - MA(k) * Pi / 180) / (1 + Math.Cos(E1))
                    E1 = E1 + diff
                Loop


    Tried

    Code
    Do Until Math.Abs(diff) < 0.00001
                     diff = (E1 - e(k) * Math.Sin(E1) - MA(k) * Pi / 180) / (1 + Math.Cos(E1))
                     E1 = E1 + diff
                 Loop


    Code
    Do
                    diff = (E1 - e(k) * Math.Sin(E1) - MA(k) * Pi / 180) / (1 + Math.Cos(E1))
                    E1 = E1 + diff
                Loop While Math.Abs(diff) > 0.00001


    A For or a ForEach will not work in this case.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!