Is it possible to do elementary row operations on a matrix in Wolfram Alpha? I know that I can row-reduce a matrix, but I’d like to be able to do row operations (scale a row, replace a row by the sum of itself and a multiple of another row, interchange rows).
There might be quicker ways, but I know you can operate on rows and columns of lists:
table = RandomInteger[9, {10, 10}];
table[[1, All]] = table[[1, All]] * 2 (* multiply every element of first row by 2*)
table[[-1, All]] = Total[table[[1 ;; -2, All]]] (* replace last row by totals of each column *)
temp = table[[-1, All]] (* save last row *)
table[[-1, All]] = table[[1, All]] (* copy top row to last row *)
table[[1, All]] = temp (* replcae top row with saved row *)
I tend to create new tables rather than modify the existing ones, as here. It’s probably safer for modestly-sized tables…
Dear Betty, it’s an interesting question. I am not sure if more elegant or straightforward solutions exist, but I sometimes resort to using basically Mathematica code in Wolfram|Alpha. My motivations for this is compactness and functional nature of Wolfram Language. Let me give you an example. I will take a 2 by 2 matrix, multiply its 1st row by 2 and then add its 2nd row to its 1st. In Mathematica we can do it as:
(#*{2, 1} + {#[[2]], 0}) &@{{1, 2}, {3, 4}}
so
{{1, 2}, {3, 4}}
became
{{5, 8}, {3, 4}}
The same code will work in Wolfram|Alpha:
Thanks for the ideas. I have my linear algebra students use C ormullion’s approach in Mathematica. But not all of them have laptops to bring to class, so I was hoping to do something similar in Wolfram Alpha during class time. Sam’s approach is a bit too advanced for my students who may have no programming experience, particularly Mathematica programming. I suppose I could teach that, but would rather not add complexity.
I would be ok with just using the RowReduce command, which works in Alpha, except that it reduces too far (treats parameters as non-zero constants) for some of my problems. For example, I sometimes ask my students to find all values of certain parameters for which a system of equations is consistent. RowReduce doesn’t work for this as this snippet shows:
RowReduce[{{1, 2, a}, {2, 4, b}}]
gives me
{{1,2,0},{0,0,1}}
What I want is
{{1,2,a},{0,0,-2a+b}}
so that students can see that the system is consistent when -2a+b=0.
My apologies, I thought your question said “Wolfram Language”, not “Wolfram Alpha”, hence my irrelevant answer…
Also I’m starting to see “Wolfram Language” on Wolfram Sites where I once would have expected to see “Mathematica”. It’s going to be an interesting year.
probably you noticed, but W|A will show you the row operations “step-by-step” if you ask to row reduce a matrix
Peter - I actually had not thought about looking at the steps! Thanks for pointing that out. Doesn’t really help me since my students don’t have pro accounts and I want them to do the steps themselves. But perhaps useful for them for the two freebies/day. Thanks again.
C ormullion - no problem! I think getting used to using “Wolfram Language” where appropriate, instead of Mathematica will take a lot of getting used to for a lot of people!
For the purpose of getting a consistency requirement, one can augment the matrix on the right with an identity matrix. Here is your example.
RowReduce[{{1, 2, a, 1, 0}, {2, 4, b, 0, 1}}]
Out[10]= {{1, 2, 0, -(b/(2 a - b)), -(a/(-2 a + b))}, {0, 0, 1, 2/(
2 a - b), 1/(-2 a + b)}}
In effect the last columns give the requirement that, for the indicated pivots to be correct, 2a-b not be equal to zero.
Explaining this to students first encountering the subject might be another matter though.
Another possibility, which might or might not work reliably, is to use LUDecomposition.
LUDecomposition[{{1, 2, a}, {2, 4, b}}]
During evaluation of In[12]:= LUDecomposition::sing: Matrix {{1,2,a},{2,0,-2 a+b}} is singular. >>
Out[12]= {{{1, 2, a}, {2, 0, -2 a + b}}, {1, 2}, 1}
Thanks, Daniel. The LU decomposition is definitely way beyond my students. These are students who are just starting out in linear algebra. Even augmenting with an identity matrix is more than I want to get into in the beginning. Thanks for the ideas though.
Here is the examples page on Wolfram|Alpha that lists some matrices operations. Hope that helps!
-Adriana
How would you do the same operation but multiply the first row by -3 then add the first row to the second row instead.
