I'm having problems with the porblem stated below:
Write a VBA macro that uses Newton's method to solve for a root. The function should take 3 arguements: an intial guess for the root, the DeltaX to use for the numerical derivatives (use a central difference approximation), and a relative stopping criteria. The fucntion should return the root of the function,i.e. the value of x that satisfies f(x) = 0. Use the absolute value of the raltive change in two successive x values to test against your relative stopping criteria. For this problem, you don't need any other testing, e.g. number of loops or time taken - just relative stopping criteria (Hint: You obviously need to embed the iterations within some kind of loop)
Assume that the function is available in a VBA function termed myf(). myf() takes 1 arguemet: the x value where the function is to be evaluated. For example, if the function is 3x^2+2x-1, then assume that the following code is already available
This is currently what I have:Option Explicit
Function myf(x as double) as double
myf = 3x^2 + 2x-1
End Function
Thanks,Option Explicit
Sub Newtons()
Dim x As double
Dim s As double
Dim dx As double
Dim i as long
x=1
s=0
dx=2
For i=1 to 1000
c=x-(myf(x)/[(myf(x+dx)-myf(x-dx))/(2*dx)]
If x-c = s Then
End Function
End If
x=c
Next i
EndFunction
Brandon
Bookmarks