MATLAB Answers

Error while finding determinant

조회 수: 6(최근 30일)
Meghna V S
Meghna V S 2021년 4월 28일
답변: Steven Lord 2021년 5월 3일
The code I ran
syms s t
N1 = ((1-s)*(1-t))/4;
N2 =((1+s)*(1-t))/4;
N3 =((1+s)*(1+t))/4;
N4 =((1-s)*(1+t))/4;
x1 =1; x2 = 5; x3 =8; x4 = 1;
y1 = 1; y2 = 1; y3 = 6; y4 = 6;
x = N1*x1 + N2*x2 + N3*x3 + N4*x4
X = simplify(x)
y = N1*y1 + N2*y2 + N3*y3 + N4*y4
Y = simplify(y)
J = [diff(x,s) diff(x,t);diff(y,s) diff(y,t)]
determinant = det(J)
I am getting an error like this:
Error using sym/subsindex (line 857)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.
Error in sym/subsref (line 902)
R_tilde = builtin('subsref',L_tilde,Idx);
  댓글 수: 1
Dyuman Joshi
Dyuman Joshi 2021년 5월 1일
I ran the same code and it ran without an error. I assume that you have the symbolic math toolbox installed.

댓글을 달려면 로그인하십시오.

답변(2개)

Shubham Khatri
Shubham Khatri 2021년 5월 3일
Hello,
Generally this error occurs due to improper use or declaration of the symbolic variables.I tried the code on my end. The code runs fine. To my understanding, you dont have symbolic math toolbox installed. Please refer to this community answer to get support on how to install a new toolbox on existing MATLAB installation.
Hope it helps

Steven Lord
Steven Lord 2021년 5월 3일
Do you by any chance have a variable named det in your workspace? If so you will not be able to call the det function until that variable is renamed or deleted.
det = 42;
syms x
det([x, x.^2; x.^3, 1])
Error using sym/subsindex (line 864)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic variables, and function body must be sym expression.

Community Treasure Hunt

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

Start Hunting!

Translated by