Find the value of a and k that minimise RMSE

2 vues (au cours des 30 derniers jours)
Tsang Chak Ng
Tsang Chak Ng le 19 Déc 2017
Hello,I am trying to find the value of a and k that minimise my function RMSE,I have input the following code,can I just asked where have I got wrong since Matlab asked me to have more arguments for some reason?
%lightprog
function RMSE=lightprog(V)
k=V(1);a=V(2)
stimulus=[2 4 6 8 10 12]
data=[1.1 1.5 2.1 2.5 2.9 3.2]
modelS=k*(stimulus.^a);
RMSE=sqrt(mean(modelS-data).^2)
return
[k,a]=fminsearch('lightprog',[0,0])

Réponses (1)

Ben Drebing
Ben Drebing le 21 Déc 2017
The function needs to be defined at the bottom of the file, if you would like to run your code in this way. Try:
[k,a]=fminsearch(@lightprog,[0,0])
function RMSE=lightprog(V)
k=V(1);a=V(2)
stimulus=[2 4 6 8 10 12]
data=[1.1 1.5 2.1 2.5 2.9 3.2]
modelS=k*(stimulus.^a);
RMSE=sqrt(mean(modelS-data).^2)
return
end

Catégories

En savoir plus sur Signal Integrity Kits for Industry Standards 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!

Translated by