フィルターのクリア

Problem using subs in syms with matrix

1 回表示 (過去 30 日間)
Saurav Agarwal
Saurav Agarwal 2012 年 5 月 14 日
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);

採用された回答

Andrei Bobrov
Andrei Bobrov 2012 年 5 月 14 日
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 件のコメント
Saurav Agarwal
Saurav Agarwal 2012 年 5 月 14 日
Thank you
rajasekhar reddy ogirala
rajasekhar reddy ogirala 2014 年 3 月 3 日
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)));

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

その他の回答 (1 件)

Alexander
Alexander 2012 年 5 月 14 日
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 件のコメント
Saurav Agarwal
Saurav Agarwal 2012 年 5 月 14 日
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 2012 年 5 月 14 日
Is there a problem with the declaration of variables a b and q. ?
Please Help!

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by