Using fminsearch to minimize root mean square error.
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
_After searching around the net for a while I have not found a good answer to this question. Please point me to one or help out if possible.
I have created a function to calculate the root mean square error of a column vector K with a scalar x:
function [rootmeansquare] = RMSE (K, x)
rootmeansquare = sqrt ( sum ( (K - x) .^ 2 )
I want to minimize RMSE for a defined vector K by adjusting x. Can I use the fminsearch function to do this? If so how?
0 commentaires
Réponses (1)
Paulo Silva
le 23 Fév 2011
K=[1 2 3 4 5 6]; %some data to test
rms =@(x)sqrt(sum((K - x).^ 2)); %function similar to yours
fminsearch(rms,0) %find the x
Another way
x=-20:0.01:20;
y=zeros(1,numel(x));
for i=1:numel(x)
y(i)=sqrt(sum((K - x(i)).^ 2));
end
ymin=min(y)
xmin=x(y==ymin)
hold on
plot(x,y)
plot(xmin,ymin,'ro')
text(xmin,ymin,['xmin=' num2str(xmin) char(10) 'ymin=' num2str(ymin)])
0 commentaires
Voir également
Catégories
En savoir plus sur Function Approximation and Clustering dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!