diff: variable must not be a number; found: | bug??
Subject: diff: variable must not be a number; found: | bug??
From: Evan Cooch
Date: Mon, 18 Nov 2013 09:37:05 -0500
Using 5.31.2 under Win 7. Am having major problems trying to figure out
why diff is choking on something. Here is a MWE:
base :
matrix([f1*gam,f2*gam,f3*gam,0,0],[0,0,0,S*eps1,0],[0,0,0,0,S*eps2],[f1*(1-gam),f2*(1-gam),f3*(1-gam),0,0],[0,0,0,S*(1-eps1),S*(1-eps2)]);
cp_base : charpoly(base,lambda);
Then, I want to implicitly differentiate the characteristic polynomial
for f1 wrt to lambda. To do this, I use
depends(lambda,f1);
deriv : diff(cp_base,f1);
lls_f1: solve(deriv,'diff(lambda,f1));
So far, everything works as it should -- the implicit derivative is
exactly what is yielded by other CAS (e.g., Maple).
The problem is when I try to subst in values for the different
parameters (e.g., gam, or f1...). I want to numerically evaluate the
derivative. When I try
lls_f1 :
subst([f3=18,f2=12,f1=8,gam=0.0725,S=0.4,eps1=0.1,eps2=0.02,lambda=1.065],
lls_f1);
Maxima returns the following error:
diff: variable must not be a number; found: 8
This problem only occurs for f1 -- no other variable. If I leave f1 out
of the list of variables
lls_f1 : subst([f3=18,f2=12,gam=0.0725,S=0.4,eps1=0.1,eps2=0.02],lls_f1);
no errors (although the result still contains f1). And, it doesn't
matter which order I enter the parameters.
Whats more puzzling is that the following works perfectly:
base :
matrix([0,0,m_3*s_0,0,0],[(1-sigma_1)*s_1,0,0,0,0],[0,(1-sigma_2)*s_2,s_3,0,0],[sigma_1*s_1,0,0,0,0],[0,sigma_2*s_2,0,s_2,s_3]);
cp_base : charpoly(base,lambda);
depends(lambda,sigma_1);
deriv : diff(cp_base,sigma_1);
lls_sig1 : solve(deriv,'diff(lambda,sigma_1));
lls_sigma1 :
subst([s_0=0.35,s_1=0.60,s_2=0.80,s_3=0.90,m_3=1.25,lambda=1.08,sigma_1=0,sigma_2=0],lls_sigma1);
So, the basic syntax and sequence of steps is identical.
So, if in the original code I use m1, m2 and m3 instead of f1, f2 and
f3, everything works:
base :
matrix([m1*gam,m2*gam,m3*gam,0,0],[0,0,0,S*eps1,0],[0,0,0,0,S*eps2],[m1*(1-gam),m2*(1-gam),m3*(1-gam),0,0],[0,0,0,S*(1-eps1),S*(1-eps2)]);
cp_base : charpoly(base,lambda);
depends(lambda,m1);
deriv : diff(cp_base,m1);
lls_m1: solve(deriv,'diff(lambda,m1));
lls_m1 :
subst([m3=18,m2=12,m1=8,gam=0.0725,S=0.4,eps1=0.1,eps2=0.02,lambda=1.065],
lls_m1);
So, is the letter 'f' protected in some way, so that you can't use it
as a variable (either by itself, or in combination with something else)?
If so, then that is a *major* pain in the <insert sensitive body part
here>. Heck, even using 'f' in a word
(fecundity1,fecundity2,fecundity3...) blows up.
Insights? Suggestions?
Thanks in advance...