What programming challenges would you pose to new users?
Show older comments
What projects would you give to take a person from no MATLAB knowledge to a greatly improve their MATLAB knowledge?
I am looking for challenges that would take a well versed MATLAB user about 30 minutes to program or less, but would expose a new MATLAB user to many new concepts.
Ideally, I will take several of these problems and turn them into videos.
See my answer below for a typical challenge.
Answers (8)
Doug Hull
on 15 Feb 2011
2 votes
Kenneth Eaton
on 15 Feb 2011
2 votes
Designing simple GUIs can introduce newer users to a number of important concepts. For example...
Challenge:
Create a stopwatch GUI with a display for the elapsed time and a single push button to start and stop the counter.
Restrictions:
- You can't use global variables.
- You can't use GUIDE.
- All the code must be in a single m-file.
- The program must not modify or depend on variables in the command workspace.
Concepts covered:
- The nuts and bolts of designing GUIs and working with uicontrols
- Callback functions
- Nested functions
- Working with timers
Admittedly, this isn't the sort of challenge I would ask of a completely green MATLAB user, more like someone who is a couple weeks or months into learning it and has a good deal of the basics down.
1 Comment
Doug Hull
on 15 Feb 2011
John D'Errico
on 15 Feb 2011
2 votes
I would give a challenge of (accurately) computing the function sine(x), for given scalar values of x using the standard Taylor series approximation. This drives them to learn the use of loops, tests for convergence. It also teaches them about floating point numbers in MATLAB, and a bit about interval reduction methods to make the series converge rapidly enough.
1 Comment
Doug Hull
on 15 Feb 2011
Matt Tearle
on 15 Feb 2011
1 vote
Several of the problems at Project Euler have made me think about new ways of doing things in MATLAB (e.g. writing my own long integer class to do things like adding 50-digit numbers).
1 Comment
John D'Errico
on 15 Feb 2011
I would add that PE was one of the incentives for writing my vpi class.
John D'Errico
on 15 Feb 2011
1 vote
How about the "game" of life? This is easily enough written in MATLAB using loops. But writing the updates in a vectorized form can teach the student about techniques for vectorization - an important skill in MATLAB.
3 Comments
Kenneth Eaton
on 15 Feb 2011
The Game of Life is always fun. For added fun you could even see who can "golf" the update algorithm the best. Here's my shortest for a "dead" boundary condition where M is a logical life matrix: lifeFcn = @(M) ~fix(filter2(ones(3),M)-M/2-3);
Sean de Wolski
on 15 Feb 2011
Ken, what about conv2? to save 2 letters
Kenneth Eaton
on 16 Feb 2011
@Sean: It actually ends up being a couple of characters longer. CONV2 has a different default 'shape' option than FILTER2, so you would have to add an additional argument 'same' (or perhaps just 's') to get just the central part of the convolution so M stays the same size on each iteration.
John D'Errico
on 15 Feb 2011
1 vote
MATLAB is a matrix laboratory. But many new users don't appreciate the capabilities of linear algebra in MATLAB. So as a way to teach them something about matrices, getting them to visualize how to set up a matrix for such a problem, I would show how to write a convolution in the form of a matrix multiply. You can build that convolution matrix in several ways. First, I might use a loop. More fun is to use toeplitz. Finally, you can teach about sparse matrices using this teaching tool, creating the matrix using spdiags. This teaches the student that sparse matrices can indeed yield significant speed improvements.
A nice thing is that some students who come to MATLAB from a signal processing background will find this example interesting, since they will understand the concept of a convolution.
Walter Roberson
on 15 Feb 2011
0 votes
Movement planning. A common assignment in robotics these days, that can help teach fundamental graph algorithms such as shortest-path.
John D'Errico
on 15 Feb 2011
0 votes
There are many useful programming capabilities in matlab. One of them is recursion. A problem is that perhaps the most common problem that is taught as a recursion is perhaps one of the worst - the Fibonacci sequence. If this sequence is generated using the brute force recursion, it takes massive amounts of computation to generate even a relatively small Fibonacci number.
However, there are also many very nice problems that can be solved using recursion. For example, computing all of the partitions of an integer is one such nice problem. It can be introduced nicely as the "making change" problem, thus list all distinct ways that one can make change for a $2.00 bill, using only "coins" in denominations of {1, 5, 10, 25, 50, 100}.
Categories
Find more on Conway's Game of Life in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!