フィルターのクリア

How can I make multi parameters using syms, automatically?

1 回表示 (過去 30 日間)
연승 김
연승 김 2021 年 3 月 16 日
コメント済み: Star Strider 2021 年 3 月 16 日
I want to make mulit parameters using syms.
For example
syms 'p%d' [2 2]
This code make matrix [p11, p12 ; p21, p22].
And I want to input a value in the symbolic variables.
Like this
p11 = 1
p12 = 2
p21 = 3
p22 = 4.
I can input a value each. But I want to automatic.
Because as the instance expand, it's hard to input a value each...
syms 'p%d' [20 10]
If I use this code, I have to coding 200 paramaters one by one.
How I can this automatically???

採用された回答

Star Strider
Star Strider 2021 年 3 月 16 日
One approach:
For the (2x2) example:
syms p
P = sym('p%d', [2 2])
v = [1 2 3 4];
P = reshape(v,[],size(P,1)).';
and for the extended (20x10) result:
syms p
P = sym('p%d', [20 10]);
v = 1:200;
P = reshape(v,[],size(P,1)).';
Experiment to get the result you want.
  2 件のコメント
연승 김
연승 김 2021 年 3 月 16 日
Thank you!! it works well!!^^
Star Strider
Star Strider 2021 年 3 月 16 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by