Equation of Tangent

11022021, 05:46 PM
Post: #1




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; 

11032021, 03:13 PM
Post: #2




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"); road 

11042021, 02:52 AM
Post: #3




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: y=3x+4 instead of y=3x4 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. 

11042021, 12:35 PM
Post: #4




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. road 

11052021, 01:05 AM
Post: #5




RE: Equation of Tangent
You nailed it Roadrunner. Thanks a lot once again.
You solved my problem. Much grateful. 

11092021, 06:33 AM
Post: #6




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 copypasting the entire expression. Any ideas anyone?? 

11122021, 10:07 PM
Post: #7




RE: Equation of Tangent
Any Answers, anyone??


11182021, 11:51 PM
Post: #8




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() 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. road 

11292021, 07:42 AM
Post: #9




RE: Equation of Tangent
Thanks Road once again.
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. 

11292021, 07:33 PM
Post: #10




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.
road 

12012021, 05:28 AM
Post: #11




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: 

12012021, 05:30 AM
Post: #12




RE: Equation of Tangent
And when I run the second program this is what I get:


12082021, 02:06 PM
Post: #13




RE: Equation of Tangent
This one might work better, but it's more complicated:
Code:
road 

12162021, 09:21 PM
Post: #14




RE: Equation of Tangent
Thanks Road,
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. 

12192021, 11:28 PM
Post: #15




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)