On Tue, Jan 08, 2008 at 09:48:09AM -0600, maxima-request at math.utexas.edu wrote:
>
> Message: 8
> Date: Tue, 8 Jan 2008 16:48:05 +0100
> From: Bart Vandewoestyne <Bart.Vandewoestyne at telenet.be>
> Subject: Re: [Maxima] defining functions of s variables
> To: Barton Willis <willisb at unk.edu>
> Cc: maxima at math.utexas.edu
> Message-ID: <20080108154805.GA19365 at simba>
> Content-Type: text/plain; charset=us-ascii
>
> On Tue, Jan 08, 2008 at 09:25:40AM -0600, Barton Willis wrote:
> > Welcome to Maxima. Here is a function that sums its arguments
> >
> > [... snip explanation ...]
>
> Barton,
>
> Thanks for the explanation. In the meanwhile, I had also found
> that I can indeed do something like:
>
>
> (%i1) f([x]) := product(x[i]^i, i, 1, length(x));
> i
> (%o1) f([x]) := product(x , i, 1, length(x))
> i
> (%i2) f(1, 2, 3);
> (%o2) 108
>
>
> But now I want to go one step further and be able to calculate partial
> derivatives for an arbitrary s-dimensional function (as it is defined by
> the user in his command for defining f([x])). And this is where I'm stuck.
>
> Take the dimension of x to be three, then the function as I define it
> above is:
>
> f(x) = x[1]^1 * x[2]^2 * x[3]^3
>
> and then i want to be able to calculate for example the first partial
> derivative to x[1], being:
>
> x[2]^2 * x[3]^3
>
> However, if I try
>
> (%i3) diff(f(x), x[1], 1);
> (%o3) 0
> (%i4) diff(f([x]), x[1], 1);
> (%o4) [0]
>
> These results are not what I expect them to be...
> I want to be able to do this for whatever partial derivative I need and
> for whatever function I a user defines, so not only for the above example
> as I have given it.
>
> Any help welcome!
> Bart
OK. I think I am making progress in struggling with the syntax
:-)
I think I can do what I need as follows:
First, I can define my function for general dimensions as
follows:
f([x]) := product(x[i]^i, i, 1, length(x))$
Then, to compute the partial derivatives I need, i can use the makelist
function to do something like this:
diff(apply(f, makelist(x[k], k, 1, s)), x[1], 1, x[2], 1);
This seems to do quite what I need. If people have any comments on the
way I am doing this or if anybody has some improvements, then I would be
glad to hear.
Regards,
Bart
--
"Share what you know. Learn what you don't."