Inverse Matrix for 6x6 matrix with variables
60 ビュー (過去 30 日間)
古いコメントを表示
I am trying to find the inverse of the matrix above. Here is my code:
x = symvar('x')
y = symvar('y')
z = symvar ('z')
A=[x y y 0 0 0; y x y 0 0 0; y y x 0 0 0; 0 0 0 z 0 0; 0 0 0 0 z 0; 0 0 0 0 0 z]
b=inv(A)
This is giving me the following error:
Error using inv
Invalid data type. Input matrix must be double or single.
Error in untitled (line 5)
b=inv(A)
Could someone explain to me what I'm doing wrong? I'm fairly inexperienced with matlab and I'm not sure what is wrong. Any information is greatly appreciated. Thank you!
0 件のコメント
回答 (2 件)
Stephen23
2023 年 11 月 7 日
syms x y z
A = [x,y,y,0,0,0; y,x,y,0,0,0; y,y,x,0,0,0; 0,0,0,z,0,0; 0,0,0,0,z,0; 0,0,0,0,0,z];
b = inv(A)
3 件のコメント
John D'Errico
2023 年 11 月 7 日
You may have written a function of your own, named inv. That would be a truly terrible idea.
Steven Lord
2023 年 11 月 7 日
The symvar function does not define symbolic variables. It identifies identifiers in an expression (other than those in a small list of excluded identifiers) that could be variables and returns those identifiers in a cell array of text data.
x = symvar('x')
y = symvar('y')
z = symvar ('z')
So when you construct A, it is not a symbolic variable. It's a cell array.
A=[x y y 0 0 0; y x y 0 0 0; y y x 0 0 0; 0 0 0 z 0 0; 0 0 0 0 z 0; 0 0 0 0 0 z]
whos x y z A
Instead, you should use the sym or syms functions to define symbolic variables (as shown in the answer from @Stephen23) and create A using those symbolic variables.
syms x y z
A=[x y y 0 0 0; y x y 0 0 0; y y x 0 0 0; 0 0 0 z 0 0; 0 0 0 0 z 0; 0 0 0 0 0 z]
whos x y z A
The inv function is defined for sym arrays.
AI = inv(A)
The fact that the symvar function you called didn't display anything makes me suspect that you might be using a symvar.m file other than the ones in MATLAB, Symbolic Math Toolbox, or Curve Fitting Toolbox. Or did you simply not show us the output that you received when you ran the code? What does this command show you when you run it?
which -all symvar
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Linear Algebra についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!