How can I subs 2 symbolic vectors in 1 comand?

1 次查看(过去 30 天)
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 ^^

采纳的回答

Star Strider
Star Strider 2019-2-16
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)

更多回答(1 个)

madhan ravi
madhan ravi 2019-2-16
编辑:madhan ravi 2019-2-16
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

类别

Help CenterFile Exchange 中查找有关 Assumptions 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by