Problem using subs in syms with matrix
1 回表示 (過去 30 日間)
古いコメントを表示
Saurav Agarwal
2012 年 5 月 14 日
コメント済み: rajasekhar reddy ogirala
2014 年 3 月 3 日
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);
0 件のコメント
採用された回答
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 件のコメント
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
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:
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!