Matlab symbolic : calculate expression with vector of symbolic variables
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I need to calculate with Matlab symbolic the following expression :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/828520/image.png)
"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 个评论
回答(2 个)
VBBV
2023-11-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Physical Channels 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!