Why Doesn't a Symbolic Matrix Equation Simplify Until After Applying subs() ?

36 ビュー (過去 30 日間)
Paul
Paul 2025 年 10 月 18 日 15:26
回答済み: dpb 2025 年 10 月 19 日 11:52
Following code is to derive an expression for the derivative of the magnitude of a vector function of time.
clearvars
syms t real
r = symfunmatrix('r(t)',t,[3,1]);
% results that follow are the same regardless of how R is declared
R = symfunmatrix('R(t)',t,[1,1]);
%syms R(t)
eqn = R(t)^2 == (r.'*r)
eqn(t) = 
eqn = diff(eqn)
eqn(t) = 
At this point, it would be nice if @doc:isolate worked for matrix equations, but it doesn't, so proceed by hand
Rx2 = R*2;
eqn = lhs(eqn)/Rx2 == rhs(eqn)/Rx2
eqn(t) = 
Why doesn't the software automatically simplify the lhs to just diff(R) as it would for a scalar equation?
It's almost as if the software does not know that matrix multipliation is associative (see below).
We could proceed by explicitly converting the lhs to symfun, but shouldn't have to.
symfunmatrix2symfun(lhs(eqn)) == rhs(eqn)
ans(t) = 
Also, if the lhs wern't a scalar then I think the conversion to symfun would result in the lhs defined in terms of its elements, which would be annoying at best and unworkable at worst depending on the dimensions of the problem.
Recognizing that r(t)*inv(R(t)) is a unit vector (don't worry about the case where R(t) == 0)
r_hat = symfunmatrix('r_hat(t)',t,[3,1]);
eqn3 = r_hat == r/R
eqn3(t) = 
then substitute
eqn = subs(eqn,rhs(eqn3),lhs(eqn3))
eqn(t) = 
Lo and behold, the substitution simplifies the lhs. I'm happy that the lhs did simplify, but I'd like to understand why it simplified (and why it did not simplify upstream in the development).
Getting back to that idea of the associative property of matrix multiplication, with R defined as symfunmatrix
diff(R)*(R/R) % expected result
ans(t) = 
(diff(R)*R)/R % correct result, but should be handled better?
ans(t) = 
Oddly enough, it appears that the preceding result is related to R(t) being 1 x 1. No problem with a symfunmatrix of larger dimension
R = symfunmatrix('R(t)',t,[2,2]);
(diff(R)*R)/R
ans(t) = 

回答 (1 件)

dpb
dpb 2025 年 10 月 19 日 11:52
I'd suggest your best chance for a definitive answer plus for there to be any chance of behavior more as you would like you should submit this to Mathworks as an official support request/enhancement request at <Product Support Page>

カテゴリ

Help Center および File ExchangeAssumptions についてさらに検索

製品


リリース

R2025b

Community Treasure Hunt

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

Start Hunting!

Translated by