How can I make multi parameters using syms, automatically?

1 visualización (últimos 30 días)
연승 김
연승 김 el 16 de Mzo. de 2021
Comentada: Star Strider el 16 de Mzo. de 2021
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???

Respuesta aceptada

Star Strider
Star Strider el 16 de Mzo. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre Numbers and Precision en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by