diff: variable must not be a number; found: | bug??



   Date: Mon, 18 Nov 2013 10:20:50 -0500
   From: Evan Cooch <evan.cooch at gmail.com>
   CC: <maxima at math.utexas.edu>

   On 11/18/2013 9:57 AM, Leo Butler wrote:
   >   
   >     Maxima returns the following error:
   >
   >     diff: variable must not be a number; found: 8
   >
   > Maxima/diff is telling you that when it subst's f1=8 into lls_f1, it
   > finds diff(blah,8), which is non-sensical.
   >
   > You want something like
   >
   > at(lls_f1,[f1=8]);
   >
   >
   >   

   Thanks!

   But why, then, does the following work? And every other bit I've code 
   I've used for a couple of years built on the same approach.

Let me suggest an alternative approach that has the virtue of being
more self-explanatory: create a function to do implicit differentiation.
(There is a package, but it seems overkill...).

(%i1)
kill(all)$
implicitdiff(f,y,x) := block([c],
  c:map(lambda([t],del(t)=0),delete(y,delete(x,listofvars(f)))),
  subst([del(x)=1,del(y)=nounify(diff)(y,x)],subst(c,first(solve(diff(f),del(y))))))$

(%i2)
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])$

(%i3)
cp_base : charpoly(base,%lambda);


(%o3) -%lambda^3*(s_3-%lambda)^2-%lambda*m_3*(1-sigma_1)*(1-sigma_2)*s_0*s_1
                                        *s_2*(s_3-%lambda)
(%i4)
implicitdiff(cp_base,%lambda,sigma_1);
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],rhs(%));

(%o4) 'diff(%lambda,sigma_1,1) = -((%lambda*m_3*sigma_2-%lambda*m_3)
                               *s_0*s_1*s_2*s_3
                               +(%lambda^2*m_3-%lambda^2*m_3*sigma_2)
                                *s_0*s_1*s_2)
                               /(3*%lambda^2*s_3^2
                                +(((m_3*sigma_1-m_3)*sigma_2-m_3*sigma_1+m_3)
                                 *s_0*s_1*s_2
                                 -8*%lambda^3)
                                 *s_3
                                +((2*%lambda*m_3-2*%lambda*m_3*sigma_1)
                                 *sigma_2
                                 +2*%lambda*m_3*sigma_1-2*%lambda*m_3)
                                 *s_0*s_1*s_2+5*%lambda^4)
(%i5)
(%o5) -.1350578819494058

Note that I subst into the rhs of the result of implicitdiff only.

Leo