0
|
5461 Views
|
6 Replies
|
9 Total Likes
View groups...
Share

# How would you fit this data in Mathematica?

Anonymous User
Anonymous User
Posted 10 years ago
 the x is 1,2,3,4,5. The y is 1.2,2.3,3.6,4.9,5.9. FInd the best-fitting power function. That is, find the best fitting function of the form f(x)=p* x^n for real parameters p and n.
6 Replies
Sort By:
Posted 10 years ago
 Transpose in this case essentially combines the two lists (like using Partition[Riffle[xi, yi], 2]). Nasser made a 2 x 5 matrix (each list as a row) and the transposed it to get the pairs of coordinates as a 5 x 2 matrix. This gets you the XY pairs. You can see this if you run the steps below: Clear[xi,yi]; yi = {1.2, 2.3, 3.6, 4.9, 5.9}; xi = {1, 2, 3, 4, 5}; {xi, yi} // MatrixForm Transpose[{xi, yi}] // MatrixForm 
Posted 10 years ago
 Clear[p, x, n]; yi = {1.2, 2.3, 3.6, 4.9, 5.9}; xi = {1, 2, 3, 4, 5}; data = Transpose[{xi, yi}]; nlm = NonlinearModelFit[data, p x^n, {p, n}, x] p1 = ListPlot[data, PlotStyle -> Red]; p2 = Plot[Normal[nlm], {x, 0, 6}, PlotTheme -> "Detailed", FrameLabel -> {{"y(t)", None}, {"x", "non-linear Fit"}}]; Show[p2, p1] 
Anonymous User
Anonymous User
Posted 10 years ago
 Can you explain what Transpose does thanks.
Posted 10 years ago
 For simple functions such as Transpose, the Mathemtica help menu provides excellent examples.
Anonymous User
Anonymous User
Posted 10 years ago
 And how would you find the residuals?
Posted 10 years ago
 And how would you find the residuals? Options are build-in. Help for more information: yi = {1.2, 2.3, 3.6, 4.9, 5.9}; xi = {1, 2, 3, 4, 5}; data = Transpose[{xi, yi}]; nlm = NonlinearModelFit[data, p x^n, {p, n}, x] nlm["FitResiduals"] nlm["StandardizedResiduals"] nlm["StudentizedResiduals"] nlm["EstimatedVariance"]