Slow matrix computations with symbolic variables

3 views (last 30 days)
I'm trying to do matrix calculations with symbolic coefficients (the matrices themselves are not symbolic). However, even just adding and multiplying matrices is taking a tremendously long time. For example:
x = sym['x', [1 3]];
A = rand(1000);
B = rand(1000);
C = rand(1000);
x(1)*A + x(2)*B + x(3)*C
takes at least half an hour (I cancelled the computation at that point). Throwing in matrix multiiplication makes the problem even worse. I can understand why things like diagonalizing matrices with symbolic variables would take a long time, but I don't see why something like this should take so long. Can someone explain what the issue is, and maybe offer some advice?
As a side note, the only reason I'm writing functions with symbolic variables is so that I can analytically take derivatives of it. So while I could do something like
f = function F(x)
f = x(1)*A + x(2)*B + x(3)*C;
end
,I couldn't analytically take derivatives of the function (the actual function I'm working with is much longer and messier).

Answers (0)

Categories

Find more on Symbolic Math Toolbox 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!