syntax error for matrix

I get the error on the first open bracket, here's the code.
close all; clear all;
syms s V;
A = [3+2+1*s 1*s+2 -3; -s-2 2+1*s+2*s+4*s -2*s; -3 -2*s 3+(1/(2*s))+2s];
B = [V;0;0];
[I]=linsolve(A,B);

回答 (1 件)

Star Strider
Star Strider 2021 年 12 月 6 日

1 投票

Typo:
A = [3+2+1*s 1*s+2 -3; -s-2 2+1*s+2*s+4*s -2*s; -3 -2*s 3+(1/(2*s))+2s]
↑ ← MISSING MULTIPLICATION OPERATOR
Correct that, and it runs without error —
syms s V
sympref('AbbreviateOutput',false);
A = [3+2+1*s 1*s+2 -3; -s-2 2+1*s+2*s+4*s -2*s; -3 -2*s 3+(1/(2*s))+2*s];
B = [V;0;0];
[I]=linsolve(A,B)
I = 
.

5 件のコメント

Thomas O'Reilly
Thomas O'Reilly 2021 年 12 月 6 日
That was fast. Thank you. That got rid of the syntax error but it isn't giving me any output. You know any reason that would happen?
Star Strider
Star Strider 2021 年 12 月 6 日
My pleasure!
It gives me output (as demonstrated), so I guess that depends on the definition of ‘output’.
Numeric output would require that the functions be evaluated at one (or more) values of the Laplace variable s with specific values of V, although that may be variable as well (for example an A-C voltage source, although that could be modeled by a Laplace transform as well).
Simplifying them may provide some benefit —
syms s V
sympref('AbbreviateOutput',false);
A = [3+2+1*s 1*s+2 -3; -s-2 2+1*s+2*s+4*s -2*s; -3 -2*s 3+(1/(2*s))+2*s];
B = [V;0;0];
[I]=simplify(linsolve(A,B), 500)
I = 
However I’m not certain that provides much additional clarity.
This is the best I can do.
.
Thomas O'Reilly
Thomas O'Reilly 2021 年 12 月 6 日
My output shows the file name and then gives me nothing else? I didn't use the simplify command or the sympref line either.
Thomas O'Reilly
Thomas O'Reilly 2021 年 12 月 6 日
It works with simplify, so thanks again. But how do you get the output look so nice?
I =
(V*(20*s^3 + 50*s^2 + 19*s + 2))/(24*s^4 + 172*s^3 + 184*s^2 + 89*s + 14)
(V*(4*s^3 + 26*s^2 + 13*s + 2))/(24*s^4 + 172*s^3 + 184*s^2 + 89*s + 14)
(2*V*s*(2*s^2 + 25*s + 6))/(24*s^4 + 172*s^3 + 184*s^2 + 89*s + 14)
Star Strider
Star Strider 2021 年 12 月 6 日
The typeset (LaTeX) output is the default here with the online Run feature. The same is also possible using the Live Editor (that I use occasionally), or by using the latex function and then a LaTeX interpreter. See The (Not So) Short Introduction to LaTeX2e - lshort.pdf for more details on LaTeX.

サインインしてコメントする。

製品

リリース

R2021b

タグ

質問済み:

2021 年 12 月 6 日

コメント済み:

2021 年 12 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by