# Subbing into a constant function in symbolic toolbox

2 vues (au cours des 30 derniers jours)
David Arnold le 14 Nov 2011
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 commentaireAfficher AucuneMasquer Aucune
bym le 15 Nov 2011
why do you think it is a bug? fxx = -6; there is nothing to substitute into?!?

Connectez-vous pour commenter.

### Réponses (1)

Abhishek Gupta le 6 Déc 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 commentairesAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Code Performance dans Help Center et File Exchange

### Community Treasure Hunt

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

Start Hunting!