# SageTex Problems page

As a teacher, one of the most convenient uses of SageTex is being able to use it create randomized tests along with an answer key as was mentioned here. The problem, however, is that programming and testing the code can take a while, so the SageTex Problems page is a chance to accumulate problems that can be easily dropped into a randomized test of your own.

results in a problem and solution that looks something like this:

There's some awkwardness in the code because you can get solution which have + and - next to each other. That's obviously not ideal but requires more code than it's worth to clean it up.

If you have any problem code to contribute, let me know and I'll be happy to post it.

# Sage: Quadratic Data and Regression

I've added code to the Python/Sage page as well as the Sage in the Classroom page for creating quadratic data as well as as finding the quadratic curve to fit quadratic data. The code is a simple extension of the Linear Regression in the previous post but, as I've mentioned earlier, various regression models are a part of precalculus. I'll certainly need these; perhaps you'll find them useful, too.

# Sage: Linear Regression

Linear regression, unfortunately, has found its way into the precaluclus curriculum; the tendency is to stuff too many subjects into the curriculum, especially when it involves using a calculator. I've put together some code for finding the regression line that best fits the data at hand. The code is posted on the Python/Sage page as well as the Sage in the Classroom page and you can see a screenshot (above). I've included it below as well:

r = [[0,76.4], [1,78.5], [2,81.5], [3,87.8], [4,88.4], [5,92.4], [6,94.0], [7,95.0]]

var('x,a,b')
model(x) = a*x+b
a = find_fit(r, model)[0].rhs()
b = find_fit(r,model)[1].rhs()
html("Regression line is %4.2fx+%4.2f"%(a,b))

points(r,color='red',size=20)+ plot(model(a = find_fit(r, model)[0].rhs(),b = find_fit(r,model)[1].rhs()),0,15,xmin = 0,xmax = 10)

The variable r is the set of data points and after declaring the variable a,x,b and
the model ax+b we're ready to solve the problem. This is accomplished through find_fit which returns the values of the variables in a list; a = find_fit(r, model)[0].rhs() gets us the value of a which we format more nicely when printing our answer with html("Regression line is %4.2fx+%4.2f"%(a,b)). After that, we plot the points and regression line on the same graph and print it out.

So now you have, I hope, some useful resources. You can create linear data from an earlier post and find the linear regression line with the code in today's post.

# Sage Tutoring: Polynomials

I've added code for generating random polynomials and then calculating the sum, difference, product and quotient of the polynomials. You can find it on the Sage in the Classroom page.

Sage has a lot of support for polynomials; the basics can be found here. The line R.<x>=QQ[] tells Sage that the polynomials will have coefficients over the rational numbers.

degree1=Integer(randint(2,5)) chooses the degree of the first polynomial to be a number between 2 and 5, inclusive, after which p1=R.random_element(degree1) will create a random polynomial of that degree. After that the code is straightforward except for the division calculation. If you divide two polynomials you won't get a quotient and remainder; you'll get the first polynomial in the numerator and the second polynomial in the denominator. To force the simplification, we need

print p1//p2,' + ',(p1%p2)/p2

p1//p2 calculates the quotient and (p1%p2) is the remainder.