Error using symengine and matrix must be square
조회 수: 11 (최근 30일)
이전 댓글 표시
While typing the following I get this error:
- error using symengine
- matrix must be square
A= [(2.*s +2) - (2.*s + 1) -1 -(2.*s +1)*(9.*s +1) -4.*s -1 -4.*s*(4.*s +1 +1./s)];
>> B= [I1;I2;I3];
>> C=[V;0;0];
>> B= inv(A).*C;
Error using symengine
Matrix must be square.
Where does the error comes from and how can I solve it?
댓글 수: 4
Ameer Hamza
2020년 9월 10일
Can you share the mathematical form of the equation you are trying to solve?
채택된 답변
Star Strider
2020년 9월 10일
편집: Star Strider
2020년 9월 10일
MATLAB will not automatically parse ‘A’ into separate elements. It is necessary to use appropriate delimiters to separate the individual elements (,) to define the elements and the rows (;).
Try this:
syms I1 I2 I3 V s
A= [(2.*s +2), - (2.*s + 1), -1; -(2.*s +1), (9.*s +1), -4.*s; -1, -4.*s, (4.*s +1 +1./s)];
B= [I1;I2;I3];
C=[V;0;0];
Eq = C == A * B;
[Isln] = solve(Eq, [I1,I2,I3]);
I1 = simplify(Isln.I1, 'Steps',100)
I2 = simplify(Isln.I2, 'Steps',100)
I3 = simplify(Isln.I3, 'Steps',100)
producing:
I1 =
(V*(20*s^3 + 13*s^2 + 10*s + 1))/(24*s^4 + 30*s^3 + 17*s^2 + 16*s + 1)
I2 =
(V*(s + 1)*(8*s^2 + 2*s + 1))/(24*s^4 + 30*s^3 + 17*s^2 + 16*s + 1)
I3 =
(V*s*(8*s^2 + 13*s + 1))/(24*s^4 + 30*s^3 + 17*s^2 + 16*s + 1)
EDIT — (10 Sep 2020 at 15:52)
To calculate them as impedances:
Z1 = simplify(V/I1, 'Steps',100)
Z2 = simplify(V/I2, 'Steps',100)
Z3 = simplify(V/I3, 'Steps',100)
producing:
Z1 =
(24*s^4 + 30*s^3 + 17*s^2 + 16*s + 1)/(20*s^3 + 13*s^2 + 10*s + 1)
Z2 =
3*s + (8*s^2 + 13*s + 1)/((s + 1)*(8*s^2 + 2*s + 1))
Z3 =
(24*s^4 + 30*s^3 + 17*s^2 + 16*s + 1)/(s*(8*s^2 + 13*s + 1))
.
댓글 수: 0
추가 답변 (1개)
Ameer Hamza
2020년 9월 10일
An alternate solution is to use the inv() or mldivide (\) operator to solve the equation. Since this seems to be the lalpalce transform of a circuit, the following also shows how to get the time-domain solution for a specific voltage signal (v).
syms s V(s) t
A = [(2*s+1) -(2*s+1) -1;
-(2*s+1) (9*s+1) -4*s;
-1 -4*s (4+1+1/s)];
C = [V; 0; 0];
I = A\C; % same as inv(A)*B but more efficient
% Let v is a constant signal, i.e., v=1
V1 = 1/s;
I1 = subs(I, V, V1);
i(t) = ilaplace(I1, s, t);
tv = 0:0.01:1;
iv = double(subs(i, t, tv));
plot(tv, iv.');

참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
