Forum archive 2000-2006

Michal Charemza - Differentiation

Michal Charemza - Differentiation

by Arnold Pizer -
Number of replies: 0
inactiveTopicDifferentiation topic started 9/1/2006; 11:15:21 AM
last post 9/1/2006; 5:23:24 PM
userMichal Charemza - Differentiation  blueArrow
9/1/2006; 11:15:21 AM (reads: 294, responses: 3)
Hi,

I am trying to differentiate a formula in a Vector context, I can differentiate it fine with respect to x or z, but if I try to differentiate it fine with respect to y, I get an error.

The code is:

$context = Context("Vector"); $f = Formula("x^2 + y^2 + z^2"); $pfbypx = $f->D(x); $pfbypy = $f->D(y); $pfbypz = $f->D(z);

And the error is:

Invalid range "f->" in transliteration operator at line 43 of (eval 1044)

If I comment out the line where I differentiate with respect to

I'm not sure if I am doing something wrong. How can I differentiate with respect to y?

Michal.

<| Post or View Comments |>


userMichal Charemza - Re: Differentiation  blueArrow
9/1/2006; 11:16:34 AM (reads: 354, responses: 0)
Oops:

If I comment out the line where I differentiate with respect to y, then the the differentials with respect to x and z work fine.

<| Post or View Comments |>


userDavide P. Cervone - Re: Differentiation  blueArrow
9/1/2006; 3:40:00 PM (reads: 358, responses: 0)
The problem is that you have not put quotes around your x, y and z. In the case of x and z, perl interprets these are string literals, since it has no other meaning for x and z, but y is used as the transliteration operator, and perl attempts to interpret it as that. Your syntax is not correct for that, so it complains. This has nothing to do with the differentiation, but rather with the perl code itself. You want
   $pfbypx = $f->D('x');
$pfbypy = $f->D('y');
$pfbypz = $f->D('z');
instead. While perl will allow you to use string literals without quotes, it is very bad practice, in my opinion, as it leads to just this type of error.

Davide

<| Post or View Comments |>


userMichal Charemza - Re: Differentiation  blueArrow
9/1/2006; 5:23:24 PM (reads: 357, responses: 0)
Thanks - this works now,

Michal.

<| Post or View Comments |>