Subbing into a constant function in symbolic toolbox
4 views (last 30 days)
Show older comments
All,
This doesn't work.
syms x y
f=3*y^2-2*y^3-3*x^2+6*x*y;
fx=diff(f,x);
fy=diff(f,y);
fxx=diff(f,x,2);
fyy=diff(f,y,2);
fxy=diff(diff(f,x),y);
S=solve(fx,fy);
FXX=subs(fxx,{x,y},{S.x,S.y});
H=fxx*fyy-fxy^2;
subs(H,{x,y},{S.x,S.y});
[S.x,S.y,FXX,H]
Wondering if it is a bug. The subs command in the symbolic toolbox does not produce a vector result when subbing a vector.
>> FXX=subs(fxx,{x,y},{S.x,S.y})
FXX =
-6
This should be a two by one vector with two -6's in it.
Is this a bug?
Workaround?
David.
1 Comment
Answers (1)
Abhishek Gupta
on 6 Dec 2011
It does feel like a bug to me. I came up with a crude workaround/hack:
syms x y
f=3*y^2-2*y^3-3*x^2+6*x*y;
fx=diff(f,x);
fy=diff(f,y);
fxx=diff(f,x,2);
fyy=diff(f,y,2);
fxy=diff(diff(f,x),y);
S=solve(fx,fy);
% Add a variable which you do not expect to be in the calculation before substitution
syms z
FXX=subs(fxx+z,{x,y},{S.x,S.y})
FXX =
z - 6
z - 6
% Substitute zero for the variable to get your original calculation
FXX = subs(FXX,z,0)
FXX =
-6
-6
Hope this helps.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!