Matlab symbolic : calculate expression with vector of symbolic variables
Afficher commentaires plus anciens
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 ?
Réponses (2)
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
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

