필터 지우기
필터 지우기

Substition of variables in a matrix

조회 수: 1 (최근 30일)
Grillteller
Grillteller 2017년 2월 6일
답변: Karan Gill 2017년 2월 21일
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!

답변 (1개)

Karan Gill
Karan Gill 2017년 2월 21일
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]

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by