The mathematical expressions resulting from two different symbolic computations are significantly different.

1 次查看(过去 30 天)
The mathematical expressions resulting from two different symbolic computations are significantly different. Does this suggest that MATLAB’s symbolic computation functionality is not yet fully developed?
I demonstrated the calculation steps of the variance of a ‘random vector’s linear combination’ through symbolic computation. I used two methods in total. One is to calculate the ‘random vector’s linear combination’, and then use Var to directly calculate the variance. The other is to normalize the random vector, and then use matrix multiplication to calculate the variance. Both methods ultimately yielded the same result. However, the mathematical expressions of the results showed a significant difference in form. Such a simple operation resulted in such a large difference in the form of the results. Therefore, more complex symbolic operations may lead to significant differences in the final result form due to differences in calculation steps.
Does this imply that MATLAB’s symbolic computation functionality is still not fully developed? I wonder if Maple or sympy have the same issue?
1、
clear
syms a b X Y c Z K M m l;
X=sym('x',[1 2]);
Y=sym('y',[1 2]);
c=[a b];
Z=[X;Y];
var(c*Z,1,2)
2、
clear
syms a b X Y c Z K M m l;
X=sym('x',[1 2]);
Y=sym('y',[1 2]);
c=[a b];
Z=[X;Y];
l=(Z(:,1)+Z(:,2))/2;
Z=Z-l;
(c*((Z)*((Z).'))*(c.'))/2

采纳的回答

Paul
Paul 2024-4-14
Case 2 can be much simplified. Were you expecting the simplified result to be returned?
clear
syms a b X Y c Z K M m l;
X=sym('x',[1 2]);
Y=sym('y',[1 2]);
c=[a b];
Z=[X;Y];
Note that var is one of those base Matlab functions that works with sympolic inputs (at least in this case)
which var(c*Z,1,2)
/MATLAB/toolbox/matlab/datafun/var.m
v1 = var(c*Z,1,2)
v1 = 
clear
syms a b X Y c Z K M m l;
X=sym('x',[1 2]);
Y=sym('y',[1 2]);
c=[a b];
Z=[X;Y];
l=(Z(:,1)+Z(:,2))/2;
Z=Z-l;
v2 = (c*((Z)*((Z).'))*(c.'))/2
v2 = 
simplify(v2)
ans = 
  1 个评论
Paul
Paul 2024-4-15
Also, the Symbolic Math Toolbox assumes all variables are complex unless otherwise indicated. In this problem, the Case 1 expression can be simplified if all of the variables in the expression are real and assumed as such
syms a b X Y c Z K M m l real
X=sym('x',[1 2],'real');
Y=sym('y',[1 2],'real');
c=[a b];
Z=[X;Y];
var(c*Z,1,2)
ans = 
simplify(ans)
ans = 

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by