Newton Method error.

Philosophaie

Active Member
Joined
Mar 5, 2010
Messages
256
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:

Invalid procedure call or argument.

Code:
           'Newton Method
            Pi = Application.WorksheetFunction.Pi
            E1 = Pi / 4 'Initialize
            diff = 1 'Initialize
            Do Until Math.abs(diff) < 0.00001
                If E1 = 3 * Pi / 2 Then
                    MsgBox ("/0")
                    E1 = 0.1
                End If
                diff = (E1 - e(k) * Math.Sin(E1) - MA(k) * Pi / 180) / (1 + Math.Cos(E1)) 'Error
                E1 = E1 + diff
            Loop
            EA(k) = E1 * 180 / Pi

What am I doing wrong?
 
Last edited:

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
have you declared e(k) and MA(k) elsewhere in the subroutine?
 
Upvote 0
Hi

When the code stops and you get the error what are the values of

E1
e(k)
MA(k)
 
Upvote 0
Code:
            Pi = Application.WorksheetFunction.Pi
This is not an answer to your question (you will need to answer the questions that have been asked of you in order to get one), rather, I thought you might find it interesting that the above can be replaced with this...
Code:
Pi = 4 * Atn(1)
 
Upvote 0
Rick, Thank you for the correction. You are right, it should read 'Evaluate function'.
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,428
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top