0

I have defined the following expression: r:sqrt((y1-x1)^2+(y2-x2)^2); When I differentiate r with respect to y1, i.e. diff(r,y1); I get the answer as (y1-x1)/sqrt((y1-x1)^2+(y2-x2)^2); The answer is technically correct but I would like the answer to be of the form (y1-x1)/r. I have tried using "subst" but I am not getting the desired answer. Here is the code

kill(all);
r:sqrt((y1-x1)^2+(y2-x2)^2);
t1:diff(r,y1);

Can someone please guide me in how to get the desired answer. Thank you

  • Try `subst (r = 'r, t1)`. Note that in general it's not always possible to get results to a form that is close to what one would do by hand. – Robert Dodier May 13 '22 at 17:00
  • Thank you for your suggestion. I did try it. t2:subst(r='r,t1); But when I differentiate t2 with respect to y1, i.e. diff(t2,y1), I get the answer as 1/r and not the expected answer. I also tried the following: t3:diff(t1,y1) and then subst(r='r,t3). But that too does not help as the denominator of the second term is not expressed in terms of r. – Salil S. Kulkarni May 14 '22 at 01:46
  • This is because when you now have the expression (y1-x1)/r. When you differentiate it, maxima doesn't know that r depends on x1 and y1. I tried "depends(['r],[x1,y1])". Then diff(t2,y1) gives something closer, but you have diff(r,y1) because maxima doesn't know what the actual relationship is. So, subst('r=r,t2) expands things out, and ev(%,diff) causes the derivatives to be taken. I don't know how to put r back into those equations. – Raymond Toy Jul 02 '22 at 16:43

0 Answers0