How can I substitute big symbolic matrices without adressing every element in it?

I need to substitute a symbolic matrix in an symbolic expression with real values. I know this can be done by sbstituting every scalar in the matrix at a time. Unfortunately, this is not possible for me since the matrices can be really big. My code looks like
N = 3; % Dimension of the state space
x_sym = sym('x_sym', [N,1]); % symbolic expression for the particle location
u1_sym = sym('u1_sym', [N,1]); % mean vector of the first Gaussian PDF
P1_sym = sym('P1_sym', [N,N]); % covariance matrix of the first Gaussian PDF
w1_sym = sym('w1_sym', [1,1]); % weight of the first Gaussian PDF
u2_sym = sym('u2_sym', [N,1]); % mean vector of the second Gaussian PDF
P2_sym = sym('P2_sym', [N,N]); % covariance matrix of the second Gaussian PDF
w2_sym = sym('w2_sym', [1,1]); % weight of the second Gaussian PDF
k1_sym = w1_sym/sqrt((2*pi)^N*det(P1_sym));
k2_sym = w2_sym/sqrt((2*pi)^N*det(P2_sym));
u_sym = 1/(k1_sym*exp(-0.5*(x_sym-u1_sym).'*inv(P1_sym)*(x_sym-u1_sym)) + k2_sym*exp(-0.5*(x_sym-u2_sym).'*inv(P2_sym)*(x_sym-u2_sym)))* ...
(k1_sym*exp(-0.5*(x_sym-u1_sym).'*inv(P1_sym)*(x_sym-u1_sym))*inv(P1_sym)*(u1_sym-x_sym) + ...
k2_sym*exp(-0.5*(x_sym-u2_sym).'*inv(P2_sym)*(x_sym-u2_sym))*inv(P2_sym)*(u2_sym-x_sym));
V_sym = jacobian(u_sym,x_sym);
Now I need to replace the symbolic vectors and matrices in the expression for u_sym and V_sym with real values. Is there any way to do this without addressing every element of the matrices?
If someone could help me I would be really thankful!

Answers (1)

x_sym and u1_sym and so on are already vectors of symbolic variables, suitable for putting into the second argument of subs()
subs(u_sym, x_sym, num2cell(Vector_Of_X_Values))

Categories

Asked:

on 6 Aug 2015

Answered:

on 6 Aug 2015

Community Treasure Hunt

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

Start Hunting!