You might do something like the following: Define a procedure expandDiff by
expandDiff := proc(expr,var)
local a,b;
if type(expr,`+`) then map(expandDiff,expr,var)
elif type(expr,`*`) then
a := op(1,expr);
b := `*`(op([2..-1],expr));
expandDiff(a,var)*b + expand(a*expandDiff(b,var))
elif type(expr,`^`) then
a := op(1,expr);
b := op(2,expr);
expr*(expandDiff(b,var)*ln(a) + b/a*expandDiff(a,var))
else Diff(expr,var)
end if
end proc:
where for completeness functionality corresponding to the type `^` has been included. Then, try the following examples:
Using the differential operator 'D' (may be using convert(expr,D) first)
it is simply D(u*v).
Explanation: Maple seems to 'understand' how basic operations have to be
applied to functions.
t:='t':
someConstants:=[0,1,2,evalf(Pi), Pi];
for b in someConstants do
p:=b;
print('p'=p, 'p(t)'=p(t));
end do:
p = 0, p(t) = 0
p = 1, p(t) = 1
p = 2, p(t) = 2
p = 3.141592654, p(t) = 3.141592654
p = Pi, p(t) = Pi(t)
So if the constant is not a symbol like Pi an assignment like p:=2 is
understood as a function taking that constant as value. And no, it would
not work for the Natural for example:
assume(n::integer): getassumptions(n);
p:=n;
p(t);
p := n
n(t)
The identity one has to define extra by (id: x -> x works very reliable):
id:=unapply(x,x);
id := x -> x
'id( t )': '%'=%;
'id( exp(sin(tau)) )': '%'=%;
id(t) = t
id(exp(sin(tau))) = exp(sin(tau))
This also works (formally) for the basic arithmetic operators:
ArithmeticOperators:=[`+`, `-`, `*`, `/`, `^`];
for b in ArithmeticOperators do
p:=b(u,v);
print('p'=p, 'p(t)'=p(t));
end do:
p = u + v, p(t) = u(t) + v(t)
p = u - v, p(t) = u(t) - v(t)
p = u v, p(t) = u(t) v(t)
u(t)
p = u/v, p(t) = ----
v(t)
v v(t)
p = u , p(t) = u(t)
Thus u*v is understood as the function t -> u(t)*v(t) and since Maple
expand automatically (otherwise: enforce it) one can simply write:
D(u*v);
%(t);
convert(%,Diff);
D(u) v + u D(v)
D(u)(t) v(t) + u(t) D(v)(t)
/d \ /d \
|-- u(t)| v(t) + u(t) |-- v(t)|
\dt / \dt /
The last command is onlyto show it in more common notation.
I did not know about Rule, because I have never really used the Student package. Maybe I should study the package in some detail. Anyway, I could not resist generalizing your idea to an n-ary product version:
Expanding Diff
You might do something like the following: Define a procedure
expandDiffbywhere for completeness functionality corresponding to the type
`^`has been included. Then, try the following examples:view it as operation on functions
Using the differential operator 'D' (may be using convert(expr,D) first) it is simply D(u*v). Explanation: Maple seems to 'understand' how basic operations have to be applied to functions. t:='t': someConstants:=[0,1,2,evalf(Pi), Pi]; for b in someConstants do p:=b; print('p'=p, 'p(t)'=p(t)); end do: p = 0, p(t) = 0 p = 1, p(t) = 1 p = 2, p(t) = 2 p = 3.141592654, p(t) = 3.141592654 p = Pi, p(t) = Pi(t) So if the constant is not a symbol like Pi an assignment like p:=2 is understood as a function taking that constant as value. And no, it would not work for the Natural for example: assume(n::integer): getassumptions(n); p:=n; p(t); p := n n(t) The identity one has to define extra by (id: x -> x works very reliable): id:=unapply(x,x); id := x -> x 'id( t )': '%'=%; 'id( exp(sin(tau)) )': '%'=%; id(t) = t id(exp(sin(tau))) = exp(sin(tau)) This also works (formally) for the basic arithmetic operators: ArithmeticOperators:=[`+`, `-`, `*`, `/`, `^`]; for b in ArithmeticOperators do p:=b(u,v); print('p'=p, 'p(t)'=p(t)); end do: p = u + v, p(t) = u(t) + v(t) p = u - v, p(t) = u(t) - v(t) p = u v, p(t) = u(t) v(t) u(t) p = u/v, p(t) = ---- v(t) v v(t) p = u , p(t) = u(t) Thus u*v is understood as the function t -> u(t)*v(t) and since Maple expand automatically (otherwise: enforce it) one can simply write: D(u*v); %(t); convert(%,Diff); D(u) v + u D(v) D(u)(t) v(t) + u(t) D(v)(t) /d \ /d \ |-- u(t)| v(t) + u(t) |-- v(t)| \dt / \dt / The last command is onlyto show it in more common notation.simpler approach
I'm not sure your true intent. Expressing u and v as functions of t works:
You could use aliases to make this easier to type and makes the output look like what you want:
Calculus1
Student package
I did not know about
Rule, because I have never really used the Student package. Maybe I should study the package in some detail. Anyway, I could not resist generalizing your idea to an n-ary product version: