Multiple input vector for polyfit and get polyval , derive the best coeff & least RMS Error

조회 수: 10 (최근 30일)
Hi
I have a code which is computing the polyval for multiple input vectors. I would like to derive best coefficient and lowest RMS error
Does MATLAB offer a manner in which I can fit all (x input number) of these simultaneously, where the solution is in the form of a polynomial, and will have some fitted coefficients/best, so that each curve is fit properly?
x1 = rand(12,1); % or replacec with a know data 1:10
x2 = rand(12,1); % or replacec with a know data 2:11
x3 = rand(12,1); % or replacec with a know data 3:12
x4 = rand(12,1); % or replacec with a know data 4:13
x5 = rand(12,1); % or replacec with a know data 5:14
x6 = rand(12,1); % or replacec with a know data 6:15
x7 = rand(12,1); % or replacec with a know data 7:16
x8 = rand(12,1); % or replacec with a know data 8:17
X = [x1,x2,x3,x4,x5,x6,x7,x8];
for n = 1:7
[p,S,mu] = polyfit(X(n),X(n+1),4) % polynomial order [ 2-4]
f(n)= polyval(p,X(n));
plot(X(n),X(n+1),'-o',X(n),f(n),'-+'); hold on;grid on
legend('data','linear fit')
end

답변 (1개)

Rishabh Mishra
Rishabh Mishra 2021년 1월 7일
Hi,
Try using the following MATLAB functions for curve fitting & creating polynomials from the given data.
  1. polydern
  2. polyfitn
  3. polyn2sym
  4. polyn2sympoly
  5. polyvain
The documentation of above functions is available in MATLAB file exchange. Just type ‘doc functionName’ in your MATLAB console where functionName is any of the above functions.
Feel free to reach out if you are still facing problems while resolving the issue.
  댓글 수: 1
Life is Wonderful
Life is Wonderful 2021년 1월 8일
편집: Life is Wonderful 2021년 1월 8일
Hi Rishabh,
Thank you! But could you please tell me how i am gonna use the (modified names to match doc search) could help me getting the best coefficient and lowest Root mean square error minimum value.
doc polyder
doc polyfit
doc polynom
doc polynomials
doc polyval
I am expecting testbench with a code that send out the comparing coefficient for rmse with lowest value. In the moment , I need to check each iteration record and compare manually / record in a notebook .
I need a regersssion workbench code that generate output for each iteration and store the coeff and rmse . Later on I can change the function you have suggestion.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by