Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by J. M. Apr 9 '13 at 0:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

Differentiate your equation :

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

 (* -Cos[\[Pi] x] Dt[y] + \[Pi] x Cos[\[Pi] y] Dt[y] + \[Pi] y Dt[
   x] Sin[\[Pi] x] + Dt[x] Sin[\[Pi] 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[\[Pi] x] + dy \[Pi] x Cos[\[Pi] y] + dx \[Pi] y Sin[\[Pi] x] +
   dx Sin[\[Pi] 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 \[Pi] y Sin[\[Pi] x] - 
 dx Sin[\[Pi] y])/(dx (-Cos[\[Pi] x] + \[Pi] x Cos[\[Pi] 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]

(* (\[Pi] y Sin[\[Pi] x] + Sin[\[Pi] y])/(Cos[\[Pi] x] - \[Pi] x Cos[\[Pi] 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] \[Pi])/(-(1/2) - (2 \[Pi])/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] \[Pi])/(-(1/2) - (2 \[Pi])/3)}, {2/3 + 1, 
      2 + (Sqrt[3] \[Pi])/(-(1/2) - (2 \[Pi])/3)}}]
   }]

enter image description here

share|improve this answer
    
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] –  andre Apr 8 '13 at 22:01

Just change the last command to

dydx[x_, y_] = (y'[x] /. First[sol] /. y[x] -> y);
share|improve this answer
    
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.