Post Reply 
Program takes in variable non exact.
07-16-2016, 08:31 AM
Post: #1
Program takes in variable non exact.
When I use my custom functions, I must put my equation into quotation marks if I want it to stay exact. This happens even if my CAS settings are "exact". For example:
Quotation Marks vs No Quotation Marks

Is there a way on the program side to not have this happen? I don't want to be doing an exam and have to go through yet another step in solving the questions.

Thanks in advance.
Find all posts by this user
Quote this message in a reply
07-17-2016, 06:29 PM
Post: #2
RE: Program takes in variable non exact.
Have you considered a CAS program? An example:

Code:
#cas
Saturday(param):=
BEGIN
 return exact(param);
END;
#end

Saturday(π+√(3)) returns π+√(3) in home and CAS
Saturday(0.3) returns 3/10 in home and CAS
Find all posts by this user
Quote this message in a reply
07-18-2016, 07:31 AM (This post was last modified: 07-18-2016 07:32 AM by CH3791.)
Post: #3
RE: Program takes in variable non exact.
Hi Roadrunner, thanks once again for responding to one of my questions.

Your code does exactly what I want it to do, but I just can't seem to get it to work on my calc. This is as close as I could get to your code.

Code:
EXPORT Sunday(my_input)
BEGIN
  return exact(my_input);
END;

This returned an answer of 6683778/1371413 which is clearly a fractional representation of π+√(3). Thus, can you show me more exactly how to create a "CAS program".
Find all posts by this user
Quote this message in a reply
07-18-2016, 11:38 AM
Post: #4
RE: Program takes in variable non exact.
Use this template:

Code:
#cas
name_of_program(paramaters):=
BEGIN
 //put your code here

 return 0; //replace 0 with what you need returned
END;
#end

Normal programs are run in HOME mode, that's why you don't get symbolic results. The #cas and #end tell the compiler to run this code in CAS mode.

Just copy and paste the template above into the emulator, change the name, and add your code. Also return the answer you want instead of 0. It's hard to be more specific without seeing the actual code you are trying to write.

-road
Find all posts by this user
Quote this message in a reply
07-18-2016, 12:58 PM
Post: #5
RE: Program takes in variable non exact.
Hi Roadrunner,
I've done what you said and was able to get it to work:
   
   
   

But now my question is, why can't I find this program through the Toolbox>User>Program Functions?
   
Find all posts by this user
Quote this message in a reply
07-18-2016, 03:25 PM
Post: #6
RE: Program takes in variable non exact.
(07-18-2016 12:58 PM)CH3791 Wrote:  But now my question is, why can't I find this program through the Toolbox>User>Program Functions?

It will be in variables->CAS-> <there>

One difference between the way that the CAS system handles things is that all objects are "variables". To the cas, a program function you made is essentially identical to storing a number into 'x'. They both are variables, that contain something. In the case of the little function, it is a small set of commands that execute steps.

When you use the #cas #end stuff, you are actually telling the program compiler "execute the things I'm typing within this block as if I typed them on the CAS screen". If you do something like myfunc(x,y):=x+y on the cas screen, you get a variable named myfunc, that contains a function taking two arguments. Note that is you delete/remove/rename your function that was created in your program, it could disappear unexpectedly. To "get it back", opening the program file, then exiting it again would then reexecute those commands and make the CAS variable again.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
07-31-2016, 05:06 AM
Post: #7
RE: Program takes in variable non exact.
Thanks very much guys, sorry for this late reply.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: