# Implicit differentiation to find the slope of the tangent line to the graph at the indicated point [duplicate]

I used ContourPlot to plot the graph of x Sin[Pi y] - y Cos[Pi x] == 1 with the following input:

eqn[x_, y_] := (x Sin[Pi y] - y Cos[Pi x] )== 1
ContourPlot[Evaluate[eqn[x, y]], {x, 0, Pi}, {y, 0, Pi}]


To find $dy/dx$ I used the following code:

yprimeEq = D[eqn[x, y[x]], x];
sol = Solve[yprimeEq, y'[x]] // Simplify;
dydx = y'[x] /. First[sol] /. y[x] -> y;


I am stuck on finding the slope of the tangent line to the graph at $(2/3,2)$. I know I have to just plug in $2/3$ for $x$ and $2$ for $y$ but I don't know how to write it in Mathematica.

exp00= Dt /@ (x Sin[Pi y] - y Cos[Pi x] == 1)

(* -Cos[π x] Dt[y] + π x Cos[π y] Dt[y] + π y Dt[
x] Sin[π x] + Dt[x] Sin[π y]==0 *)


( = $-\text{Cos}[\pi x] \text{Dt}[y]+\pi x \text{Cos}[\pi y] \text{Dt}[y]+\pi y \text{Dt}[x] \text{Sin}[\pi x]+\text{Dt}[x] \text{Sin}[\pi y]==0$)

replace Dt[x] by for example dx, idem for y

 exp01 = exp00 /. {Dt[y] -> dy, Dt[x] -> dx}

(* -dy Cos[π x] + dy π x Cos[π y] + dx π y Sin[π x] +
dx Sin[π y] == 0 *)


( = $-\text{dy} \text{Cos}[\pi x]+\text{dy} \pi x \text{Cos}[\pi y]+\text{dx} \pi y \text{Sin}[\pi x]+\text{dx} \text{Sin}[\pi y]==0$)

The reason for doing this is that if we gives yet numerical values to x and y, Dt[x] and Dt[y] will become null (may be useless here, as we give values at the very end).

Solve dy function of dx :

derivative00=dy/dx /. Solve[exp01 ,{dy}][[1]]

(* (-dx π y Sin[π x] -
dx Sin[π y])/(dx (-Cos[π x] + π x Cos[π y])) *)


( = $\frac{-\text{dx} \pi y \text{Sin}[\pi x]-\text{dx} \text{Sin}[\pi y]}{\text{dx} (-\text{Cos}[\pi x]+\pi x \text{Cos}[\pi y])}$)

Cancel dx which is common to numerator and denominator :

derivative01=Cancel[derivative00]

(* (π y Sin[π x] + Sin[π y])/(Cos[π x] - π x Cos[π y]) *)


( = $\frac{\pi y \text{Sin}[\pi x]+\text{Sin}[\pi y]}{\text{Cos}[\pi x]-\pi x \text{Cos}[\pi y]}$ )

Apply the numeric values :

derivative02=derivative01 /. {x -> 2/3, y -> 2}


resultat : (Sqrt[3] π)/(-(1/2) - (2 π)/3)

( = $\frac{\sqrt{3} \pi }{-\frac{1}{2}-\frac{2 \pi }{3}}$)

verification :

ContourPlot[Evaluate[eqn[x, y]], {x, 0, Pi}, {y, 0, Pi},
Epilog -> {
PointSize[0.03],
Point[{2/3, 2}],
Text[Style["{2/3,2}", FontSize -> 12], {2/3, 2}, {1, 1.5}],
Line[{{2/3 - 1,
2 - (Sqrt[3] π)/(-(1/2) - (2 π)/3)}, {2/3 + 1,
2 + (Sqrt[3] π)/(-(1/2) - (2 π)/3)}}]
}]


• I forgot the application of the slash-dot object. Thanks for answering. – ppkjref Apr 8 '13 at 21:55
• /. is ReplaceAll. Must be used with a rule (->). Exemple : f[a] /. a->b gives f[b] – andre314 Apr 8 '13 at 22:01

Just change the last command to

dydx[x_, y_] = (y'[x] /. First[sol] /. y[x] -> y);

• you can also just substitute the values: dydx/.{x->2/3,y->2}. – Spawn1701D Apr 8 '13 at 21:44
• After looking at the outputs from andre's steps I arrived at this. Thanks – ppkjref Apr 8 '13 at 22:07
• If you want just to find a specific value substituting is enough. If you want to use $\frac{dy}{dx}$ as a function of $x,y$ then defining it as a function is better. – Spawn1701D Apr 8 '13 at 22:33