How can I subs 2 symbolic vectors in 1 comand?
1 view (last 30 days)
Show older comments
Pedro González López
on 16 Feb 2019
Answered: Star Strider
on 16 Feb 2019
HI!
I have this code:
syms a b c d
X=[a,b]; Y=[c,d];
Z=[X;Y];
X0=[1,2]; Y0=[3,4];
Can I subs "X0" and "Y0" in "Z" without linking "X" and "Y"?
I mean something like (warning, totally invented) subs(Z,{X Y},{X0,Y0})
thanks ^^
0 Comments
Accepted Answer
Star Strider
on 16 Feb 2019
You defined ‘Z’ to require 4 different arguments, so the substitution has to match them, either using subs or using ‘Z’ as a function:
syms a b c d
X=[a,b]; Y=[c,d];
Z=[X;Y];
X0=[1,2]; Y0=[3,4];
Zs = subs(Z,{a,b,c,d},{X0(1),X0(2),Y0(1),Y0(2)})
syms a b c d
X=[a,b]; Y=[c,d];
Z(X,Y)=[X;Y];
X0=[1,2]; Y0=[3,4];
Zs = Z(X0(1),X0(2),Y0(1),Y0(2))
However if you defined ‘Z’ differently, these would work:
syms a b c d
X=a; Y=c;
Z=[X;Y];
X0=[1,2]; Y0=[3,4];
Zs = subs(Z,{X,Y},{X0,Y0})
syms a b c d
X=a; Y=c;
Z(X,Y)=[X;Y];
X0=[1,2]; Y0=[3,4];
Zs = Z(X0,Y0)
0 Comments
More Answers (1)
madhan ravi
on 16 Feb 2019
Edited: madhan ravi
on 16 Feb 2019
Edit: Corrected the mistake.
A workaround:
Z=matlabFunction([X,Y]); % change this line
XY=num2cell([X0,Y0]);
Z(XY{:}) % evaluate all in one go subs() alternative
0 Comments
See Also
Categories
Find more on Assumptions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!