Matlab symbolic : calculate expression with vector of symbolic variables
    5 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
Hello,
I need to calculate with Matlab symbolic the following expression :

"l" is a vector of symbolic variables and "C_l" also (same length than "l", that is to say, `l_max -l_min = 3000-10=2990`).
To calculate this, I did :
    clear
    syms l_min l_max fsky Np var1D varO1
    l_min = 10
    l_max = 3000
    l = sym('l_',[1 (l_max - l_min)])
    C_l = sym('C_l_',[1 (l_max -l_min)])
    % First observable
    var1D = symsum(2/((2*l+1)*fsky*Np^2), l, l_min, l_max)
    varO1 = var1D/symsum(C_l, l_min, l_max)^2
    Error using symengine
    Invalid operands.
    Error in sym/privBinaryOp (line 1030)
                Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
    Error in / (line 373)
            X = privBinaryOp(A, B, 'symobj::mrdivide');
    Error in inequality (line 9)
    var1D = symsum(2/((2*l+1)*fsky*Np^2), l, l_min, l_max)
I don't know to proceed to compute the expression of sigma_o,1^2 just above (varO1 in the code snippet).
Where is my error ?
0 comentarios
Respuestas (2)
  VBBV
      
      
 el 19 de Nov. de 2023
        Use the element wise operator for  / and ^   ... i.e.  ./ and .^ as below
clear
    syms l_min l_max fsky Np var1D var2D varO1 varO2
    l_min = 10
    l_max = 300
    syms L
    %l = sym('l_',[1 (l_max - l_min)])
    C_l = sym('C_l_',[1 (l_max -l_min)])
    % First observable
    var1D = symsum(2/((2*L+1)*fsky*Np^2), L, l_min, l_max)
    varO1 = var1D/sum(C_l)^2
    % Second observable
    var2D = symsum(((2*L+1)*fsky*Np^2), L, l_min, l_max)
    varO2 = var2D./symsum((2*L+1)*C_l, L, l_min, l_max).^2  % use element wise operator
0 comentarios
Ver también
Categorías
				Más información sobre Assumptions en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






