Clear Filters
Clear Filters

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

4 views (last 30 days)
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

Accepted Answer

Paul
Paul on 14 Apr 2024
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 Comment
Paul
Paul on 15 Apr 2024
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 = 

Sign in to comment.

More Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!