Problem using subs in syms with matrix

1 visualizzazione (ultimi 30 giorni)
syms a b q;
c=q*a+b;
d=c(1);
e=c(2);
f=c(3);
a=[1 2 3]';
b=[4 5 6]';
q=[1 9 0;
2 3 4;
3 5 4];
c=subs(c)
d=subs(d)
e=subs(e)
f=subs(f)
The variable c will be a 3X1 matrix and I wanna extract the individual elements for further operation. Please Help!
I get the error
??? Error using ==> mupadmex Error in MuPAD command: Index exceeds matrix dimensions.
Error in ==> sym.sym>sym.subsref at 1381 B = mupadmex('symobj::subsref',A.s,inds{:});
Error in ==> Untitled2 at 5 e=c(2);

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 14 Mag 2012
b = sym('b',[3 1])
a = sym('a',[3 1])
q = sym('q',[3 3])
a1 = [1 2 3]';
b1 = [4 5 6]';
q1 = [1 9 0;
2 3 4;
3 5 4];
d = c(1)
d = subs(d,[a(:);b(:);q(:)],[a1(:);b1(:);q1(:)])
  2 Commenti
rajasekhar reddy ogirala
rajasekhar reddy ogirala il 3 Mar 2014
error msg to below program in image is
Error in sym/subsref
B = mupadmex('symobj::subsref',A.s,inds{:});
in line 41
gp = eval(f(z)/(f(z)-f(y)));

Accedi per commentare.

Più risposte (1)

Alexander
Alexander il 14 Mag 2012
The error raises in these lines:
d=c(1);
e=c(2);
f=c(3);
The variable c is a (1x1) sym and MATLAB cannot access the 2nd or 3rd element. From the code I guess, you want to substitute q by some values? If I'm wrong, please let me know what you want to achieve by c(1), c(2), and c(3). Following I assume you want to substitute q:
If you have R2012a you can use symfuns for that:
syms a b q c(q);
c(q)=q*a+b;
d=c(1);
e=c(2);
f=c(3);
a=[1 2 3]';
b=[4 5 6]';
q=[1 9 0;
2 3 4;
3 5 4];
d=subs(d)
e=subs(e)
f=subs(f)
If you have an older version, you have to substitute q:
syms a b q;
c=q*a+b;
d=subs(c, q, 1);
e=subs(c, q, 2);
f=subs(c, q, 3);
a=[1 2 3]';
b=[4 5 6]';
q=[1 9 0;
2 3 4;
3 5 4];
d=subs(d)
e=subs(e)
f=subs(f)
  2 Commenti
Saurav Agarwal
Saurav Agarwal il 14 Mag 2012
Thanks for the reply.
I guess my question wasn't clear enough.
q is a 3x3 matrix and a & b are 3X1 matrix.
so my c should be a 3X1 matrix
i wanna store the three elements of c in d, e and f so that i can carry out further calculations in syms representation itself.
the substitution is at the end of code.
I hope i am clearer this time.
syms a b q;
c=q*a+b;
d=c(1);
e=c(2);
f=c(3);
%..... operations on d e and f
%...
%...
a=[1 2 3]';
b=[4 5 6]';
q=[1 9 0;
2 3 4;
3 5 4];
c=subs(c)
d=subs(d)
e=subs(e)
f=subs(f)
Saurav Agarwal
Saurav Agarwal il 14 Mag 2012
Is there a problem with the declaration of variables a b and q. ?
Please Help!

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by