Tema17 - 17.19 Heres VBA code to implement linear...

Info iconThis preview shows pages 1–11. 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
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
17.19 Here’s VBA code to implement linear regression: Option Explicit Sub Regres() Dim n As Integer Dim x(20) As Single, y(20) As Single, a1 As Single, a0 As Single Dim syx As Single, r2 As Single n = 7 x(1) = 1: x(2) = 2: x(3) = 3: x(4) = 4: x(5) = 5 x(6) = 6: x(7) = 7 y(1) = 0.5: y(2) = 2.5: y(3) = 2: y(4) = 4: y(5) = 3.5 y(6) = 6: y(7) = 5.5 Call Linreg(x(), y(), n, a1, a0, syx, r2) MsgBox "slope= " & a1 MsgBox "intercept= " & a0 MsgBox "standard error= " & syx MsgBox "coefficient of determination= " & r2 MsgBox "correlation coefficient= " & Sqr(r2) End Sub Sub Linreg(x, y, n, a1, a0, syx, r2) Dim i As Integer Dim sumx As Single, sumy As Single, sumxy As Single Dim sumx2 As Single, st As Single, sr As Single Dim xm As Single, ym As Single sumx = 0 sumy = 0 sumxy = 0 sumx2 = 0 st = 0 sr = 0 For i = 1 To n sumx = sumx + x(i) sumy = sumy + y(i) sumxy = sumxy + x(i) * y(i) sumx2 = sumx2 + x(i) ^ 2 Next i xm = sumx / n ym = sumy / n a1 = (n * sumxy - sumx * sumy) / (n * sumx2 - sumx * sumx) a0 = ym - a1 * xm For i = 1 To n st = st + (y(i) - ym) ^ 2 sr = sr + (y(i) - a1 * x(i) - a0) ^ 2 Next i syx = (sr / (n - 2)) ^ 0.5 r2 = (st - sr) / st End Sub
Background image of page 9

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

View Full DocumentRight Arrow Icon
17.20 log N log Stress 0 3.053463 1 3.024486 2 2.996949 3 2.903633 4 2.813581 5 2.749736 6 2.630428 n =7 = 514 . 58 i i y x = 91 2 i x = 21 i x
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/13/2012 for the course AEROSPACE 301 taught by Professor Pfchang during the Spring '12 term at Shandong University.

Page1 / 13

Tema17 - 17.19 Heres VBA code to implement linear...

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

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