matlab: ndgrid function

Just noticed in MATLAB google groups, in this thread. There is a function preventing us to write nested loops i.e ndgrid.

Here the original code :

for habs=0:.25:1
for pabs=0:.2:1
for beta=0:pi/2:2*pi
for alpha=0:pi/5:2*pi

H=habs*(cos(beta)+i*sin(beta));
p=pabs*(cos(alpha)+i*sin(alpha));
W=abs(H)^2*abs(p)*(2*exp(i*(alpha-beta))+ exp(-i*(alpha-  beta)))*exp(i*beta);
plot(real(W+H),imag(W+H),’o’,’MarkerSize’,4)
hold on

end
end
end
end

With ndgrid function, the code becomes :

[habs,pabs,beta,alpha]=ndgrid(0:.25:1,0:.2:1, 0:pi/2:2*pi,0:pi/5:2*pi);
H=habs.*(cos(beta)+i*sin(beta));
p=pabs.*(cos(alpha)+i*sin(alpha));
W=abs(H).^2.*abs(p).*(2*exp(i*(alpha-beta))+ exp(-i*(alpha-beta))).*exp(i*beta);

W=W(:);
H=H(:);
plot(real(W+H),imag(W+H),’o’,’MarkerSize’,4)

Further, you may check the run time. Which one faster ?

Rudin’s book

Currently, i’m reading one of Rudin’s analysis book i.e Principles of Mathematical Analysis. I feel a bit easier to peruse the book since I got a course on introduction of mathematical analysis last semester at mathematics dept. It was Linear Methods – TMA4145. I regret that I just read the book right now, why don’t I read it last year ? In spite, I bought second book of Rudin : Real and Complex Analysis last year. I noticed in the second book’s preface mentioning the first book. I managed to find the first book at university central library and it is an excellent book !

And today, I have seen positive comment about the book. To bear it on my mind, allow me to copy here.. :

Principles of Mathematical Analysis by Walter Rudin can rightly be called “the Bible of classical analysis”. I have seen it cited in more books than I can count. And after a full year of working through the book in graduate school, I can see why. As many other reviewers here have pointed out, this book requires more than a little of that magical quality called “mathematical maturity”. Simply defined, “mathematical maturity” is the ability to read between the lines and fill in the gaps in a given mathematical text.

While Rudin certainly provides an encyclopedic account of basic analysis in metric spaces, he does leave some gaps (many are intentional) in his proofs. So be alert when you read this book, and if anything in his super short, slick proofs is not 100% clear, be prepared to fill in the details yourself. Also, remember that Rudin’s way of presenting proofs is not always the most instructive when first learning the material. There is an implicit challenge to the reader to see if he or she can provide a more expository proof. Although I can say that when the classical proof suffices, Rudin usually does not deviate from it.

Some of the highlights/weaknesses of the book are the following:

Chapter 1: The material in this chapter is of course standard. However, Rudin supplements the chapter with an appendix on the construction of the real field from the field of rationals via the notion of Dedekind cuts. After reading many, many analysis books, I can tell you that it is difficult to find an explicit construction of the reals in books on an elementary level. Thus, while certainly not required to appreciate the rest of the text, I do recommend at least a casual perusal of the appendix just to see that “it can be done”.

Chapter 2: Rudin may seem to go a little overboard in his presentation on basic topology, but trust me, it will *all* be used later. So do not gloss over anything in this chapter. In particular, note how the notion of compactness is not defined a priori by any metric space ideas. However, in metric spaces, compactness does imply certain useful properties. One that is used again and again is the equivalence of compactness and sequential compactness in metric spaces. Thus, after moving on to Chapter 3 and beyond, I advise you to look back at Chapter 2 often.

Chapter 3: One notable feature is that Rudin does not attempt to discuss limits per se before discussing numerical sequences and series. This may make you a little uncomfortable at first, but it turns out that this approach works best. Again, everything in this chapter is essential to the rest of the book. My only gripe with this chapter is the material on “upper and lower limits”, better known as lim sup and lim inf. I feel that he should have expanded the discussion in this section a little more. In particular, his Theorem 3.19 should have had a proof supplied in the text. One of the reasons I feel this way is because the Root and Ratio tests for convergence of infinite series of numbers use lim sup heavily.

Chapter 4: Limits are finally introduced as the reader remembers them from basic calculus. The only difference is that Rudin works with arbitrary metric spaces, which turns out to be very useful later. Take note of Theorem 4.2. Reformulating the existence of a limit of a function in terms of limits of sequences is a handy theoretical tool that makes a lot of proofs (Rudin’s included) much easier to understand. That said, there are no real surprises until Theorem 4.8. You can probably omit the subsection “Discontinuities” with no loss. I say this even though some of the theorems in “Monotonic Functions” use that material in their proofs. Theorem 4.30 in particular (monotone functions on open intervals have at most a countable number of discontinuities) has a much better proof than that Rudin provides. So try and look elsewhere for the proofs of those theorems.

Chapter 5: All the derivative proofs are just like you remember from advanced calculus. The only one that merits special attention is L’Hospital’s Rule. Work through it very carefully, it is more subtle than it appears.

Chapter 6: The Riemann-Stieltjes integral can be obtained by only slightly more effort, so Rudin wisely decides to base all of his proofs (through Theorem 6.19) on it. Just be aware that some of the material covered, such as the Fundamental Theorem of Calculus and integration by parts is only discussed for the original Riemann integral. Theorem 6.25 (based on the Cauchy-Schwarz inequality) acquires a special significance in the following chapters, so memorize it!

Chapter 7: By far, this is the most crucial chapter in the book. This is probably the material that you may have had limited or no exposure to in the past. The famous Weierstrass Approximation Theorem (and its generalization by Marshall Stone) is given here. Read this chapter front to back at least four times. Yes, it is that important. Otherwise, the Fourier Theory presented in Chapter 8 will seem like gibberish.

Chapter 8: Expansion of analytic functions via power series is presented here. A brisk, but complete development of the exponential, sine and cosine functions is also featured here. Problem 6 in the exercises at the end of the chapter is worth special consideration. Work it out after you read about the exponential function. The Fourier material is relatively straightforward, although awkward when divorced from measure theory. As Rudin himself notes, the hypothesis that f be Riemann integrable is often unnecessary, so you may want to peek ahead at Chapter 11 while reading many of the proofs, especially Parseval’s Theorem. The material on the gamma function is cute, but not really needed.

Chapter 9: The standard treatment of multivariable functions. Rudin’s coverage of linear algebra is succinct. Also, the linear algebra has more important uses than merely providing a pathway to “multivariable calculus”. The theory of linear operators sketched in Theorems 9.5 to 9.8 will lead you directly to the more abstract theory of Banach spaces. The Banach spaces take a very central role in advanced analysis as can be seen by reading Royden’s “Real Analysis”. I also recommend supplementary reading for this chapter. A good book to look at is Charles Pugh’s “Real Mathematical Analysis” which has an extensive treatment of multivariable functions. Also, you might skim over George Simmon’s “Introduction to Topology and Modern Analysis”, a great introduction to the abstract theory of operators. This material is only hinted at in Rudin, but comes to its full fruition in Simmons.

Chapter 10: This is Rudin’s introduction to differential geometry. I honestly have not given this chapter a thorough reading, but on the surface it looks ok. Most of the deeper theorems from multivariable calculus (excepting the Implicit Function Theorem, discussed in Chapter 9) are treated here, such as the trifecta known as Stoke’s, Green’s, and the Divergence Theorems, respectively. This chapter is important to anyone going into fields such as partial differential equations.

Chapter 11: This chapter seems to be the one that most people criticize in the book. Rudin gives a perfunctory outline of Lebesgue theory that seems to rob the reader of much needed detail. Indeed, this chapter is a little too lean for my tastes. But in Rudin’s defense, he warns the reader at the outset that “proofs are only sketched in some cases, and some of the easier propositions are stated without proof”. Hence, I recommend just giving this chapter a light read, then go to another book (such as Royden) for the real proofs. As expected, Rudin discusses some of the seminal results of Lebesgue theory, including, but not limited to: the Monotone Convergence Theorem, the Dominated Convergence Theorem, and the correspondence of the Lebesgue integral with the ordinary Riemann integral (whenever the latter exists). The Riesz-Fischer Theorem from Fourier analysis appears here. Lebesgue’s Dominated Convergence Theorem (Theorem 11.32) is worth a careful reading. Afterwards, look at Exercise 12 in Chapter 7 for a simpler version of the DCT using the familiar Riemann integral. The proof is not that difficult.

It goes without saying that the exercises are extremely important and should all be attempted. Unless you are brilliant, odds are that at least a few will elude you. Nonetheless, many important results and counterexamples are listed in the exercises, so you will benefit from working them. Be warned though that Rudin will intermingle easy with very difficult problems.

An obvious problem is the outrageous price. Unfortunately, this book is essential reading, so you’ll just have to cough up the dough or look for it cheap elsewhere. It is a good book to learn from and a fantastic reference. I don’t know if I would call it the “best analysis book ever”. But its current edition was released 30 years ago, so that says something about its popularity.

P.S. Once you’ve finished Rudin, the book by Pugh referenced above is a good read to “pull it all together”. There are some well-thought out problems that will both challenge and inspire you to learn more at the same time.

Highly recommended.