I have an issue about the declaration of an array of symbolic variables.
In the following code snippet, eigenv_sp
is a 7x7 numerical array and x
is a symbolic 7x7x2 array :
% Symbolic variables
x = sym('x', [7 7 2]);
aP1 = sym('aP1', [7 7]);
for k=1:7
for l=1:7
aP1(k,l) = sum(x(k,1:7,1).*eigenv_sp(1:7,l));
end
end
I get the following error :
Error using symengine
Array sizes must match.
Error in sym/privBinaryOp (line 946)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in .* (line 267)
X = privBinaryOp(A, B, 'symobj::zip', '_mult');
Error in test1 (line 72)
aP1(k,l) = sum(x(k,1:7,1).*eigenv_sp(1:7,l))
I don't understand how to mix the symbolic expression of x(k,1:7,1)
and the numerical element
eigenv_sp(1:7,l)
.
Indeed, after this try to mix both, I would like to implement a system of equations to solve with 49 unknown variables (I am working with 7x7 matrix size) and I don't how to proceed.
I tried to start from the function :
function F=myfun(x,i,j)
% First part
F(1) = a2(i,j) + sum(aP1(i,1:7).*bP2T(1:7,j)) + sum(bP2(i,1:7).*aP1T(1:7,j)) + b2(i,j) - eq(i,j);
% second part
for i=1:7
for j=1:7
F(7*(i-1)+j+1) = sum(F1(i,1:7).*aP1(1:7,j)) + sum(F1(i,1:7).*bP2(1:7,j)) + sum(F2(i,1:7).*aP1(1:7,j)) + sum(F2(i,1:7).*bP2(1:7,j)) - ...
sum(aP1(i,1:7).*ad1(1:7,j)) + sum(bP2(i,1:7).*ad1(1:7,j)) + sum(adP1(i,1:7).*dP2(1:7,j)) + sum(bP2(i,1:7).*dP2(1:7,j));
end
end
end
and the solving part :
% Solution of system of non linear equations with loop
y = zeros(7, 7, 2);
for i=1:7
for j=1:7
a0 = 1e7;
b0 = 1e7;
x0 = [ a0 b0];
fun = @(x)myfun(x,i,j);
y(i,j,:) = fsolve(fun,x0)
end
end
The goal is to get a(i,j)=x(i,j,1)
and b(i,j)=x(i,j,2)
which are the solutions of the 2 matrices that I want to build by each solving which gives (i,j) element.
What might be wrong here? How can I circumvent this problem of implementation in Matlab?
Update
Sorry, the input matrices are located here :
and the Matlab test1.m
that reproduces the error :