필터 지우기
필터 지우기

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