Matrix with unknown values

2 ビュー (過去 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 Center および File ExchangeSolver 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