vpasolve() Unable to find variables in equations for solving determinant of a matrix that has symbolic inside as zero

조회 수: 13 (최근 30일)
Hi guys!
I am trying to get what 'p' value would make the determinate of matrix Z to be zero. Matrix Z is constructed by taking some user inputs.
I ran the code and it gives error:
Error using sym/vpasolve
Unable to find variables in equations.
You can input any numbers 5 as number of elements and 1, 1, 1, 1, 1 for E values for testing purposes
Thank you!
% define variables
L = 1; % in metre
w = 10 * 10^-3; % width in m
h = 3.5 * 10^-3; % height in m
I = (1/12) * w * (h^3) % area moment of inertia about bending axies
% ask user for # of element
prompt = "What is the element #? ";
n = input(prompt);
% coifficient matrix for stiffness
L = 1 / n;
cons1 = [12, 6*L, -12, 6*L;
6*L, 4*L^2, -6*L, 2*L^2;
-12, -6*L, 12, -6*L;
6*L, 2*L^2, -6*L, 4*L^2];
cons2 = [36, 3*L, -36, 3*L;
3*L, 4*L^2, -3*L, -L^2;
-36, -3*L, 36, -3*L;
3*L, -L^2, -3*L, 4*L^2];
% initialize stiffness matrix with 0
Z1 = zeros(2*n+2,2*n+2);
% Z2 = zeros(2*n+2,2*n+2);
% Z2 = repmat(sym(0),2*n+2,2*n+2);
Z2 = zeros(2*n+2,2*n+2,'sym');
% ask user for E values to compute EI/L^3
syms p
K1 = zeros (1, n);
K2 = -p / (30*L);
for i = 1:n
prompt = "Enter E value in GPa (10^9) of " + i + "th element: ";
K1(1, i) = 10^9 * (input(prompt)) * I / (L^3);
end
% stiffness matrix Z1
for i=1:n
%1st row elements
Z1(2*i-1, 2*i-1) = Z1(2*i-1, 2*i-1) + K1(1, i) * cons1(1,1);
Z1(2*i-1, 2*i) = Z1(2*i-1, 2*i) + K1(1, i) * cons1(1,2);
Z1(2*i-1, 2*i+1) = Z1(2*i-1, 2*i+1) + K1(1, i) * cons1(1,3);
Z1(2*i-1, 2*i+2) = Z1(2*i-1, 2*i+2) + K1(1, i) * cons1(1,4);
%2nd row elements
Z1(2*i, 2*i-1) = Z1(2*i, 2*i-1) + K1(1, i) * cons1(2,1);
Z1(2*i, 2*i) = Z1(2*i, 2*i) + K1(1, i) * cons1(2,2);
Z1(2*i, 2*i+1) = Z1(2*i, 2*i+1) + K1(1, i)* cons1(2,3);
Z1(2*i, 2*i+2) = Z1(2*i, 2*i+2) + K1(1, i) * cons1(2,4);
%3rd row elements
Z1(2*i+1, 2*i-1) = Z1(2*i+1, 2*i-1) + K1(1, i) * cons1(3,1);
Z1(2*i+1, 2*i) = Z1(2*i+1, 2*i) + K1(1, i) * cons1(3,2);
Z1(2*i+1, 2*i+1) = Z1(2*i+1, 2*i+1) + K1(1, i) * cons1(3,3);
Z1(2*i+1, 2*i+2) = Z1(2*i+1, 2*i+2) + K1(1, i) * cons1(3,4);
%4th row elements
Z1(2*i+2, 2*i-1) = Z1(2*i+2, 2*i-1) + K1(1, i) * cons1(4,1);
Z1(2*i+2, 2*i) = Z1(2*i+2, 2*i) + K1(1, i) * cons1(4,2);
Z1(2*i+2, 2*i+1) = Z1(2*i+2, 2*i+1) + K1(1, i) * cons1(4,3);
Z1(2*i+2, 2*i+2) = Z1(2*i+2, 2*i+2) + K1(1, i) * cons1(4,4);
end
% stiffness matrix Z2
for i=1:n
%1st row elements
Z2(2*i-1, 2*i-1) = Z2(2*i-1, 2*i-1) + K2 * cons2(1,1);
Z2(2*i-1, 2*i) = Z2(2*i-1, 2*i) + K2 * cons2(1,2);
Z2(2*i-1, 2*i+1) = Z2(2*i-1, 2*i+1) + K2 * cons2(1,3);
Z2(2*i-1, 2*i+2) = Z2(2*i-1, 2*i+2) + K2 * cons2(1,4);
%2nd row elements
Z2(2*i, 2*i-1) = Z2(2*i, 2*i-1) + K2 * cons2(2,1);
Z2(2*i, 2*i) = Z2(2*i, 2*i) + K2 * cons2(2,2);
Z2(2*i, 2*i+1) = Z2(2*i, 2*i+1) + K2 * cons2(2,3);
Z2(2*i, 2*i+2) = Z2(2*i, 2*i+2) + K2 * cons2(2,4);
%3rd row elements
Z2(2*i+1, 2*i-1) = Z2(2*i+1, 2*i-1) + K2 * cons2(3,1);
Z2(2*i+1, 2*i) = Z2(2*i+1, 2*i) + K2 * cons2(3,2);
Z2(2*i+1, 2*i+1) = Z2(2*i+1, 2*i+1) + K2 * cons2(3,3);
Z2(2*i+1, 2*i+2) = Z2(2*i+1, 2*i+2) + K2 * cons2(3,4);
%4th row elements
Z2(2*i+2, 2*i-1) = Z2(2*i+2, 2*i-1) + K2 * cons2(4,1);
Z2(2*i+2, 2*i) = Z2(2*i+2, 2*i) + K2 * cons2(4,2);
Z2(2*i+2, 2*i+1) = Z2(2*i+2, 2*i+1) + K2 * cons2(4,3);
Z2(2*i+2, 2*i+2) = Z2(2*i+2, 2*i+2) + K2 * cons2(4,4);
end
Z = Z1 - Z2;
result = det(Z);
vpasolve(result == 0);
  댓글 수: 7
Felis Flora
Felis Flora 2022년 11월 28일
Hey! I did check more carefully into the codes and I realize my Z2 matrix is decleared as sym becuase I wanted to put 'p' inside. I changed it back to double by
Z2 = zeros(2*n+2,2*n+2);
Now I am getting p values as:
p =
53.593749999999851
47.323625082480667
34.747271605892116
23.517947908203610
15.476909016569952
5.876010185987303
3.220949355182853
1.415053093988928
-0.000000000000001
0.352707539190412
10.824601932307521
10.718749999999885
Also I was trying to isolate A and B using isolate(Z, p) if I undertsanded you correctly but it gives error saying
Error using sym/isolate
First argument must be an equation.
I searched up and realize that the matrix expression there is not an accetable input for isolate().
But I feel there is a high chance that I misunderstood isolate constants
Torsten
Torsten 2022년 11월 28일
Also I was trying to isolate A and B using isolate(Z, p) if I undertsanded you correctly but it gives error saying
Error using sym/isolate
First argument must be an equation.
I meant to manually isolate them in your code, not to use the isolate command.
You set n = 5 ? And are the results for p as expected ?

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

답변 (1개)

Varun
Varun 2023년 9월 6일
Hi Felis,
After looking at your code, I perceive that you have created a symbolic variable ‘p and you are trying to get solutions for 'p' that would make the determinate of matrix Z to be 0 but you are facing error while doing so. I reproduced the issue locally as well for your given input of n as 5 and elements E as 1,1,1,1,1.
Actually, in last second line result=det(Z); the determinant of matrix ‘Z’ is zero for the specified input, as well as most of the other (test) inputs. So, “result” becomes independent of symbolic variable ‘p’. And as there is no other symbolic variable present in the “result” as it is 0, using vpasolve results into the above error.
To resolve the error, you can recheck the calculation of matrix Z because “det(Z)” is expected in terms of symbolic variable ‘p but it comes out to be 0 always. I tried changing Z(1,1) to 1 (for testing purpose) so that det(Z) is non-zero and has ‘p’ in the expression, the error was gone and “vpasolve” gave some solutions to ‘p’.
Refer following page to learn more on using “vpasolve”:
Hope this helps.

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by