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;
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
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=3x-4
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.
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
You nailed it Roadrunner. Thanks a lot once again.
You solved my problem.
Much grateful.
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??
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()
BEGIN
LOCAL 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.
-road
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.
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
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:
And when I run the second program this is what I get:
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;
-road
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.
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;