how can i return l21 value

1 view (last 30 days)
R jagadish
R jagadish on 14 Mar 2023
Answered: Dyuman Joshi on 14 Mar 2023
i am unable to return the l21 values as it is saved in a string format
here is my code:
syms l21 l31 l32 u11 u12 u13 u22 u23 u33
L=[1 0 0;l21 1 0;l31 l32 1]
L = 
U=[u11 u12 u13;0 u22 u23;0 0 u33]
U = 
B=L*U
B = 
A=[2 -3 1;1 -1 -2;3 1 -1]
A = 3×3
2 -3 1 1 -1 -2 3 1 -1
x=solve(A==B,[l21,l31,l32,u11,u12,u13,u22,u23,u33])
x = struct with fields:
l21: 1/2 l31: 3/2 l32: 11 u11: 2 u12: -3 u13: 1 u22: 1/2 u23: -5/2 u33: 25
l21
l21 = 

Answers (1)

Dyuman Joshi
Dyuman Joshi on 14 Mar 2023
As you can see above, l21 is stored as a field in the struct x. You need to use dot indexing to get its value -
syms l21 l31 l32 u11 u12 u13 u22 u23 u33
L=[1 0 0;l21 1 0;l31 l32 1];
U=[u11 u12 u13;0 u22 u23;0 0 u33];
B=L*U;
A=[2 -3 1;1 -1 -2;3 1 -1];
x=solve(A==B,[l21,l31,l32,u11,u12,u13,u22,u23,u33])
x = struct with fields:
l21: 1/2 l31: 3/2 l32: 11 u11: 2 u12: -3 u13: 1 u22: 1/2 u23: -5/2 u33: 25
%Accessing field values via dot indexing
x.l21
ans = 
x.u11
ans = 
2

Categories

Find more on Data Type Identification in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!