Multiple input vector for polyfit and get polyval , derive the best coeff & least RMS Error
Afficher commentaires plus anciens
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
Réponses (1)
Rishabh Mishra
le 7 Jan 2021
0 votes
Hi,
Try using the following MATLAB functions for curve fitting & creating polynomials from the given data.
- polydern
- polyfitn
- polyn2sym
- polyn2sympoly
- 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 commentaire
Life is Wonderful
le 8 Jan 2021
Modifié(e) : Life is Wonderful
le 8 Jan 2021
Catégories
En savoir plus sur Curve Fitting Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!