Problem with zeros and solve in HP Prime.
01-20-2014, 10:01 PM (This post was last modified: 01-20-2014 11:27 PM by Han.)
Post: #4
 Han Senior Member Posts: 1,871 Joined: Dec 2013
RE: Problem with zeros and solve in HP Prime.
zeros() works fine when used as follows:

Code:
zeros("(x-1)*(x-2)*(x+1)*e^(-1/2*x^2)","x")

as does the case when e^() is replaced with exp(). You were correct to cast fd as a string. I wonder if there is an issue with your use of collect() -- it too is a CAS command and requires its arguments to be cast as strings. So if d(1) is not a string, you might get nonsensical results since it will be evaluated via the Home view.

Also you do not need to add two null strings when forming temp, if the goal is simply to cast fd as a string. Use one of the two shown below:

Code:
temp:=""+fd; // or temp:=STRING(fd);

Be aware that STRING() and string() behave slightly differently depending on Home vs CAS view. This is not an issue in a program since everything executes as if in the Home view.

An easy way to track down the problem debug it.

Here's an example of how to implement it. Usage: EXTREMA("x^3-3*x","x") Note that only minimal error checking is in place. Your actual program should check to see if complex mode is on (this may affect the results of zeros()), and other details I have left out.

Code:
 TestSD(); EXPORT EXTREMA(f,v) BEGIN   local fd,cp,sd,n,j,r={};   fd:=STRING(diff(f,v));   // create a second deriv test function   sd:="sd_(" + v + "):=" + diff(fd,v);   CAS(sd);   cp:=zeros(fd,v);   n:=SIZE(cp);   if TYPE(n)==6 then n:=n(1); end;   if n then     r:=makelist(TestSD(cp(X)),X,1,n);    else     return("No extrema found");   end;   // delete function   CAS("purge(sd_)");    return(r); END; TestSD(x) begin   local s;   // ensure no singularities   iferr     s:=EXPR("sign(sd_("+x+"))");   then     return({x,"2nd deriv singularity"});   end;   case     if s>0 then return({x,"Min"}); end;     if s<0 then return({x,"Max"}); end;     return({x,"2nd deriv = 0"});   end;  end;

Graph 3D | QPI | SolveSys
 « Next Oldest | Next Newest »

 Messages In This Thread Problem with zeros and solve in HP Prime. - John P - 01-20-2014, 11:08 AM RE: Problem with zeros and solve in HP Prime. - Han - 01-20-2014, 03:11 PM RE: Problem with zeros and solve in HP Prime. - John P - 01-20-2014, 04:08 PM RE: Problem with zeros and solve in HP Prime. - Han - 01-20-2014 10:01 PM RE: Problem with zeros and solve in HP Prime. - Michael de Estrada - 01-21-2014, 01:19 AM RE: Problem with zeros and solve in HP Prime. - Han - 01-21-2014, 01:31 AM RE: Problem with zeros and solve in HP Prime. - John P - 01-21-2014, 10:18 AM

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