kill(all)$

The unit vector to f(x),draw unit vector to f(x), version 1.0 
peter.vlasschaert@gmail.com,31/01/2019.

load packages
============

load(lrats)$

rem :only use simple graphics ( not draw )

point where to draw tangent
========================

load(lrats)$

p1:x1=3;

p1a:y1=3;

given function: f(x),f'(x)
=============

f(x)
----

f(x):=x^2;

f ' (x)
-------

example: same function , x^2+constant

p2:diff(f(x),x);

@ value : x1, differentation
=======================

p2a:subst([x=rhs(p1)],p2);

tangent line
==========

line :  y = a*x+b⋂
===

p3: y-rhs(p1a) =p2a*(x-rhs(p1));

p3a:solve(p3,y)[1];

p4:a=coeff(rhs(p3a),x,1);

p4a:b=coeff(rhs(p3a),x,0);

select point : xa > x1
=================

p5:xa=rhs(p1)+.6;

find : ya (use p3a)
===============

p5a:ya=subst([x=rhs(p5)],rhs(p3a));

unit vector
=========

1e)  vector coordinates
====================

p6:[xa=rhs(p5),x1=rhs(p1),ya=rhs(p5a),y1=rhs(p1a)];

2e)  unit vector
====================

p6a:dist = subst(p6,sqrt((xa-x1)^2+(ya-y1)^2));

x- direction
-----------------

p6b:subst(p6,( xa-x1)/rhs(p6a));

y- direction
-----------------

p6c:subst(p6,( ya-y1)/rhs(p6a));

check : unit vector
================

(p6b)^2+(p6c)^2;

begin point : unit vector ('see above')
===============================

p7: p1;

p7a:p1a;

end point     : unit vector
=====================

x value : end point
================

p8 : xe=rhs(p1)+p6b;

y value : end point
================

p8a:subst([x=rhs(p1)+p6b,y=ye],p3a);

p9:[[rhs(p1),rhs(p1a)],[rhs(p8),rhs(p8a)]];

same_xy
========

wxplot2d([f(x),rhs(p3a),2*x], [x,0,4],[y,-2,10],same_xy)$

not same_xy
===========

wxplot2d([f(x),rhs(p3a),2*x], [x,-1,3.5],[y,-2,20])$

draw line : between two points
==========================

first point x,y
========

p9a:rhs(p1);

p9b:rhs(p1a);

second point x,y
===========

p9c:rhs(p8);

p9d:rhs(p8a);

rico
===

m:(p9d-p9b)/(p9c-p9a);

linear equation
=============

y-3=m*(x-3);

p10:solve(%,y)[1];

translation : y1=3: horizontal shift
============================

p11:lhs(p10) = rhs(p10)+rhs(p1a);

wxplot2d([f(x),rhs(p3a),rhs(p11),2*x], [x,-1,3.5],[y,-2,10])$

translation : x1=3: vertical shift x => x-3
=================================

p12: subst([x=x-3],p10);

wxplot2d([f(x),rhs(p3a),rhs(p11),2*x,rhs(p12)], [x,-1,3.5],[y,-2,10])$

to a point (x1,y1) with same  slope
==============
y = m*(x-x1)+y1

p13:y=m*(x-rhs(p1))+rhs(p1a);

p13a:expand(p13);

	      wxplot2d([f(x),rhs(p3a),rhs(p11),2*x,rhs(p13)], [x,-1,3.5],[y,-2,10])$ 

wxplot2d([[discrete,p9],x^2],[x,0,10],[y,0,15],same_xy);

first point : on the curve.
====================

p14a:xa1= rhs(p1);

p14b:ya1=f(rhs(p14a));

second point : direction of tangent.
==============================

p15a:xa2 = rhs(p1)+p6b;

p15b:ya2 = rhs(p14b)+p6c;

p16:[xa1=rhs(p14a),ya1=rhs(p14b),xa2=rhs(p15a),ya2=rhs(p15b)];

p16a:rhs(p16[1]);
p16b:rhs(p16[2]);
p16c:rhs(p16[3]);
p16d:rhs(p16[4]);

p17:[[p16a,p16b],[p16c,p16d]];

wxplot2d([[discrete,p17],x^2],[x,2.95,3.2],[y,0,15]);

wxplot2d([[discrete,p17],x^2],[x,0,6],[y,0,15]
, [style, points, lines], [color, red, blue]
);

wxplot2d([[discrete,p17],x^2],[x,2.95,3.2],[y,0,15]
, [style, points, lines], [color, red, blue],
[point_type, asterisk],[title,"f(x) ,unit vector"],
        [legend, "unit vec", "f(x)"],
        [xlabel, "x values"],
        [ylabel, "y values"])$

unit vector  to  f(x)
===============

'------------------------------------------------------------------------------------------------------'

lowest   point ,red diamond (3,9)
highest point ,red diamond (3.164398987305357,9.986393923832145)

'------------------------------------------------------------------------------------------------------'