# Avoid issue when differentiating Green's function

Posted 1 month ago
403 Views
|
4 Replies
|
4 Total Likes
|
 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: What's wrong with my code? Answer
4 Replies
Sort By:
Posted 1 month ago
 What is n? Answer
Posted 1 month ago
 n can be any real number greater than 2, forgot to initialize it. Answer
Posted 1 month 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]  Answer
Posted 1 month ago
 If[] is a programming construct. It is not designed to play well with symbolic mathematics. Use Piecewise instead. Answer