Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.3K Views
|
1 Reply
|
2 Total Likes
View groups...
Share
Share this post:

"D" Command generates general error in notebook

Posted 5 years ago

Hi;

I really like using the "D" Command because of its format and ease of use, however the command seems to cause me calculation problems - See Attached.

I defined the function f[x,y] and used the function to generate derivatives for both x & y. I then copy and pasted the results into a newly defined function g[x,y] and subsequently calculated the value of g[1,1]

Next I created another function h[x,y] using the same "D" commands that generated the solutions that I copy and pasted into the prior "g" function. The new h[x,y] function give the same results as the prior g[x,y] function however when I use the value of h[1,1], I get a "general" error message stating the "1 is not a valid value".

To further test, I created another function j[x,y] using the Derivative command which does not give an error message and give the expected results.

I use the "D" command a lot and most of the time it seems to give the desired results, and actually prefer it over the Derivative command because the "D" command is faster to use and I like its format better. Currently, I am trying to figure out when I should use the "D" command and when I should use the Derivative command, or whether I should use the "D" command at all.

Please review the attached and let me know if there is a problem in the "D" command code or in the way I am using the command.

Thanks,

Mitch Sandlin

POSTED BY: Mitchell Sandlin

You can use the D operator and avoid the problem by defining your function with immediate evaluation:

Clear[x, y];
f[x_, y_] = D[x^2 y, x];
f[1, 1]

With delayed evaluation you get the error, because the numerical values 1 are replaced into the formula before the derivative is calculated.

A similar problem happens with traditional Leibniz dy/dx notation: if you need the derivative d(log(x))/dx at x=1, you first calculate the derivative with symbolic x, and then replace x=1, not the other way round.

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard