Problem using subs in syms with matrix
3 次查看(过去 30 天)
显示 更早的评论
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!