Using polyfit() to get 'p' vector
6 次查看(过去 30 天)
显示 更早的评论
Hi MATLAB community!
I'm using MATLAB R2020a.
I was using polyfit() function to find a 1st order polynomial fitting of my data. I tried to use two ways to get p vector as below:
[p, S, mu] = polyfit(R1, avg_E, 1); % polyfit of R1 and avg_E, 1st order polynomial
p_1op = polyfit(R1, avg_E, 1); % polyfit of R1 and avg_E, 1st order polynomial
After I ran this code, I checekd 'p' and 'p_1op', and they look completely different:
p = [-345.733272503816 717.117508770000]
p_1op = [-1234.10283170532 1484.39195156382]
Would you share some thoughts or experience related to this? I was not sure why this happened and how I should fix it.
Thank you for reading!
0 个评论
回答(1 个)
Pankil Kalra
2021-6-14
Hi Juyong,
The question you have asked has already been answered at this community post. To summarise the reason for the difference – When you call the function with 3 return variables: [p, S, mu], the third output mu tells matlab to center and scale the data. The centering and scaling values are stored in mu. This centered and scaled data is used to generate the polynomial fit. The polynomial fit in the function call without mu is created using the raw R1 data. Hence, there is a difference between the parameter values or p vector in the two cases.
You can read more about the polynomial fit function at the documentation page
2 个评论
Steven Lord
2021-6-14
Please don't delete your question.
If someone else has the same question as you did in the future, they can search and hopefully find your question and its answer more quickly than if they posted and waited for someone else to answer.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!