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