eqn(t) = 
Why Doesn't a Symbolic Matrix Equation Simplify Until After Applying subs() ?
Show older comments
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 = diff(eqn)
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
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)
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
then substitute
eqn = subs(eqn,rhs(eqn3),lhs(eqn3))
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
(diff(R)*R)/R % correct result, but should be handled better?
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
Accepted Answer
More Answers (0)
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

