Find the value of a and k that minimise RMSE

1 次查看(过去 30 天)
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])

回答(1 个)

Ben Drebing
Ben Drebing 2017-12-21
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

类别

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