0

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 :

Fisher_GCsp_flat

Fisher_XC_GCph_WL_flat

and the Matlab test1.m that reproduces the error :

test1.m

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please provide a complete and minimal example that can be run on our computer. What is `a2`? what is`bP2T` ? Why are you overwriting all the elements of `aP1` in your first loop ? This question cannot be answered if you do not provide all the necessary information. – obchardon Nov 30 '20 at 17:09
  • @abchardon I provided you the 2 Fisher matrices and the script (`test1.m`) that reproduces the error : hoping this will help –  Dec 01 '20 at 03:44

0 Answers0