Tema18 - 18.14 Here is a VBA program to implement Newton...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
18.14 Here is a VBA program to implement Newton interpolation. It is set up to solve Example 18.5: Option Explicit Sub Newt() Dim n As Integer, i As Integer Dim yint(10) As Single, x(10) As Single, y(10) As Single Dim ea(10) As Single, xi As Single Range("a5").Select n = ActiveCell.Row Selection.End(xlDown).Select n = ActiveCell.Row - n Range("a5").Select For i = 0 To n x(i) = ActiveCell.Value ActiveCell.Offset(0, 1).Select y(i) = ActiveCell.Value ActiveCell.Offset(1, -1).Select Next i Range("e3").Select xi = ActiveCell.Value
Background image of page 6
Call Newtint(x(), y(), n, xi, yint, ea) Sheets("Sheet1").Select Range("d5:f25").ClearContents Range("d5").Select For i = 0 To n ActiveCell.Value = i ActiveCell.Offset(0, 1).Select ActiveCell.Value = yint(i) ActiveCell.Offset(0, 1).Select ActiveCell.Value = ea(i) ActiveCell.Offset(1, -2).Select Next i Range("a5").Select End Sub Sub Newtint(x, y, n, xi, yint, ea) Dim i As Integer, j As Integer, order As Integer Dim fdd(10, 10) As Single, xterm As Single Dim yint2 As Single For i = 0 To n fdd(i, 0) = y(i) Next i For j = 1 To n For i = 0 To n - j fdd(i, j) = (fdd(i + 1, j - 1) - fdd(i, j - 1)) / (x(i + j) - x(i)) Next i Next j xterm = 1# yint(0) = fdd(0, 0) For order = 1 To n xterm = xterm * (xi - x(order - 1)) yint2 = yint(order - 1) + fdd(0, order) * xterm ea(order - 1) = yint2 - yint(order - 1) yint(order) = yint2 Next order End Sub 18.15 Here is the solution when the program from Prob. 18.14 is run. 18.16 See solutions for Probs. 18.1 through 18.3. 18.17 A plot of the error can easily be added to the Excel application. The following shows the solution for Prob. 18.4:
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
The following shows the solution for Prob. 18.5: 18.18
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 13

Tema18 - 18.14 Here is a VBA program to implement Newton...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online