STACK: How to check if a point is in a domain of a function given by the student?

STACK: How to check if a point is in a domain of a function given by the student?

by Luiz Gustavo Cordeiro -
Number of replies: 3

Hello.

I am working with limits and undefined expressions, and I have a question which asks for an elementary function which is not defined at a point x0, but whose limit at x0 exists and is equal to some given number a0.

The student inputs his answer in "ans1", as an formula on the variable x. I can check for the limit easily, but I do not know how to check whether the formula given by the student has x=x0 as a point in its domain. Below is a simplified version of it:


Question variables:

x0=rand([-2,-1,0,1,2]);
a0=rand([-2,-1,0,1,2]);
possible_response(x):=a0*sin(x-x0)/(x-x0);

Question:

Write down a formula for \(f(x)\) which defines an elementary function which does not have {@x0@} in its domain, but for which \(\displaystyle{\lim_{x\to {@x0@}}f(x)={@a0@}}\).
Answer: f(x)=ans1 validation:ans1


Checking for the limit works well with AlgEquiv and Maxima's limit function (even for in/undefined limits), but I do not know how to check if x=x0 is in the domain of ans1. Whenever I try to evaluate ans1 at x=x0 via subst([x=x0],ans1), if it is not in its domain (e.g. ans1=a0*sin(x-x0)/(x-x0)), I get a "division by zero" error and no points are given,


Thanks, Christopher Sangwin,Tim at Lone Pine Koala SanctuaryTim Hunt, for this amazing plugin.

Average of ratings: -
In reply to Luiz Gustavo Cordeiro

Re: STACK: How to check if a point is in a domain of a function given by the student?

by Luiz Gustavo Cordeiro -
More specifically, this is the error I get with division by zero:

Division by zero. Division by zero. Node PRSANS1 generated the following runtime error: Division by zero.
In reply to Luiz Gustavo Cordeiro

Re: STACK: How to check if a point is in a domain of a function given by the student?

by Robert Mařík -

In Maxima you can evaluate in errcatch command which prevents to issue the error and returns empty list instead. See the Maxima manual. The following code returns 1 if ans1 is undefined at x0 and 0 otherwise.

x0:4;
ans1:sin(x-3)/(x-3);
ans2:errcatch(subst([x=x0],ans1));
if ans2=[] then 1 else 0;