syntax error for matrix

1 view (last 30 days)
Thomas O'Reilly
Thomas O'Reilly on 6 Dec 2021
Commented: Star Strider on 6 Dec 2021
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);

Answers (1)

Star Strider
Star Strider on 6 Dec 2021
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 Comments
Thomas O'Reilly
Thomas O'Reilly on 6 Dec 2021
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 on 6 Dec 2021
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.

Sign in to comment.

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!