# Tag Archives: tex

## An M-file to generate easy-to-row-reduce matrices

In my Linear Algebra class we use a lot of MATLAB — including on our timed tests and all throughout our class meetings. I want to stress to students that using professional-grade technological tools is an essential part of learning a subject whose real-life applications closely involve the use of those tools. However, there are a few essential calculations in linear algebra, the understanding of which benefits from doing by hand. One of those calculations is row-reduction. Nobody does this by hand; but doing it by hand is useful for understanding elementary row operations and for getting a feel for the numerical processes that are going on under the hood. And it helps with understanding later concepts, notably that of the LU factorization of a matrix.

I have students take a mastery exam where they have to reduce a 3×5 or 4×6 matrix to reduced echelon form by hand. They are not allowed any technology on that exam. I’ve learned that making up good matrices for this exam is surprisingly tricky. My first attempt at writing the exam resulted in a nice-looking matrix whose reduced echelon form had mind-bendingly big fractions in it. I want the exam to be about row reduction and not fraction arithmetic, so I  sat down this morning and wrote this MATLAB function called easyRR.m which automatically spits out $m \times n$ random integer matrices whose row-reduction process might involve fractions but which aren’t horrendous:

%% Function to create an mxn matrix that is easy to row-reduce by hand.
% Basic idea: Construct this matrix by building an LU factorization for it
% where both L and U have small integer values.
% R. Talbert, Feb 15, 2011

function A = easyRR(m,n)

%% Create the L in the LU factorization. This matrix encodes the elementary
%% row operations needed to get A to echelon form.

L = randi([-10, 10], [m,m]);

% Replace diagonal elements with 1's:
for i=1:m
L(i,i) = 1;
end

% Zero out all entries above the diagonal:
L = tril(L);

%% Now create the U in the LU factorization, using smaller integers so that
%% the back substitution phase isn't too bad.

% This creates an mxn random integer matrix and zeros out all entries below
% the diagonal.
U = triu(randi([-5,5], [m,n]));

%% The easy-to-reduce matrix is the product of L and U.
A = L*U;



Here’s a screenshot:

The fractions involved here have denominators no larger than 25, which is way more doable for students than what I had been having them work with (sorry, guys).

And, if you happen to have the Symbolic Toolbox for MATLAB, you can add the line latex(sym(A)) to the end and the function will spit out the $\LaTeX$ code for that matrix, for easy copy/paste into the exam.

Anyway, I thought this was useful and so I’m giving it away!

Filed under LaTeX, Linear algebra, Math, MATLAB, Teaching

## Five reasons you should use LaTeX and five tips for teaching it

Over the weekend a minor smack-talk session opened up on Twitter between Maria Andersen and about half a dozen other math people about MathType versus $\LaTeX$. Maria is on record as being pro-MathType and yesterday she claimed that $\LaTeX$ is “not intuitive to learn”.  I warned her that a pro-$\LaTeX$  blog post was in the offing with those remarks, and so it comes to this. $\LaTeX$ is accessible enough that every math teacher and every student in a math class at or above Calculus can (and many should) learn $\LaTeX$ and use it for their work. I have been using $\LaTeX$ for 15 years now and have been teaching it to our sophomore math majors for five years. I can tell you that students can learn it, and learn to love it.

Why use $\LaTeX$ when MathType is already out there, bundled with MS Word and other office programs, tempting us with its pretty point-and-click interface? Five reasons.

1. $\LaTeX$ looks better. Seriously. MathType is getting better at visual appeal — it doesn’t look appalling any more — but nothing beats $\LaTeX$ for refinement and polish.
2. $\LaTeX$ is the mathematical typesetting standard in all technical disciplines and in many related fields. Most, if not all, major publications in math, computer science, engineering, and physics use $\LaTeX$ as the preferred typesetting system. arXiv prefers $\LaTeX$ over all other formats.
3. $\LaTeX$ is becoming a standard elsewhere, especially on the web. Last year, Google Documents added an equation editor that is basically a stripped-down $\LaTeX$ editor with a point-and-click interface. The wildly popular online presentation tool Prezi has said that $\LaTeX$ integration is coming. WordPress.com blogs like Casting Out Nines can do $\LaTeX$, and so can Wikispaces and several other web services. Online $\LaTeX$ typesetters abound, and more are popping up. The web likes open standards, and since MathML is all but impossible to use, $\LaTeX$ fills a gaping need for free, open-source mathematical typesetting. Which brings me to the next point:
4. $\LaTeX$ is free. Free as in beer and free as in freedom. You can download it right now for just about any operating system imaginable, and have the full strength of the system available to you at no cost. And this is a system that has been around for 40 years (if you count TeX) and has millions of users, many of whom actively contribute to the further development of the system by writing specialized packages and macros. This is in stark contrast to MathType, which is proprietary and closed, and although you get the “Lite” version bundled in with office software, the full version will set you back at least \$37.
5. $\LaTeX$ is what you make it. You can use $\LaTeX$ with a point-and-click IDE, or you can type everything out by hand with a text editor and compile from the command line, or anything in between. You can tinker with the low-level creation of fonts or just quickly type out a letter. It’s up to the user. Other proprietary programs force a menu-driven point-and-click approach upon you, which you may like but may not like.

Others may add to these in the comments. But if $\LaTeX$ is so great, how come nobody ever seems to learn it until graduate school? I’m not sure, but it’s not because $\LaTeX$ is counterintuitive. It’s not totally obvious, either, but with a little guidance, $\LaTeX$ can make perfect sense even to high school students. If you’re a math or science teacher, make it a project to learn $\LaTeX$ yourself and start using it in your classes, then teach it to your students. Here are five ways to make that a painless process.

1. Use an IDE or a user-friendly text editor rather than a plain, no-frills text editor or EMACS. For Windows machines, use the free TeXNicCenter IDE that gives point-and-click code insertion (or you can just type the code in) with syntax highlighting. On Macs, use TextMate if you have the money and Aquamacs if you don’t; both of these are text editors with tons of great $\LaTeX$ goodies built in. (In TextMate, for instance, typing begin and hitting the Tab key automatically creates an environment with the matching \end{}. ) On Linux, try Kile. These provide user-friendly interfaces and syntax highlighting that take the edge off some of the learning curve.
2. Have someone else do the installation and setup, or provide a total handholding guide for doing it. The only really hard thing about using $\LaTeX$ is simply getting it to work in the first place. This is one of the advantages MathType has over $\LaTeX$, but the payoff is worth it. New users will need to be walked through the whole process in high-definition detail. But once that’s over, the fun begins.
3. Start small and simple, and build gradually. When first getting students to use $\LaTeX$, restrict them to just a small, relatively simple document, one that’s mostly text with a little bit of math typsetting required. Small, early successes will convince them that learning $\LaTeX$ is worthwhile. I like to give out my training videos to students and have them learn the system on their own; then have a grace period where students get extra credit for doing their assignments in $\LaTeX$; and then start requiring it after the grace period expires.
4. Use it yourself. Students will learn from your example. Try writing your next syllabus in $\LaTeX$; and your class handouts; and your tests (perhaps using the excellent exam package). When you use it, and students begin to use it, they see that they are producing math that looks as good as what the pros do, and they get excited.
5. When you give a document made with $\LaTeX$, also give out the source code that generated it. Students can then look at what you created, ask “How’d s/he do that?”, and get the answer immediately from your code and do it themselves. I myself have learned about half the $\LaTeX$ I know from this method, and adapting/tweaking someone else’s code is a time-honored and very effective means of learning almost anything done on a computer.

Once they are over the initial learning curve and producing beautiful mathematical documents, my students look back on the dark days of MS Equation Editor and wonder, along with me, why anybody would put themselves through something like that. Happy $\LaTeX$-ing!

Filed under LaTeX, Math, Profhacks, Social software, Teaching, Technology, Twitter, Uncategorized

## 12 videos for getting LaTeX into the hands of students

There seem to be two pieces of technology that all mathematicians and other technical professionals use, regardless of how technophobic they might be: email, and $\LaTeX$. There are ways to typeset mathematical expressions out there that have a more shallow learning curve, but when it comes to flexibility, extendability, and just the sheer aesthetic quality of the result, $\LaTeX$ has no rival. Plus, it’s free and runs on every computing platform in existence. It even runs on WordPress.com blogs (as you can see here) and just made its entry into Google Documents in miniature form as Google Docs’ equation editor. $\LaTeX$ is not going anywhere anytime soon, and in fact it seems to be showing up in more and more places as the typesetting system of choice.

But $\LaTeX$ gets a bad rap as too complicated for normal people to use. It seems to be something people learn only in graduate school, with few undergraduates — and even fewer high school students — ever seeing it, much less using it. There is a grain of truth there; $\LaTeX$ is not a WYSIWYG word processor, and the near-programming aspect of using $\LaTeX$ can overwhelm users used to pointing-and-clicking for everything.

But I think that the benefits of using $\LaTeX$ outweigh the costs, and undergraduates and high school students can, and ought to, learn how to use $\LaTeX$ as fluently as they use a word processor for other courses. A couple of years ago, I put together a series of twelve screencasts for use in our sophomore “transition-to-proof” class on learning $\LaTeX$. I put these screencasts online, but mainly they were only advertised to my students and colleagues. Now, however, I’d like to throw these out there for everyone to use.

All twelve of these are done on a Windows system running MiKTeX and the free $\LaTeX$ IDE known as TeXNicCenter.  This provides students with as close to a point/click interface to $\LaTeX$ as you could expect to get. Within that context, there are two basic intro videos:

These two videos are enough to learn how $\LaTeX$ works and will allow you to make a simple file with uncomplicated math and text in it. The remaining 10 videos follow from these two. Some are prerequisites for the others — and those prereqs are stated explicitly at the beginning of any video that has them — but if you watch them in the following order there will be no dependency problems:

Some of these are pretty long, but all totalled (including the two “basics” videos) this is less than two hours of viewing.

When I’ve used these in class, I give students some printed instructions on how to download and configure MiKTeX and TeXNicCenter, and then I have them watch these videos out of class. They are instructed to work along with the videos. I give them about a week to do so. Within that week, if there’s a problem set or something else in the class that could be done with $\LaTeX$, I’ll offer extra credit to students to do so, to incentivize their learning the system. After the end of that week, I will insist that all major assignments have to be done in $\LaTeX$, or else the assignment gets a grade of “0”.

Students have sometimes struggled to get up the learning curve, but if they’re allowed and encouraged to help each other, everyone eventually gets to the point where they are quite fluent writing up homework and so on. Students have even elected to use $\LaTeX$ on assignments in other courses, even non-math courses.

I’m going to use these videos in linear algebra this semester (our transition-to-proof course is now defunct) and I’ll be making up a new screencast on MATLAB and $\LaTeX$. Later, probably during the summer, I’ve been thinking about redoing the entire video series; I now have better screencasting tools than I used to have, and I’d like to keep all the videos under 10 minutes so they can go on YouTube.

So feel free to use these (attributing authorship to me is appreciated but not required), and if you have suggestions or comments, please email them or leave them below.

Filed under LaTeX, Linear algebra, Math, Problem Solving, Technology

## LaTeX as a word processor?

Good article here at The Productive Student giving five reasons why students should use $\LaTeX$ as their word processor and not Microsoft Word:

1. Never worry about formatting again.
2. It looks way better. [By the way: Very nice article on LaTeX’s typesetting at that link.]
3. It won’t crash: LaTeX is basically a plain text file. You can edit it anywhere, in any text editor, and it basically can’t crash on you. File size is very small which makes it very portable.
4. It’s great for displaying equations, which is why it’s the leading standard among sciencitifc scholars.
5. It fits in with the workflow of a student and allows you to do one thing well: Write.

The writer also shares some of his practices for writing papers (not necessarily math or science papers) with $\LaTeX$, stressing $\LaTeX$‘s ability to handle bibliographic data as the “killer feature”.

$\LaTeX$ was not designed to be a word processor, so there are some downsides for using $\LaTeX$ for word processing. Graphics are not easy to handle, if you are going to include any in your document. Some basic formatting tasks like footers and margin settings are tricky to manipulate. And above all, there is a fairly formidable learning curve to $\LaTeX$, not the least of which is the fact that you have to install things yourself (something a surprisingly large number of students don’t know how to do) and use a text editor. (We forget that text editors are essentially an alien world to students who are raised on GUI’s for everything.) And for collaborative projects, Word’s ability to insert comments and track changes in a document is really essential.

Still, I think most college students can learn $\LaTeX$ if they put their minds to it, and the fact that it’s free and portable and “future-proof” is awfully appealing in a world where this year’s version of Word can’t be trusted to interoperate with last year’s.

Finally, I think there’s a lot to be said for something the article brings up as well: You should use a text editor to write content, and a word processor to format it. Type it up in a basic editor or Google Docs, and then import it into your favorite proprietary program(s) to make it look nice. Separating content from form will save a lot of people headaches and improve their writing as well.