home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / e / e004 / 1.img / CURVEFIT.MCD < prev    next >
Encoding:
Text File  |  1987-10-22  |  2.4 KB  |  119 lines

  1. .MCD 20000 60
  2. .CMD PLOTFORMAT logs=0,0 subdivs=1,1 size=5,15 type=l
  3. .CMD FORMAT  rd=d ct=10 im=i et=3 zt=15 pr=3 mass length time charge
  4. .CMD SET ORIGIN 0
  5. .CMD SET TOL 0.001000
  6. .CMD MARGIN 0
  7. .CMD LINELENGTH 78
  8. .CMD SET PRNCOLWIDTH 8
  9. .CMD SET PRNPRECISION 4
  10. .CMD FILENAME data1 data1
  11. .CMD FILENAME data2 data2
  12. .TXT 1 0 1 27 
  13. a1,26,78,25
  14. POLYNOMIAL CURVE FITTING
  15. .TXT 2 5 5 54 
  16. a5,54,52,214
  17. This document shows how to fit a quadratic function 
  18. to a set of data. The same technique also works for 
  19. other types of curve fitting and for multiple 
  20. regression (regression with several independent 
  21. variables).
  22. .TXT 6 0 3 73 
  23. a3,73,73,162
  24. (This document follows the presentation in "Applied Linear Statistical 
  25. Models", by John Neter and William Wasserman, Richard D. Irwin, 1974. 
  26. Chapters 7 and 8.)
  27. .TXT 4 -5 1 43 
  28. a1,43,78,42
  29. First, read the data from external files:
  30. .EQN 2 6 1 21 
  31. x:READPRN(data1)
  32. .EQN 0 26 1 16 
  33. N:length(x)
  34. .EQN 2 -26 1 21 
  35. y:READPRN(data2)
  36. .EQN 0 26 1 11 
  37. N=?
  38. .TXT 2 -32 1 28 
  39. a1,28,78,27
  40. Compute sample statistics:
  41. .EQN 1 40 2 23 
  42. mean(y)=?
  43. .EQN 1 -34 1 17 
  44. mean(x)=?
  45. .EQN 1 0 2 22 
  46. var(x)=?
  47. .EQN 0 34 2 23 
  48. var(y)=?
  49. .EQN 2 0 2 24 
  50. stdev(y)=?
  51. .EQN 1 -34 1 22 
  52. stdev(x)=?
  53. .TXT 2 -6 1 26 
  54. a1,26,78,25
  55. Simple linear curve fit:
  56. .EQN 2 6 1 21 
  57. corr(x,y)=?
  58. .EQN 2 0 1 17 
  59. m:slope(x,y)
  60. .EQN 0 21 1 21 
  61. b:intercept(x,y)
  62. .EQN 2 -21 1 22 
  63. linear(x):m*x+b
  64. .TXT 2 0 1 29 
  65. a1,29,72,28
  66. Compute mean squared error:
  67. .EQN 2 0 4 30 
  68. SSE.L:{55}((y-linear(x))^2){49}
  69. .EQN 5 0 4 16 
  70. MSE.L:SSE.L/(N-2)
  71. .EQN 2 24 3 21 
  72. MSE.L=?
  73. .TXT 4 -30 1 1 
  74. x1,1,0,0
  75. .TXT 1 0 1 39 
  76. a1,39,78,38
  77. Quadratic fit using matrix operations
  78. .TXT 2 6 1 35 
  79. a1,35,72,34
  80. Create second variable: x squared
  81. .EQN 2 1 3 12 
  82. x2:(x^2){49}
  83. .EQN 1 23 1 16 
  84. i:0;N-1
  85. .TXT 4 -24 1 17 
  86. a1,17,72,16
  87. Create X matrix
  88. .EQN 1 19 2 11 
  89. X{52}:x
  90. .EQN 0 15 2 12 
  91. X{52}:x2
  92. .EQN 1 -33 2 11 
  93. X[(i,0):1
  94. .EQN 3 0 2 22 
  95. b:(X{51}*X)^-1*(X{51}*y)
  96. .EQN 3 0 4 19 
  97. b=?
  98. .TXT 6 -1 1 15 
  99. a1,15,71,14
  100. Fitted curve:
  101. .EQN 1 14 3 30 
  102. quad(x):b[0+b[1*x+b[2*x^2
  103. .TXT 4 -14 1 29 
  104. a1,29,72,28
  105. Compute mean squared error:
  106. .EQN 2 2 4 28 
  107. SSE.Q:{55}((y-quad(x))^2){49}
  108. .EQN 5 0 4 16 
  109. MSE.Q:SSE.Q/(N-2)
  110. .EQN 1 22 3 21 
  111. MSE.Q=?
  112. .TXT 4 -30 1 44 
  113. a1,44,78,43
  114. Now graph the two curves against the data:
  115. .EQN 3 0 10 31 
  116. 7*10^5&0&y[i,linear(x[i){1,1,8,15,dll}@&&x[i
  117. .EQN 0 38 10 29 
  118. 7*10^5&0&y[i,quad(x[i){1,1,8,15,dll}@&&x[i
  119.