Subbing into a constant function in symbolic toolbox

조회 수: 4 (최근 30일)
David Arnold
David Arnold 2011년 11월 14일
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
bym
bym 2011년 11월 15일
why do you think it is a bug? fxx = -6; there is nothing to substitute into?!?

댓글을 달려면 로그인하십시오.

답변 (1개)

Abhishek Gupta
Abhishek Gupta 2011년 12월 6일
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.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by