MATLAB Answers

0

How can I subs 2 symbolic vectors in 1 comand?

Asked by Pedro González López on 16 Feb 2019
Latest activity Answered by 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

Sign in to comment.

2 Answers

Answer by Star Strider
on 16 Feb 2019
 Accepted Answer

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

Sign in to comment.


Answer by madhan ravi
on 16 Feb 2019
Edited by 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

Sign in to comment.