Message Boards Message Boards

0
|
3028 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Avoid issue when differentiating Green's function

Posted 4 years ago

So I'm trying to plot my Green's function derivative using the following code:

n = 3;    
G[x_, xx_] := -1/(2 n) If[x < xx, x^n xx^-n, xx^n x^-n];
DG[x_, xx_] := D[G[x, xx], x];
Plot[DG[x, 0.3], {x, 0, 1}]

While Plot[G] works, trying to plot its derivative gives me some weird errors: enter image description here

What's wrong with my code?

POSTED BY: Omer G
4 Replies
Posted 4 years ago

The problem is caused by using SetDelayed in the definition of DG. The derivative is not evaluated until it is used, and when it is, it is a derivative with respect to a constant x. So, either use Set in the definition of DG or force evaluation prior to use.

Plot[Evaluate@DG[x, 0.3], {x, 0, 1}, Exclusions -> None]

enter image description here

POSTED BY: Rohit Namjoshi

If[] is a programming construct. It is not designed to play well with symbolic mathematics. Use Piecewise instead.

POSTED BY: Gianluca Gorni
Posted 4 years ago

What is n?

POSTED BY: Rohit Namjoshi
Posted 4 years ago

n can be any real number greater than 2, forgot to initialize it.

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

Group Abstract Group Abstract