Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

How to create matrices of Symbolic Variables in an earlier version of Symbolic toolbox

Asked by Hari

Hari (view profile)

on 18 Jun 2013

Hi,

Is there any way in which a command with similar functionality as X = sym('x',[2*N,1]); can be worked with an earlier version of Matlab where such commands are not supported..any answer in the right direction will be appreciated.

I currently work on an optimization problem of a throughput model (in commodities). The large number of related variables necessitates me to use symbolic toolbox to create matrices (or arrays) of symbolic vars..Unfortunately, the old version of Matlab is not supporting the command.

thanks,

Hari

0 Comments

Hari

Hari (view profile)

3 Answers

Answer by Alan Weiss

Alan Weiss (view profile)

on 18 Jun 2013

This might not be as slick as the other answers, but it is in the documentation, and is easy to generalize.

Alan Weiss

MATLAB mathematical toolbox documentation

1 Comment

Andrei Bobrov

Andrei Bobrov (view profile)

on 18 Jun 2013

+1

Alan Weiss

Alan Weiss (view profile)

Answer by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 18 Jun 2013
Edited by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 18 Jun 2013
N=10;
evalin('base',['y=sym([x1' sprintf(' ,x%d ',2:N) '])'])

0 Comments

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

Answer by Andrei Bobrov

Andrei Bobrov (view profile)

on 18 Jun 2013
Edited by Andrei Bobrov

Andrei Bobrov (view profile)

on 18 Jun 2013

2D symbolic array with size [7 x 5]:

m = 7; n = 5;
[ii,jj] = ndgrid(1:n,1:m);
v = sprintf('x%d%d,',[ii(:),jj(:)]');
X = reshape(sym(['[',v(1:end-1),']']),m,[]);

ADD after Alan Weiss's answer

m = 7; n = 5;
[ii,jj] = ndgrid(1:m,1:n);
s = arrayfun(@(x,y)sprintf('x%d_%d',x,y),ii,jj,'un',0);
X = sym(s);

0 Comments

Andrei Bobrov

Andrei Bobrov (view profile)

Contact us