Substition of variables in a matrix

3 views (last 30 days)
Grillteller
Grillteller on 6 Feb 2017
Answered: Karan Gill on 21 Feb 2017
Hi,
I have a matrix in the form of
Adiff=
[ Xi1, Yi1, Zi1, 1, 0, 0, 0, 0, -Xi1*xi1, -Yi1*xi1, -Zi1*xi1]
[ 0, 0, 0, 0, Xi1, Yi1, Zi1, 1, -Xi1*yi1, -Yi1*yi1, -Zi1*yi1]
[ Xi2, Yi2, Zi2, 1, 0, 0, 0, 0, -Xi2*xi2, -Yi2*xi2, -Zi2*xi2]
[ 0, 0, 0, 0, Xi2, Yi2, Zi2, 1, -Xi2*yi2, -Yi2*yi2, -Zi2*yi2]
Now i want to substitute the symbolic vectors Xi =[Xi1; Xi2 ...] , Yi= [Yi1; Yi2 ...] etc... with vectors with actual values,
e.g.
X1 = -390.93; Y1 = -477.52; Z1 = 0.07;
X2 = -101.5; Y2 = -479.19; Z2 = 0.11;
Xg = [X1; X2; X3; X4; X5; X6];
Yg = [Y1; Y2; Y3; Y4; Y5; Y6];
Zg = [Z1; Z2; Z3; Z4; Z5; Z6];
I already tried
.
for i=1:1:2
A = subs(Adiff, [Xi(i), Yi(i), Zi(i)], [Xg(i), Yg(i), Zg(i)]);
end
But in this loop, only the second variables will be replaced.
Edit: Additional code pieces
Syms
Xi = sym('Xi',[1,2]);
Yi = sym('Yi',[1,2]);
Zi = sym('Zi',[1,2]);
Thanks in advance!

Answers (1)

Karan Gill
Karan Gill on 21 Feb 2017
This works. Example is below. Can you provide the code for getting Adiff? Are you creating Xi,Yi,Zi first and using them to create Adiff?
>> A = sym('A%d%d',[3 3])
V = A(1,:)
values = randi(100,1,3)
subs(A,V,values)
A =
[ A11, A12, A13]
[ A21, A22, A23]
[ A31, A32, A33]
V =
[ A11, A12, A13]
values =
15 43 92
ans =
[ 15, 43, 92]
[ A21, A22, A23]
[ A31, A32, A33]

Community Treasure Hunt

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

Start Hunting!