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
Ameer Hamza 2020-9-10
Can you share the mathematical form of the equation you are trying to solve?

请先登录,再进行评论。

采纳的回答

Star Strider
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))
.

更多回答(1 个)

Ameer Hamza
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.');

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by