Matrix with unknown values
6 views (last 30 days)
Show older comments
Dear community, I am loosing my mind with this simple problem:
A = B .* X
where A and B are two arrays [3x1x80] and X is a matrix [3x3x80].
As X has 5 unknown values I tried to implement this matrix equation with fminsearch:
function [estimates,model] = findvalues(A,B)
X0 = [0.1 0.1 0.2 0.3 0.56];
model = @maps;
options=optimset('Display','off','MaxIter',100000,'MaxFunEvals',100000,'TolX',1e-8);
[estimates] = fminsearch(model, X0, options);
function [ FittedCurve,sse] = maps(params)
X = zeros(3,3,80);
a = params(1);
b = params(2);
c = params(3);
d = params(4);
e = params(5);
X(1,1,:) = -(Rb + (1 ./ a));
X(1,2,:) = (1 ./ b) - (((e - (1 - f)) ./ f) ./ (V ./ f) .* (1 ./ c));
X(2,1,:) = (1 ./ a);
c = -(((r1o .* CRo) + R1o0) + (1 ./ b));
X(2,2,:) = c';
X(2,3,:) = (1 ./ c);
X(3,2,:) = (1 ./ b) - ((d./(V.*(1-h))).*(1./a));
X(3,3,:) = (-(Ri + (1 ./ c)));
for i = 1:80
FittedCurve(:,:,i) = mtimes( ((sin(a) .* (I - ((exp(X(:,:,i))).^TR))) , B);
end
ErrorVector = FittedCurve - A;
sse = sum((ErrorVector .^ 2),3);
end
end
It does not work. Is it because maybe fminsearch is not the most suitable function for this problem? Or is there a conceptual mistake?
I really thank you for the support.
2 Comments
Accepted Answer
Walter Roberson
on 7 Feb 2018
Your function must return a scalar to be used with fminsearch. You have 3D array A so ErrorVector is 3D and you sum() the square of that over the 3rd dimension, which is going to give you a 2D array instead of a scalar.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!