[SOLVED] Given (|) in programming?
05-29-2016, 04:57 AM (This post was last modified: 06-21-2016 11:27 AM by CH3791.)
Post: #1
 CH3791 Junior Member Posts: 40 Joined: May 2016
[SOLVED] Given (|) in programming?
Hi, I am trying to make a program that calculates x intercepts. Right now, it can calculate the answer, but I can't make it restrict the domain.

I understand you can do this directly in the CAS app:
solve(SIN(x)=0,x)|{(x>-10) AND (x<10)}
{-3*pi, -2*pi, -pi, 0, pi, 2*pi, 3*pi}

But when I put that kind of syntax into my program, it returns "Error: Invalid input".
Code:

EXPORT XINT(expression,domainlow,domainhigh)
BEGIN
LOCAL equation;
LOCAL variable;
variable:="x";
equation:=EXPR(LOWER(STRING("0="+expression)));
print("X-INTERCEPT(S)");
RETURN "DONE";
END;

Any ideas?
05-29-2016, 08:24 AM
Post: #2
 roadrunner Senior Member Posts: 443 Joined: Jun 2015
RE: Given (|) in programming?
I'm not sure that syntax, using the "|" operator, is valid within a program; but using assume() and additionally() does appear to work. See modified program below:

Code:
EXPORT XINT1(expression,domainlow,domainhigh)
BEGIN
LOCAL equation;
LOCAL variable;
variable:="x>"+string(domainlow);
CAS.assume(EVAL(variable));
variable:="x<"+string(domainhigh);
// variable:="x";
equation:=EXPR(LOWER(STRING("0="+expression)));//EXPR means convert to a string.
print("X-INTERCEPT(S)");
RETURN "DONE";
END;
05-29-2016, 08:47 AM (This post was last modified: 05-29-2016 08:55 AM by CH3791.)
Post: #3
 CH3791 Junior Member Posts: 40 Joined: May 2016
RE: Given (|) in programming?