Create function that functionally same to polyfit
3 次查看(过去 30 天)
显示 更早的评论
Create a user-defined function 'fitpoly' that has the same function as 'polyfit'
Reads the given data points from a text or Excel file and approximates the curve with an nth-order polynomial function
Set the input and output factors the same as ‘polyfit’
4 个评论
Rik
2022-5-17
Unfortunately for you, Google had a cached version of this page from before you attempted to edit away your homework question.
Sam Chak
2022-5-17
编辑:Sam Chak
2022-5-17
I think the Professor won't penalize @종석 박 so long as he acquired the regression analysis knowledge (cognitive) and the coding skills (psychomotor) as required by the assignment and outlined in the Outcome-Based Education (OBE). The Professor will be happy when writing the Education Report at the end of the academic term. As long as there is no blatant plagiarism elements, then he should be "SAFE".
回答(3 个)
Image Analyst
2022-5-17
There is still another way @종석 박 can do the assignment without plagiarizing. He can construct the equation like
Ax = y
using a for loop where A =
x(1)^n, x(1)^(n-1), x(1)^(n-2), ....., x(1), 1
x(2)^n, x(2)^(n-1), x(2)^(n-2), ....., x(2), 1
x(3)^n, x(3)^(n-1), x(3)^(n-2), ....., x(3), 1
...
x(m)^n, x(m)^(n-1), x(m)^(n-2), ....., x(m), 1
Then once you have the tall array you can do
coefficients = A \ y(:)
which is basically the method for doing least squares regression "manually".
0 个评论
Sam Chak
2022-5-16
I find it a little strange. Should your Intructor/Professor send you to learn the essentials through MATLAB Onramp at the beginning of the course in MATLAB?
From your description, it seems that your Intructor/Professor wants you to study the algorithm in polyfit.m.
This example only has 3 points, (1, 4), (2, 7), (3, 14). Try to improvise from here.
% Formulate the problem as a linear equation, A*x = b
P = [1 4; 2 7; 3 14]
x = P(:, 1)
A = [x.^2 x repelem(1, 3, 1)]
b = P(:, 2)
x = A\b
0 个评论
Image Analyst
2022-5-16
@종석 박 did you try what Jan told you?
function coefficients = myPolyFit(x, y, n)
coefficients = x(:) .^ (n : -1 : 0) \ y(:);
end
If not, why not?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!