How can I subs 2 symbolic vectors in 1 comand?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Pedro González López
am 16 Feb. 2019
Beantwortet: Star Strider
am 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 Kommentare
Akzeptierte Antwort
Star Strider
am 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 Kommentare
Weitere Antworten (1)
madhan ravi
am 16 Feb. 2019
Bearbeitet: madhan ravi
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Assumptions finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!