Matrix with unknown values

조회 수: 4 (최근 30일)
Marianna
Marianna 2018년 2월 7일
댓글: Marianna 2018년 2월 8일
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
Jan
Jan 2018년 2월 7일
편집: Jan 2018년 2월 7일
Please fix:
A and X are two arrays [3x1x80] and X is a matrix [3x3x80].
One of the matrices is B.
Please explain "in does not work" with any details. It is easier to suggest a solution than to guess the problem.
Marianna
Marianna 2018년 2월 7일
Thank you. I get this error:
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in fminsearch (line 200)
fv(:,1) = funfcn(x,varargin{:});
Error in findvalues (line 17)
[estimates] = fminsearch(model, start_point, options);

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 2월 7일
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.
  댓글 수: 3
Walter Roberson
Walter Roberson 2018년 2월 8일
No, I think the solution is
sse = sum(ErrorVector(:) .^ 2);
Marianna
Marianna 2018년 2월 8일
Ok. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by