You could do something like this.
I just made up some numbers to try the code.
Also, obviously variable names like columnOfData are not very meaningful and I wouldn't recommend them but I didn't want to depart to far from your starting point.
I removed some of the ./ and just used / where the operation involved a vector and a scalar so element by element calculations were not needed. Would work with ./ but makes it less clear what you are doing. I also defined x separately from the index in the loop, in case you wanted to use other x values and also so tha you could have an index for recording the RMSE values.
With some more work, you could probably fully vectorize this (eliminate the loop) but at least this should get you started.
a = 2.2
b = 3.4
c = 8.1
d = 10.4
e = 0.6
f = 22.4
avgW = [8;7.2;44;3.12]
columnOfData = [3;9;8.3;2]
g = length(avgW)
x = 1:10000;
for k = 1:10000
wCalc = ( ( a ./ ( ( columnOfData / x(k) ) - b ) ) - c - d - e ) * f;
RMSE(k) = sqrt( sum( ( wCalc - avgW).^2) / g );
end
[RMSEOpt,idx] = min(RMSE)
xOpt = x(idx)
Best Answer