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

13 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Rishabh Mishra
Rishabh Mishra il 7 Gen 2021
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 Commento
Life is Wonderful
Life is Wonderful il 8 Gen 2021
Modificato: Life is Wonderful il 8 Gen 2021
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by