Equation of Tangent
11-02-2021, 05:46 PM
Post: #1
 vjc Junior Member Posts: 10 Joined: Oct 2020
Equation of Tangent
Hi all,
The HP prime does not show the equation of a tangent. It just draws a tangent.
I tried writing a program where I can put in an equation and specify the X value where the tangent is supposed to be, but am coming up with wrong answer. I am not very conversant with programming, Can anyone look into it and correct the program. Thanks.

TANGENT EXPORT ()
BEGIN
LOCAL f, B;
PRINT;
INPUT (f, "Function:", "f (X) =", "Enter the algebraic expression");
f ▶ F1;
INPUT (A, "Study of the tangent at x =?", " X =");
PRINT ("f (X) =" + F1);
PRINT ("Equation of the tangent at " + A + " :");
PRINT ("Y =" + SLOPE (F1, A) + "(X -" + A + ") +" + F1 (A));
−SLOPE (F1, A) * A + F1 (A) ▶ B;
PRINT ("that is: Y =" + SLOPE (F1, A) + "X +" + B);
END;
11-03-2021, 03:13 PM
Post: #2
 roadrunner Senior Member Posts: 418 Joined: Jun 2015
RE: Equation of Tangent
Your first input statement looks wrong. Try changing this:

INPUT (f, "Function:", "f (X) =", "Enter the algebraic expression");

to this:

INPUT ({{f,[2],40}}, "Function:", "f (X) =", "Enter the algebraic expression");

11-04-2021, 02:52 AM
Post: #3
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
Thanks a lot roadrunner. Works flawlessly now. I had spent so much time on it but with my limited knowledge could not figure it out. Thanks a ton.

The answer that I am getting shows the -ve B as:
and if I modify "X +" in the last line of program to just "X " I get the - values correctly but if there is a positive value of B there is no + sign (I get 3x4 instead of 3x+4).

I can live with y=3x+-4 as I do get the answer but is there a way where I could either + or - sign before B as appropriate.

And many thanks once again roadrunner.
11-04-2021, 12:35 PM
Post: #4
 roadrunner Senior Member Posts: 418 Joined: Jun 2015
RE: Equation of Tangent
Changing this line:

PRINT ("that is: Y =" + SLOPE (F1, A) + "X +" + B);

to this:

PRINT ("that is: Y =" + SLOPE (F1, A) + IFTE(B<0,"X -","X +") + ABS(B));

should do what you want.

11-05-2021, 01:05 AM
Post: #5
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
You nailed it Roadrunner. Thanks a lot once again.
You solved my problem.
Much grateful.
11-09-2021, 06:33 AM
Post: #6
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
The working program, if needed by anyone else, is as follows:
(Credit goes to roadrunner to correct my shoddy programming)

BEGIN
LOCAL f, B;
PRINT;
INPUT ({{f,[2],40}}, "Function:", "f (X) =", "Enter the algebraic expression");
f ▶ F1;
INPUT (A, "Study of the tangent at x =?", " X =");
PRINT ("f (X) =" + F1);
PRINT ("Equation of the tangent at " + A + " :");
PRINT ("Y =" + SLOPE (F1, A) + "(X -" + A + ") +" + F1 (A));
−SLOPE (F1, A) * A + F1 (A) ▶ B;
PRINT ("that is: Y =" + SLOPE (F1, A) + IFTE(B<0,"X -","X +") + ABS(B));
END;

There is scope for improvement here but is beyond my limited programming skills.
I would love if instead of typing in the algebraic expression at the very first input, we would just type, say 1, and it would pick up the expression F1(X) from function symbolic view, and similarly pressing 2 would pick up the expression F2(X) from function symbolic view and so on. This will save the effort of retyping or copy-pasting the entire expression. Any ideas anyone??
11-12-2021, 10:07 PM
Post: #7
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
11-18-2021, 11:51 PM
Post: #8
 roadrunner Senior Member Posts: 418 Joined: Jun 2015
RE: Equation of Tangent
It turns out that the SLOPE function doesn't seem to work with expressions stored in variables so I had to make some changes to calculate the slope the old fashion way: by taking the first derivative.

Here's what i came up with:

PHP Code:
EXPORT TANGENT()BEGINLOCAL f, B, fn, ff, sf;PRINT;INPUT (fn, "Function:", "f (X) =", "Enter the algebraic expression");EXPR("F"+fn)▶f;INPUT (A, "Study of the tangent at x =?", " X =");PRINT ("f (X) =" + f);PRINT ("Equation of the tangent at " + A + " :");EVAL(subst(diff(f,'X',1),'X=A'))▶sf;EVAL(subst(f,'X=A'))▶ff;PRINT ("Y =" + sf + "(X -" + A + ") +" + ff);−sf * A + ff ▶ B;PRINT ("that is: Y =" + sf + IFTE(B<0,"X -","X +") + ABS(B));END;

On the first input statement enter an integer, n (0 to 9) and it will use function Fn from the symbolic view of the function app.

11-29-2021, 07:42 AM
Post: #9
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
The new program does take the expression stored in variables.
I tried using the formula you gave, but it seems I am coming up with incorrect answers.
I wish I had better programming skills, but can not seem to find where the error is.
11-29-2021, 07:33 PM
Post: #10
 roadrunner Senior Member Posts: 418 Joined: Jun 2015
RE: Equation of Tangent
Are you running it from HOME or CAS? It appears to only work from HOME, which wasn't expected, and I'm not sure why. I thought all PPL programs ran from HOME regardless of which screen it is started from.

12-01-2021, 05:28 AM
Post: #11
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
Thanks Road. I am running it in Home, not CAS.
When I run the original program using the slope function, this is what I get:

Attached File(s) Thumbnail(s)

12-01-2021, 05:30 AM
Post: #12
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
And when I run the second program this is what I get:

Attached File(s) Thumbnail(s)

12-08-2021, 02:06 PM
Post: #13
 roadrunner Senior Member Posts: 418 Joined: Jun 2015
RE: Equation of Tangent
This one might work better, but it's more complicated:

Code:
 EXPORT TANGENT() BEGIN  LOCAL a, f, df, b, fn, ff, sf;  PRINT;  INPUT (fn, "Function:", "f (X) =", "Enter the algebraic expression");  CASE   IF fn==1 THEN    F1▶f;    diff(F1(X),'X',1)▶df;   END;   IF fn==2 THEN    F2▶f;    diff(F2(X),'X',1)▶df;   END;   IF fn==3 THEN    F3▶f;    diff(F3(X),'X',1)▶df;   END;   IF fn==4 THEN    F4▶f;    diff(F4(X),'X',1)▶df;   END;   IF fn==5 THEN    F5▶f;    diff(F5(X),'X',1)▶df;   END;   IF fn==6 THEN    F6▶f;    diff(F6(X),'X',1)▶df;   END;   IF fn==7 THEN    F7▶f;    diff(F7(X),'X',1)▶df;   END;   IF fn==8 THEN    F8▶f;    diff(F8(X),'X',1)▶df;   END;   IF fn==9 THEN    F9▶f;    diff(F9(X),'X',1)▶df;   END;   IF fn==0 THEN    F0▶f;    diff(F0(X),'X',1)▶df;   END;  DEFAULT   RETURN "error";  END;  INPUT (a, "Study of the tangent at x =?", " X =");  PRINT ("f (X) =" + f);  PRINT ("Equation of the tangent at " + a + " :");  EXPR(REPLACE(STRING(df), "X", STRING(a)))▶sf;  EXPR(REPLACE(STRING(f), "X", STRING(a)))▶ff;  PRINT ("Y =" + sf + "(X -" + a + ") +" + ff);  −sf * a + ff ▶ b;  PRINT ("that is: Y =" + sf + IFTE(b<0,"X -","X +") + ABS(b)); END;

12-16-2021, 09:21 PM
Post: #14
 vjc Junior Member Posts: 10 Joined: Oct 2020
RE: Equation of Tangent
That works flawlessly. Perfect solution for something missing inherently in Prime.
I don't know why is it missing in Prime whereas both Casio and TI calculators display the equation of Tangent right on the screen where the Tangent is drawn.
You made it work. That was an elaborate and long program you wrote, must have taken a lot of your time and effort, many thanks once again.
12-19-2021, 11:28 PM
Post: #15
 RobbiOne Junior Member Posts: 4 Joined: Oct 2020
RE: Equation of Tangent
in order to run on a G2 with new firmware (25 nov 2021), change all "diff" lines
from:
diff(Fn(X),'X',1)▶df;
to
diff(Fn(X),X)▶df; or diff(Fn(X))▶df;
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)