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.

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

SageTex1There'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

QuadRegI'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

SageLinRegLinear 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]]

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

PolynomialsI'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.

Sage Interact: Passwords


A friend sent me a link recently through e-mail. When I clicked on it, it was clear that my friend's e-mail had been hacked. Several days later, my e-mail was hacked. So I've been thinking a little bit about security and passwords. Wikipedia is always a good place to start a search; it led me to this page. The main point I took away is that my knowledge was outdated because (as of 2011) technology "...can crack a 10 letter single-case password in one day.". Their guideline suggest a password of length at least 12-14 characters. Other websites suggested that at least 16 characters should be used. The criteria for what was a secure password also varied; the information here looked, to me, like the best criteria.

The warning at the website here got me thinking: why not create my own passwords with the help of Sage? The code is straightforward and it's posted on the Python/Sage page. The output is shown above. Just pick the length of the password and how many passwords you want. If you're still not sure about how secure the passwords are, you can check the strength at sites like this or this.