Help using symolic variable

2 views (last 30 days)
Alok
Alok on 20 Oct 2011
I am trying to implement a piece of code:
n = 1000;
syms l;
m = sym('m', [ 1 n ] );
x = sym( 0 );
for i =1:1:n
J_j(1,i) = [ (1/3)*m(1,i)*l*l x x -(1/2)*m(1,i)*l;
x x x x;
x x x x;
-(1/2)*m(1,i)*l x x m(1,i) ];
end
Now, when I try to implement this code, it gives me following error:
??? Error using ==> mupadmex
Error in MuPAD command: Invalid index [list];
during evaluation of 'matchNonSingletonLHS'
Error in ==> sym.sym>sym.subsasgn at 1435
C = mupadmex('symobj::subsasgn',A.s,B.s,inds{:});
can anyone help?
Thank you so much in advance.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Oct 2011
When you use [] in that J_j assignment statement, you are constructing a 4x4 MATLAB array of symbolic values. A 4x4 MATLAB array cannot fit in to a single array element J_j(1,i) .
A symbolic array can be a single "object" that happens to store 4x4 in it, but such arrays have to be constructed at the MuPad level, or by using sym() with array notation and then subs() in to elements of the resulting symbolic array.

More Answers (1)

Alok
Alok on 20 Oct 2011
Hi folks,
I got the code running after some modifications but I have a new problem, first I will write code:
J_j = sym( 'J_j', [ 1 n ] );
this was the modification, now my code is rnning just fine but there is problem in output, I want J_j(1,i) to be a 4*4 matrix, but actually what is happening is it is 1*1 matrix and only the first element of the definition provide in the question itself, can anyone help me.....
Very urgent!!!
Thank you

Community Treasure Hunt

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

Start Hunting!