Current location - Trademark Inquiry Complete Network - Trademark registration - Newton Difference Trademark and Interpolation Formula Code
Newton Difference Trademark and Interpolation Formula Code
Dim aa As Double, bb As Double' respectively receive the variables at both ends of the root interval in findway.

Dim x( 1) is the root of Double' receiving ercigenway respectively.

1.0 er Method for Finding the Real Root of Quadratic Equation-Tested

Private Subercigenway (A is simple, B is simple and C is simple)' A, B and C correspond to the coefficients of quadratic equation.

Adjust d to double precision.

d = b ^ 2 - 4

If d< is 0.

Msgbox "Δ Δ is less than 0 and has no real root", "Message"

x(0) = 0: x( 1) = 0

Then ElseIf d = 0.

x(0) = -b / (2 * a): x( 1) = x(0)

other

x(0)=(-b-Sgn(b)* Sqr(d))/(2 * a):x( 1)= c/(a * x(0))

If ... it will be over.

End joint

2. 1 findway scan root interval in equal steps-tested

Private sub find way (byval a is single, byval b is single, h is double)' a and b are the endpoints of the interval to be scanned, and h is the step size.

Dim a 1 is double precision.

a 1 = a

do

if f(a 1)* f(a 1+h)& lt; Then = 0

aa = a 1: bb = a 1 + h

outlet connection

If ... it will be over.

a 1 = a 1 + h

Loop while a1< b

If a1> B so

MsgBox "Cannot find the root interval, please try a smaller step size"

outlet connection

If ... it will be over.

End joint

2.2 dichotomy root test

Private function er fenfun (byval a is single, byval b is single, eps is double)' A and b are endpoints of rooted interval, and EPS is error.

Dim x0 is Double, x 1 is Double, x2 is Double, f0 is Double, f 1 is Double, and f2 is Double.

x 1 = a: x2 = b

do

x0 = (x 1 + x2) / 2

f0 = f(x0)

If f0 = 0, then

Exit Do

other

f 1 = f(x 1): f2 = f(x2)

If F0 * f1<; Then 0

x2 = x0

other

x 1 = x0

If ... it will be over.

If ... it will be over.

Abs(x 1-x2) > time cycle; storage battery

x0 = (x 1 + x2) / 2

erfenfun = x0

End function

2.4 Newton Tangent Method-Tested

The private function Newton fxfun (byvalx0 is double, eps is double) is double' x0 is the nearby root, and EPS is the error.

Dim x 1 is of double precision, f0 is of double precision, and f 1 is of double precision.

x 1 = x0

do

x0 = x 1

F0 = f(x0): f 1 = fd(x0) 'fd represents the derivative function of f.

If ABS (f1) < Then eps.

X 1 = x0: exit from Do.

If ... it will be over.

x 1 = x0 - f0 / f 1

Loop until ABS (x1-x0) <; storage battery

newtonfxfun = x 1

End function

2.3 stediedaifun sefensen accelerated iteration method (equation form is x-f(x)= 0)- test.

Private function stediedaifun (byvalx0 as double, eps 1asdouble, eps2asdouble) as double' x0 is the root near the analytical solution, eps 1 is the error of the output result, and eps2 is the criterion for judging whether the iteration can continue.

Dim y is Double, z is Double, and x 1 is Double.

x 1 = x0

do

x0 = x 1

y = f(x0): z = f(y)

If ABS (z-2 * y+x0) < So eps2

MsgBox "In order to satisfy the eps2 condition, the iteration cannot continue"

Exit function

If ... it will be over.

x 1 = x0 - (y - x0) ^ 2 / (z - 2 * y + x0)

Loop until ABS (x1-x0) <; eps 1

stediedaifun = x 1

End function

2.5 Newton tangent method to solve Newton fxnfun n algebraic equation-tested

Newton fxnfun (a () is single, eps is double, and x0 is double) is double 'a () to store the n coefficients of the equation in descending order, EPS is error, and x0 is nearest root.

Dim k is an integer, n is an integer, f0 is a double precision, f 1 is a double precision, and x 1 is a double precision.

N = unbound (a)

x 1 = x0

do

x0 = x 1

f0 = a(0): f 1 = f0

For k = 1 to n-1

f0 = a(k) + f0 * x0

f 1 = f0 + f 1 * x0

Next k

f0 = a(n) + f0 * x0

x 1 = x0 - f0 / f 1

Loop until ABS (x1-x0) <; storage battery

newtonfxfun = x 1

End function

2.6 linecutfun chord cutting method-tested

The private function line cut fun (byval x0 is double, byval x 1 is double, eps is double, n is long) is the limit of iteration times, x0 and x 1 are the endpoints of rooted interval, and EPS is the error.

Mark f0 as Double, f 1 as Double, and f2 as Double.

Dim x2 is Double, and I is Long.

f0 = f(x0): f 1 = f(x 1)

For i = 1 to n

x2 = x 1-(x 1-x0)* f 1/(f 1-F0)

f2 = f(x2)

If ABS (F2) <: Then eps.

Quit for ...

If ... it will be over.

x0 = x 1:x 1 = x2:F0 = f 1:f 1 = F2

Next, I

If i = n+1

MsgBox "The number of calculations required is too low to meet the accuracy requirements"

If ... it will be over.

linecutfun = x2

End function

4. 1 Lagrange interpolation polynomial-tested.

Private function lagrangeczfun (a () is double, byval u is double) is double 'a (1, n) to store n+ 1 nodes, and u is the interpolation point.

Dim i is an integer, j is an integer and n is an integer.

Dim l is Double and v is Double.

v = 0

n = UBound(a,2)

For j = 0 to n

l = 1#

For i = 0 to n

If i = j, go to hulue.

l = l * (u - a(0,i)) / (a(0,j) - a(0,I))

hulue:

Next, I

v = v + l * a( 1,j)

Next J.

Lagrange function = v

End function

4.2 Newton Interpolation-Tested

The private function newtonczfun (a () is double and u is double) stores n+ 1 nodes for double 'a (1, n), and u is the interpolation point.

Dim n is an integer, I is an integer, J is an integer, and K is an integer.

Dim z () is Double, f () is Double, and v is Double.

n = UBound(a,2)

ReDim z(n),f(n)

For i = 0 to n

z(i) = a( 1,I)

Next, I

For i = 1 to n

k = k + 1

For j = 1 to n

f(j) = (z(j) - z(j - 1)) / (a(0,j) - a(0,j - k))

Next J.

For j = 1 to n

z(j) = f(j)

Next J.

Next, I

f(0) = a( 1,0)

v = 0

For i = n to 0 step-1

v = v * (u - a(0,i)) + f(i)

Next, I

newtonczfun = v

End function

4.3 hermiteczfun Hermite Interpolation Test

The private function Hermiteczfun (a () is double, FD () is double, and U is double) is double 'a (1, n) to store n+ 1 nodes, fd(n) to store the derivative value of n+ 1 nodes, and U is the interpolation point.

Dim l () is Double, ld () is Double, G () is Double, H () is Double, and aim is Double.

Dim n is an integer, I is an integer and j is an integer.

N = unbound (a)

ReDim l(n),ld(n),g(n),h(n)

aim = 0

For i = 0 to n

l(i) = 1: ld(i) = 0

For j = 0 to n

If j = i, then go to hulue.

l(i) = l(i) * (u - a(0,j)) / (a(0,i) - a(0,j))

ld(i) = ld(i) + 1 / (a(0,i) - a(0,j))

hulue:

Next J.

g(i) = ( 1 + 2 * (a(0,i) - u) * ld(i)) * l(i) * l(i)

h(i) = (u - a(0,i)) * l(i) * l(i)

aim = aim + g(i) * a( 1,i) + h(i) * fd(i)

Next, I

hermiteczfun = aim

End function

5.2.1tixingfun variable step integration method-tested

Private function tixingjfff (A is single, b is single, eps is double, and m is long) is double 'A and b are the upper and lower bounds of the integral, EPS is the error, and m is the maximum number of calculations.

Dim h is Double, t 1 is Double, t2 is Double, t is Double, and hh is Double.

Dim n As Long: n = 1

h = b - a: t 1 = h * (f(a) + f(b)) / 2

do

t = 0

For i = 1 to n

t = t + f(a + (i - 0.5) * h)

Next, I

hh = h * t

t2 = (t 1 + hh) / 2

If ABS (T2-t1) <; Eps then exits Do.

t 1 = t2: h = h / 2: n = 2 * n

Circulate until n>2 * meters.

If n>, then 2 * m

MsgBox "The number of calculations is too small to meet the error requirements"

If ... it will be over.

tixingjffun = t2

End function

5.2.2 Simpson Integral Method with Variable Step Size-Tested

Private function simplesonjfun(A is single, b is single, eps is double, and m is long) is double 'A and b are the upper and lower bounds of the integral, EPS is the error, and m is the maximum number of calculations.

Dim n is as long as I am.

Dim h is Double, t 1 is Double, t2 is Double, hh is Double, s 1 is Double, and s2 is Double.

n = 1:h = b-a:t 1 = h *(f(a)+f(b))/2

hh = h *(f((a+b)/2)):s 1 =(t 1+2 * hh)/3

do

n = 2 * n: h = h / 2: t2 = (t 1 + hh) / 2

t = 0

For i = 1 to n

t = t + f(a + (i - 0.5) * h)

Next, I

hh = t * h

s2 = (t 1 + 2 * hh) / 3

If ABS (S2-s1) <; Eps then exits Do.

t 1 = t2: s 1 = s2

Loop until n>m

If n>M Then MsgBox "has too few calculations to meet the error requirements"

simpsonjffun = s2

End function

5.3 Rhomberg integral method

Private function rombergjfun(a is Single, b is Single, eps is Double) is Double.

K is an integer, n is an integer, and h is a double precision.

k = 0: n = 1: h = b - a

End function

First derivative found-tested

Private function ds 1 fun(x0 is single, eps is double) is double' x0, and EPS is error.

Dim h is Double, t 1 is Double, and t2 is Double.

h = 1:t 1 =(f(x0+h)-f(x0-h))/(2 * h)

h = h/2:T2 =(f(x0+h)-f(x0-h))/(2 * h)

Do While Abs(t2-t 1) > battery

t 1 = t2

h = h / 2

t2 = (f(x0 + h) - f(x0 - h)) / (2 * h)

ring

ds 1fun = t2

End function

5.5.2 Second derivative of ds2fun-Tested

Private function ds 2 fun(x0 is single and eps is double) asdouble' x0 is derivative and EPS is error.

Dim h is Double, t 1 is Double, and t2 is Double.

h = 1:t 1 =(f(x0+h)+f(x0-h)-2 * f(x0))/(h * h)

h = h/2:T2 =(f(x0+h)+f(x0-h)-2 * f(x0))/(h * h)

Do While Abs(t2-t 1) > battery

t 1 = t2

h = h / 2

T2 =(f(x0+h)+f(x0-h)-2 * f(x0))/(h * h)

ring

ds2fun = t2

End function