Answer. I really want you to learn Matlab. There are several reasons. It's the program engineers use in their work. Now, I realize that many of you have learned Maple at some point. The reason that you should learn Matlab in this course is that it is vastly superior when it comes to wavelets, importing images, and doing a laundry list of other things that Maple is simply inadequate for. I know many of you have had lots of trouble with the program, and I'm going to try to give you several exercises that I hope will get you started.
Let's plot 3t sin(t/2) over the interval t= -3*pi to 5*pi.
We first create a row vector t
to hold the t-values you
want to plot. I like linspace
, but I'll show you a second
method later. By the way, the percent sign (%) in Matlab is a
comment. Matlab will ignore it, so you can copy it into your commands
or simply ignore it, as you please. Next, we will create a vector y to
hold the y-values corresponding to each t-value. Finally, we will plot
the function.
%Create 3000 equally spaced t-values, from -3*pi to 5*pi. t=linspace(-3*pi, 5*pi,3000); %Create 3000 y-values corresponding to the t-values. y=3*t.* sin(t/2); %Note .* - it means entry by entry multiplication. %Plot y vs. t. plot(t,y)There is another way to get the vector with t's. If you want to focus on spacing rather than on the number of points - say you want them spaced 0.01 apart, then the way to do it is to use the start:increment:end method.
t=(-3*pi):0.01:5*pi;
y=3*t.* sin(t/2);
plot(t,y)
There are some quick methods of plotting. For example, if you don't
care about how many points you're plotting and just want to see the
function, then you can use fplot
. To plot the function
3*t.* sin(t/2) all that you have to do is execute this command:
fplot('3*t.* sin(t/2)',[-3*pi,5*pi])
Here is a second example with fplot. Suppose we want to plot e-x/2 sin(4x) for x=0 to x=10. You first need to know that in Matlab, as in Maple, ex is exp(x). After that, it's easy.
fplot('exp(-x/2).*sin(4*x)',[0,10])
Answer. Sure. There's a much easier way. I don't remember the specifics of the problem, but a typical partial sum has coefficients that look like the ones derived in example 1.29, p. 70. The series there is a sine series, so all a's are 0. The bn's are given by
bn = 2(-1)n+1/n.
How do we make a vector in Matlab containing these coefficients? The first thing is to create a vector holding the index n.To do this, we initialize an integer N that tells us how far we want to go. For 40 coefficients, start with
N=40;
Next, we create a vector n=[1,2,...,N]. This is easy using Matlab's colon (:) operator:
n=1:1:N;
start:increment:end
. You could use
linspace here, but it's harder and nobody would do it that way. (OK,
linspace(1,N,N) is how you would do it.) Also, 1 is such a common
increment that Matlab allows you to leave it out. Hence, n=1:N works
too. Now, we want create the vector b.
b=2*(-1).^(n+1)./n;
N=100;
n=1:N;
b=2*(-1).^(n+1)./n;
This gives the coefficient vector, and we get it without loops or
messy codes. All very simple. The only thing that you have to remember
is to use .^ and ./ in the power and division operations. Without
them, these are matrix operations.
Answer. There are two types of images needing conversion into forms that can be read by the wavelet toolbox in MATLAB. The best and clearest explanation is in the documentation that comes with MATLAB. Click on HELP, and then do a search for the phrase "Image Conversion". From there, it should be clear. If not, send me another message. - FJN