Math 414 - Spring 2004

Questions & Answers

  1. Question (3/15/04). Can I use Maple to do the plots?

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

    Matlab will plot the function, selecting the t-values itself. Notice the structure of the command. The first part is the function you want to plot in backquotes, '3*t.* sin(t/2)'. This is followed by a comma, and then by the interval [start, finish] - in this case we have [-3*pi,5*pi], but it can be whatever you want.

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



  2. Question (3/19/04). I am in your MATH 414 course and I am wondering if you could answer a MATLAB question for me. Your part_sum_c.m takes two vectors(or arrays, whichever MATLAB prefers to call to them) as its argument along with the linear space and the half-interval. If you are finding a partial sum Sn where n = 3, then it's not a problem to enter the 3-dimensional vectors. However, one of the problems on the homework that I have been diligently finishing asks for S40. Now, it wasn't difficult to calculate these coefficients by hand and put them in a vector for part_sum_c.m, but I was wondering if there is an easier way to figure out these 40 elements. If I, for some strange reason, wanted to find the partial sum S100, would I have to figure out n=100 coefficients by hand, or is there a MATLAB routine that I can use? Thanks for your time.

    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;

    This has the pattern 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;

    To do a hundred coefficients is simple. Here is the code for N=100.
    
    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.



  3. Question (4/2/04). I'm working on the conversion of an image file .jpg to .mat-file. I used imread(filename) (i.e. X=imread('fp0.jpg), and then I save it as a new .mat- file. I'm able to reopen it by imshow(X). However, in the wavelet toolbox, I cannot load the X.mat file. The error message is "no image to load." How do you correct this problem?

    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