Hi there,
I am using symbolic array but come across a transpose error. Below is the code:
syms x1 x2 x3
cstr = [6*x1^2 + 3*x2^2 - 2*x2*x3 + 3*x3^2 -17*x1 + 8*x2 -14*x3 + 19, ...
5 - x1 - 2*x2 -x3, ...
7 - 5*x2 - 3*x3, ...
x1*(2 - x1), ...
x2*(2 - x2)];
However, after transposing the array, it becomes:
cstr =
6*x1^2 + 3*x2^2 - 2*x2*x3 + 3*x3^2
8*x2 - 17*x1
19 - 14*x3
5 - 2*x2 - x1
-x3
7 - 3*x3 - 5*x2
-x1*(x1 - 2)
-x2*(x2 - 2)
How can I make correct transposition.

 採用された回答

Birdman
Birdman 2018 年 2 月 20 日
編集済み: Birdman 2018 年 2 月 20 日

0 投票

cstr = [6*x1^2 + 3*x2^2 - 2*x2*x3 + 3*x3^2 - 17*x1 + 8*x2 - 14*x3 + 19, ...
5 - x1 - 2*x2 - x3, ...
7 - 5*x2 - 3*x3, ...
x1*(2 - x1), ...
x2*(2 - x2)];
and
cstr.'
will give you what you want.

3 件のコメント

Dan Li
Dan Li 2018 年 2 月 20 日
Hi Birdman, thanks for the help. But is it caused by the space? The original input makes the entry "6*x1^2 + 3*x2^2 - 2*x2*x3 + 3*x3^2 -17*x1 + 8*x2 -14*x3 + 19" be three segments. I noticed that there is no space before 17*x1 and 14*x3. So this seems a little bit inconvenient that I have to make sure there are spaces.
Birdman
Birdman 2018 年 2 月 20 日
Exactly, you need to leave spaces in those terms, therefore your initial situation did not work out for you.
Dan Li
Dan Li 2018 年 2 月 20 日
Thank you very much.

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

その他の回答 (0 件)

質問済み:

2018 年 2 月 20 日

コメント済み:

2018 年 2 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by