Cannot use "diff" in a function assignment.
- Subject: Cannot use "diff" in a function assignment.
- From: Stavros Macrakis
- Date: Wed, 23 Nov 2011 19:00:13 -0500
Restoring the missing exponents, we have:
---- using expressions ---
m: a3*x^3 + a4 * x^4 + a5 * x^5 + a6 * x^6 + a7 * x^7;
dm: diff(m,x);
F: m/x^2;
ddF: diff(F,x,2);
linsolve( [subst(1,x,m)=1,
subst(1,x,dm)=0,
subst(1,x,ddF)=6,
subst(1/2,x,m)=5/6,
subst(1/2,x,dm)=10/9
],
[ a3, a4, a5, a6, a7 ]
);
(%i2) m:a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3
(%o2) a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3
(%i3) dm:diff(m,x)
(%o3) 7*a7*x^6+6*a6*x^5+5*a5*x^4+4*a4*x^3+3*a3*x^2
(%i4) F:m/x^2
(%o4) (a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3)/x^2
(%i5) ddF:diff(F,x,2)
(%o5) 6*(a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3)/x^4
-4*(7*a7*x^6+6*a6*x^5+5*a5*x^4+4*a4*x^3+3*a3*x^2)/x^3
+(42*a7*x^5+30*a6*x^4+20*a5*x^3+12*a4*x^2+6*a3*x)/x^2
(%i6) linsolve([subst(1,x,m) = 1,subst(1,x,dm) = 0,subst(1,x,ddF) =
6,subst(1/2,x,m) = 5/6,
subst(1/2,x,dm) = 10/9],[a3,a4,a5,a6,a7])
(%o6) [a3 = 502/9,a4 = -1811/9,a5 = 290,a6 = -1732/9,a7 = 440/9]
---- using defined functions ---
m(x) := a3*x^3 + a4 * x^4 + a5 * x^5 + a6 * x^6 + a7 * x^7;
dm(x) := ''( diff(m(x),x) );
F(x) := ''( m(x)/x^2 );
ddF(x):= ''( diff(F(x),x,2) );
linsolve( [m(1)=1,
dm(1)=0,
ddF(1)=6,
m(1/2)=5/6,
dm(1/2)=10/9
],
[ a3, a4, a5, a6, a7 ]
);
(%i7) m(x):=a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3
(%o7) m(x):=a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3
(%i8) dm(x):=7*a7*x^6+6*a6*x^5+5*a5*x^4+4*a4*x^3+3*a3*x^2
(%o8) dm(x):=7*a7*x^6+6*a6*x^5+5*a5*x^4+4*a4*x^3+3*a3*x^2
(%i9) F(x):=(a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3)/x^2
(%o9) F(x):=(a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3)/x^2
(%i10) ddF(x):=6*(a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3)/x^4
-4*(7*a7*x^6+6*a6*x^5+5*a5*x^4+4*a4*x^3+3*a3*x^2)/x^3
+(42*a7*x^5+30*a6*x^4+20*a5*x^3+12*a4*x^2+6*a3*x)/x^2
(%o10) ddF(x):=6*(a7*x^7+a6*x^6+a5*x^5+a4*x^4+a3*x^3)/x^4
-4*(7*a7*x^6+6*a6*x^5+5*a5*x^4+4*a4*x^3+3*a3*x^2)/x^3
+(42*a7*x^5+30*a6*x^4+20*a5*x^3+12*a4*x^2+6*a3*x)/x^2
(%i11) linsolve([m(1) = 1,dm(1) = 0,ddF(1) = 6,m(1/2) = 5/6,dm(1/2) =
10/9],[a3,a4,a5,a6,a7])
(%o11) [a3 = 502/9,a4 = -1811/9,a5 = 290,a6 = -1732/9,a7 = 440/9]
They are completely equivalent at this level. But I still do not recommend
the function-defining style. It works fine for simple interactive examples
like this, but it leads to difficulties and confusion. You get a hint of
that from the above, where %i8 (the *input* line) contains the
differentiated value -- that is the (horrible) way ''(...) works....
-s