Post Reply 
Integral Step by Step Solver for HP Prime
04-14-2023, 09:11 PM
Post: #1
Integral Step by Step Solver for HP Prime
EXPORT IndefiniteIntegration()
BEGIN
// Set up program variables
LOCAL f, int, choice;

// Prompt the user to enter the function to be integrated
TextOut(1,1,"Enter the function to be integrated:");
f:=CAS(INPUT());

// Prompt the user to choose the integration method
TextOut(1,2,"Choose the integration method:");
TextOut(1,3,"1. Substitution");
TextOut(1,4,"2. Integration by parts");
TextOut(1,5,"3. Partial fractions");
TextOut(1,6,"4. Trigonometric substitution");
TextOut(1,7,"5. Integration by inspection");
choice:=INPUT();

// Use integration by substitution to find the indefinite integral
IF choice=1 THEN
int:=SubstitutionIntegration(f);

// Use integration by parts to find the indefinite integral
ELSEIF choice=2 THEN
int:=IntegrationByParts(f);

// Use partial fractions to find the indefinite integral
ELSEIF choice=3 THEN
int:=PartialFractionIntegration(f);

// Use trigonometric substitution to find the indefinite integral
ELSEIF choice=4 THEN
int:=TrigSubstitutionIntegration(f);

// Use integration by inspection to find the indefinite integral
ELSEIF choice=5 THEN
int:=InspectionIntegration(f);

ELSE
// Display an error message if an invalid choice is entered
TextOut(1,8,"Error: Invalid choice");
RETURN;
END;

// Display the intermediate steps and the final result
TextOut(1,8,"Indefinite integral:");
TextOut(1,9,STRING(int)+"+C");
END;

// Helper function for substitution integration
EXPORT SubstitutionIntegration(f)
BEGIN
LOCAL u, v, du, dv, int;
u:=CAS(Str("u=",SubstVar(f)));
v:=Int(Simplify(f/SubstVar(f))*SubstVar(f),SubstVar(f));
dv:=CAS(Deriv(v,SubstVar(f)));
du:=CAS(Deriv(u,SubstVar(f)))*CAS(Deriv(SubstVar(f)));
int:=Simplify(SubstVar(f)*v-Int(v*dv/SubstVar(f))-Int(u*du,SubstVar(f)));

// Display the intermediate steps
TextOut(1,10,"Step 1: Let u = "+STRING(u));
TextOut(1,11,"Step 2: Find dv/d"+STRING(u)+" = "+STRING(dv));
TextOut(1,12,"Step 3: Find v = "+STRING(v));
TextOut(1,13,"Step 4: Substitute into the integral:");
RETURN Simplify(int);
END;

// Helper function for integration by parts
EXPORT IntegrationByParts(f)
BEGIN
LOCAL u, v, du, dv, int;
u:=FirstVar(f);
v:=Int(Simplify(f/u),u);
dv:=CAS(Deriv(v));
du:=CAS(Deriv(u));
int:=Simplify(u*v-Int(v*du)-Int(u*dv));

// Display the intermediate steps
TextOut(1,10,"Step 1: Let u = "+STRING(u));
TextOut(1,11,"Step 2: Let dv = "+STRING(dv));
TextOut(1,12,"Step 3: Find v = "+STRING(v));
TextOut(1,13,"Step 4: Substitute into the integral:");
RETURN Simplify(int);
END;

// Helper function for partial fraction integration
EXPORT PartialFractionIntegration(f)
BEGIN
LOCAL pf, int;
pf:=PartialFraction(f);
int:=0;
FOR i FROM 1 TO Size(pf) DO
int:=int+Simplify(Int(pf[i]/pf[i][1]));
END;

// Display the intermediate steps
TextOut(1,10,"Step 1: Find the partial fraction decomposition:");
FOR i FROM 1 TO Size(pf) DO
TextOut(1,10+i,STRING(pf[i])+" = "+STRING(pf[i][1])+" / ("+STRING(pf[i][2])+")");
END;
TextOut(1,10+Size(pf)+1,"Step 2: Integrate each term:");
RETURN Simplify(int);
END;

// Helper function for trigonometric substitution integration
EXPORT TrigSubstitutionIntegration(f)
BEGIN
LOCAL u, v, du, dv, int, choice;

// Prompt the user to choose the trigonometric substitution
TextOut(1,10,"Choose the trigonometric substitution:");
TextOut(1,11,"1. x = a*sin(u)");
TextOut(1,12,"2. x = a*tan(u)");
TextOut(1,13,"3. x = a*sec(u)");
choice:=INPUT();

// Use the selected trigonometric substitution to find the indefinite integral
IF choice=1 THEN
u:=CAS(Str("u=asin(x/a)"));
v:=Int(Simplify(f*Cos(u))/a,u);
int:=Subst(v,SubstVar(f),u);

// Display the intermediate steps
TextOut(1,15,"Step 1: Let x = a*sin(u)");
TextOut(1,16,"Step 2: Find dx/d"+STRING(u)+" = "+STRING(a*Cos(u)));
TextOut(1,17,"Step 3: Substitute into the integral:");
ELSEIF choice=2 THEN
u:=CAS(Str("u=atan(x/a)"));
v:=Int(Simplify(f*Sec(u)^2)/a,u);
int:=Subst(v,SubstVar(f),u);

// Display the intermediate steps
TextOut(1,15,"Step 1: Let x = a*tan(u)");
TextOut(1,16,"Step 2: Find dx/d"+STRING(u)+" = "+STRING(a*Sec(u)^2));
TextOut(1,17,"Step 3: Substitute into the integral:");
ELSEIF choice=3 THEN
u:=CAS(Str("u=acos(x/a)"));
v:=Int(Simplify(f*Sin(u)*Sec(u))/a,u);
int:=Subst(v,SubstVar(f),u);

// Display the intermediate steps
TextOut(1,15,"Step 1: Let x = a*sec(u)");
TextOut(1,16,"Step 2: Find dx/d"+STRING(u)+" = "+STRING(a*Sin(u)*Sec(u)));
TextOut(1,17,"Step 3: Substitute into the integral:");
ELSE
// Display an error message if an invalid choice is entered
TextOut(1,15,"Error: Invalid choice");
RETURN;
END;

RETURN Simplify(int);
END;

// Helper function for integration by inspection
EXPORT InspectionIntegration(f)
BEGIN
LOCAL int;
int:=Int(f);

// Display the intermediate steps
TextOut(1,10,"Step 1: Recognize the integral:");
TextOut(1,11,"Step 2: Integrate the recognized form:");
RETURN Simplify(int);
END;

Permanently banned
Find all posts by this user
Quote this message in a reply
06-03-2023, 06:08 PM
Post: #2
RE: Integral Step by Step Solver for HP Prime
hi, unfortunately this is not working, i keep getting syntax errors all over the code :/
Find all posts by this user
Quote this message in a reply
Yesterday, 05:43 AM
Post: #3
RE: Integral Step by Step Solver for HP Prime
Hi, do you need to connect to a pc to run this?
Find all posts by this user
Quote this message in a reply
Post Reply 




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