Borrar filtros
Borrar filtros

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

26 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Paul
Paul el 14 de Abr. de 2024 a las 13:47
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 comentario
Paul
Paul el 15 de Abr. de 2024 a las 16:40
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 = 

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by