Cleve’s Corner: Cleve Moler on Mathematics and Computing https://blogs.mathworks.com/cleve Cleve Moler is the author of the first MATLAB, one of the founders of MathWorks, and is currently Chief Mathematician at the company. He writes here about MATLAB, scientific computing and interesting mathematics. Fri, 15 Mar 2024 18:05:58 +0000 en-US hourly 1 https://wordpress.org/?v=6.2.2 Twenty Years of Parallel MATLAB https://blogs.mathworks.com/cleve/2024/03/15/twenty-years-of-parallel-matlab/?s_tid=feedtopost https://blogs.mathworks.com/cleve/2024/03/15/twenty-years-of-parallel-matlab/#respond Fri, 15 Mar 2024 18:05:58 +0000 https://blogs.mathworks.com/cleve/?p=11077

I have just returned from the MathWorks company meeting celebrating our 40th Anniversary. In one of the presentations, Jos Martin described how Parallel MATLAB was introduced almost twenty years ago. Here are a few slides from Jos's talk.... read more >>

]]>

I have just returned from the MathWorks company meeting celebrating our 40th Anniversary. In one of the presentations, Jos Martin described how Parallel MATLAB was introduced almost twenty years ago. Here are a few slides from Jos's talk.

Contents

Why There Wasn't Any Parallel MATLAB

In MATLAB News and Notes for spring 1995, I wrote a one-page Cleve's Corner titled "Why there isn't any parallel MATLAB." There were three reasons.

  • Memory model. MATLAB would generate a matrix on a host machine, split it into roughly equally sized submatrices, and distribute each submatrix to a node. But it took far longer to distribute the data then it did to do the computation. Any matrix that would fit into memory on the host was too small to make effective use of the parallel computer itself.
  • Granularity. The amount of work involved in a single matrix computation is too little to be effectively parallelized.
  • Business situation. There are too few potential customers at this time (1995) to undertake fundamental changes in MATLAB's architecture.

This one-page note turned out to be one of my most widely cited publications.

.

.

Twenty-seven Parallel MATLABs

A 2001 survey by Ron Choy at MIT found 27 different projects that were developing some way to run MATLAB in parallel. All of them involved a MATLAB-based host program calling a fixed library of parallel functions, written in some other language, on the workers. None of the systems were capable of running arbitrary MATLAB programs in parallel. None of them were MathWorks products.

Distributed Computing Toolbox

MathWorks introduced the MATLAB Distributed Computing Toolbox in November 2004. We improvised this demo setup at our first Supercomputing Conference, SC2004 in Pittsburg,

.

Supercomputing Conference

A year later, SC2005 was in Seattle and our booth featured four worker machines on a wire shelving unit purchased at a local Home Depot.

.

Bill Gates

Since Seattle was his home town, Bill Gates gave the keynote talk at SC2005. He announced that Microsoft was going into High Performance Computing and used the MathWorks Distributed Computing Toolbox in his demonstration.

.

Now There is a Parallel MATLAB

So, a little more than ten years after the first Cleve's Corner about parallel computing, a second Cleve's Corner in News and Notes was able to reverse the situation.

.


Get the MATLAB code

Published with MATLAB® R2023a

]]>
https://blogs.mathworks.com/cleve/2024/03/15/twenty-years-of-parallel-matlab/feed/ 0
Chaotic Swinging Sticks https://blogs.mathworks.com/cleve/2024/02/20/chaotic-swinging-sticks/?s_tid=feedtopost https://blogs.mathworks.com/cleve/2024/02/20/chaotic-swinging-sticks/#comments Tue, 20 Feb 2024 16:24:41 +0000 https://blogs.mathworks.com/cleve/?p=11022

The Swinging Sticks is a kinetic sculpture that exhibits chaotic motion. The device became very popular after it upstaged Tony Stark in Iron Man 2. My daughter Carolyn gave me a desktop version of Swinging Sticks for Christmas. I immediately set out to simulate it.... read more >>

]]>

The Swinging Sticks is a kinetic sculpture that exhibits chaotic motion. The device became very popular after it upstaged Tony Stark in Iron Man 2. My daughter Carolyn gave me a desktop version of Swinging Sticks for Christmas. I immediately set out to simulate it.

Contents

Chaotic Motion

Chaotic motion appears random but isn't. Once the motion begins, the initial conditions together with Newton's law of motion, F = ma, determine subsequent behavior. There are no random forces. It may be difficult to predict positions, but they are well-determined, nonetheless.

A classic example of chaotic motion is the double pendulum. One mass at end of a massless string swings about a fixed pivot, and a second mass is attached by a massless string to the first. My simulator of the classic double pendulum is available in Cleve's Lab, swinger, and a movie is available here pendulum movie.

Swinging Sticks

The swinging sticks are similar to the double pendulum. The sticks are two rods with uniformly distributed mass, different lengths and off-center pivots. The best way to view the motion is to download this code and run it in your own MATLAB. Otherwise, here in a short slow-motion animated GIF.

And, here is a longer Swinging Sticks Video.

The motion of the shorter of the two rods is chaotic. Here are the orbits traced by the ends of the short rod.

Sculpture

Swinging Sticks sculptures are available in various sizes and colors. The Swinging Sticks.

Our mathematical model is of a frictionless perpetual motion machine. The real sculptures have an ingenious electromagnetic controller in the base that is claimed to run for two years on four AA batteries. Mine has been running since Christmas. An excellent YouTube video by Wayne Schmidt describes the controller.

Code

https://blogs.mathworks.com/cleve/files/swinging_sticks.m


Get the MATLAB code

Published with MATLAB® R2024a

]]>
https://blogs.mathworks.com/cleve/2024/02/20/chaotic-swinging-sticks/feed/ 2
Nick Higham (1961-2024) https://blogs.mathworks.com/cleve/2024/01/25/nick-higham-1961-2024/?s_tid=feedtopost https://blogs.mathworks.com/cleve/2024/01/25/nick-higham-1961-2024/#comments Thu, 25 Jan 2024 16:36:37 +0000 https://blogs.mathworks.com/cleve/?p=10982

Nick Higham passed away last Saturday. Nick was a close friend of mine and a great friend of MATLAB. I will leave it to others to describe his research and teaching, his many honors, and his service to our community, especially SIAM. I have just a few, more personal, comments.... read more >>

]]>

Nick Higham passed away last Saturday. Nick was a close friend of mine and a great friend of MATLAB. I will leave it to others to describe his research and teaching, his many honors, and his service to our community, especially SIAM. I have just a few, more personal, comments.

Contents

NA Digest

Monday's NA Digest led off with this from Nick's wife Francoise and his brother Des.

Subject: Nick Higham (1961--2024)
With great sadness we report that Nick Higham, Royal Society Research
Professor and Richardson Professor of Applied Mathematics at the
University of Manchester, passed away on January 20, 2024, at the age
of 62 after an 18 month struggle with a form of blood cancer. An
obituary describing Nick's research and leadership contributions will
appear in SIAM News in due course.
Francoise Tisseur and Des Higham

Books

Nick was an excellent writer, and an excellent writer about writing.

Here are the covers of his six books.

SIAM published five of these. Two are surveys of Nick's research on the accuracy of numeric algorithms and the computation of matrix functions. Two more, one of them coauthored with Dennis Sherwood, are guides to mathematical exposition.

MATLAB Guide, by Des and Nick Higham, is one of my favorite books about MATLAB. It is a succinct introduction for newcomers and a valuable refresher for old-timers. The third edition, published in 2017, includes chapters on object-oriented computing, parallel computing, the Symbolic Math Toolbox and other recent additions. Be sure to check out the MATLAB Guide web site.

The only non-SIAM book pictured above is The Princeton Companion to Applied Mathematics. It is over 1,000 pages long and features nearly 200 sections written by an international team of experts. Nick is the editor-in-chief and wrote many of the sections himself.

MATLAB

Here is a Word Cloud from Nick's home page. It shows the frequency of the tags for his blog and confirms his interest in MATLAB.

gallery

Anyone interested in numerical linear algebra should also be interested in the gallery function, which is based on Nick's work. Enter

>> doc gallery

Scroll down to matrixname and investigate over 70 different test matrices.

If you find gallery irresistible, take a look at anymatrix, an extensible matrix collection, by Nick and Mantas Mikaitis.

expm

This is very personal for me. Thirty or forty years ago, Charlie Van Loan and I were regarded as authorities on computing the matrix exponential, $e^{A}$. The function expm has been in MATLAB since its very beginning. Around twenty years ago, we ceded the authority title to Nick and Awad Al-Mohy. Their code for matrix exponential is now the basis for expm.

Goodbye

Our business has lost one of its superstars. I have lost a good friend, way too soon. Goodbye Nick.


Get the MATLAB code

Published with MATLAB® R2023a

]]>
https://blogs.mathworks.com/cleve/2024/01/25/nick-higham-1961-2024/feed/ 1
Exponential Fitting, Separable Least Squares, and Quahogs https://blogs.mathworks.com/cleve/2024/01/12/exponential-fitting-separable-least-squares-and-quahogs/?s_tid=feedtopost https://blogs.mathworks.com/cleve/2024/01/12/exponential-fitting-separable-least-squares-and-quahogs/#comments Fri, 12 Jan 2024 16:35:32 +0000 https://blogs.mathworks.com/cleve/?p=10964

We have been investigating a recent bug report about fitnlm, the Statistics and Machine Learning Toolbox function for robust fitting of nonlinear models.... read more >>

]]>

We have been investigating a recent bug report about fitnlm, the Statistics and Machine Learning Toolbox function for robust fitting of nonlinear models.

Contents

Quahogs

The bug report comes from Greg Pelletier, an independent research scientist and biogeochemical modeler in Olympia, Washington. Greg has been studying the vulnerability of sensitive marine organisms to increases in ocean acidification. One of the most important of these organisms is Mercenaria mercenaria, the hard clam.

Especially here in New England, hard clams are known by their traditional Native American name, quahog. They have a well-deserved reputation for making excellent clam chowder.

Acidification

We are all aware of increasing levels of carbon dioxide in the earth's atmosphere. We may not be as aware of the effect this increase has on the health of the earth's oceans. According to NOAA, the ocean absorbs about 30% of the atmospheric carbon dioxide.

A definitive and controversial 2009 paper by Justin Ries and colleagues, then at the Woods Hole Oceanographic Institution, is "Marine calcifiers exhibit mixed responses to CO2-induced ocean acidification", https://doi.org/10.1130/G30210A.1. The hard clam example in Greg's bug report comes from figure 1K in the Ries et al. paper.

The independent variable in experiments is the ratio of alkalinity of sea water to the concentration of dissolved inorganic carbon. The dependent variable is the calcification rate, which compares how fast the organism builds its shells to how fast the shells are dissolving.

Separable Least Squares

The model chosen by Ries at al. is

$$ y \approx \beta_1 + \beta_2 e^{\lambda t} $$

where $t$ is the ratio of alkalinity to dissolved carbon and $y$ is the calcification rate. The data have only four distinct values of $t$, with several observations of $y$ at each value.

The parameters $\beta_1$, $\beta_2$ and $\lambda$ are determined by least squares curve fit. This is a separable least squares problem. For any given value of $\lambda$, the parameters $\beta_1$ and $\beta_2$ occur linearly and the least squares solution can be obtained by MATLAB's backslash.

Gene Golub and Victor Pereyra described separable least squares in 1973 and proposed solving it by a variable projection algorithm. Since 1973 a number of people, including Pereyra, Linda Kaufman, Fred Krogh, John Bolstadt and David Gay, have contributed to the development of a series of Fortran programs named varpro. In 2011, Dianne O'Leary and Burt Rust created a MATLAB version of varpro. Their report, https://www.cs.umd.edu/~oleary/software/varpro/, is a good background source, as well as documentation for varpro.m.

I have a section on separable least squares, and an example, expfitdemo, in NCM, Numerical Computing with MATLAB. I have modified expfitdemo to work on Greg's quahogs problem.

Centering Data

It turns out that the problem Greg encountered can be traced to the fact that the data are not centered. The given values of $t$ are all positive. This causes fitnlm to print a warning message and attempt to rectify the situation by changing the degrees of freedom from 22 to 23, but this only makes the situation worse. (We should take another look at the portion of fitnlm that adjusts the degrees of freedom.)

It is always a good idea in curve fitting to center the data with something like

  t = t - mean(t)

The values of $y$ are already pretty well centered. Rescaling $y$ with

  y = 10000*y

makes interpretation of results easier.

Exponential Fitting

With the data centered and scaled, we have three different ways of tackling Greg's problem. All three methods agree on the results they compute.

  • fitnlm. Treats all parameters as if they were nonlinear. Computes statistical quantities such as R-squared and RMS Error.
  • varpro. Venerable software history. Only one nonlinear parameter for the quahogs problem. Delivers additional statistical quantities in Regression structure.
  • quahogsfit. Textbook separable least squares code. Modification for the quahogs problem of expfitdemo from NCM. Only one nonlinear parameter. No statistics.

Results

  • fitnlm
Nonlinear regression model:
    y ~ param1 + param2*exp(param3*xval)
Estimated Coefficients:
              Estimate      SE        tStat       pValue
              ________    _______    _______    __________
    param1     0.69536     0.1657     4.1964    0.00037344
    param2    -0.26482    0.19909    -1.3302       0.19709
    param3     -22.218     8.1494    -2.7263      0.012327
Number of observations: 25, Error degrees of freedom: 22
Root Mean Squared Error: 0.307
R-Squared: 0.828,  Adjusted R-Squared 0.813
F-statistic vs. constant model: 53, p-value = 3.86e-09
  • varpro
Linear Parameters:
  0.695367   -0.264837
Nonlinear Parameters:
 -22.217495
Norm         of weighted residual  =   1.438935
Norm         of data vector        =   3.545820
Expected error of observations     =   0.306782
Coefficient of determination       =   0.828145
Regression.t_ratio
    4.1962
   -1.3301
   -2.7264
Regression.std_param
    0.1657
    0.1991
    8.1490
  • quahogsfit
lambda =
  -22.2180
condX =
    4.3882
beta =
    0.6954
   -0.2648
normres =
    1.4389

quahogsfit produces this plot, which can be compared with figure 1K from Ries et al, reproduced above.

Software

The codes for this post are available here quahogs_driver.m and here varpro.m.

Thanks

Thanks to Greg Pelletier for the bug report and to Tom Lane for his statistical expertise.


Get the MATLAB code

Published with MATLAB® R2023a

]]>
https://blogs.mathworks.com/cleve/2024/01/12/exponential-fitting-separable-least-squares-and-quahogs/feed/ 1
Season’s Greetings https://blogs.mathworks.com/cleve/2023/12/20/seasons-greetings-2/?s_tid=feedtopost https://blogs.mathworks.com/cleve/2023/12/20/seasons-greetings-2/#comments Wed, 20 Dec 2023 14:13:20 +0000 https://blogs.mathworks.com/cleve/?p=10936

Season's Greeings Get the MATLAB code (requires JavaScript) Published with MATLAB®... read more >>

]]>

Season's Greeings


Get the MATLAB code

Published with MATLAB® R2023a

]]>
https://blogs.mathworks.com/cleve/2023/12/20/seasons-greetings-2/feed/ 1
Blog Post Number 300, Vibrating Logo https://blogs.mathworks.com/cleve/2023/12/13/blog-post-number-300-vibrating-logo/?s_tid=feedtopost Wed, 13 Dec 2023 18:23:26 +0000 https://blogs.mathworks.com/cleve/?p=10855

This is post number 300 of Cleve's Corner blog. The first post was on June 6, 2012, which is 600 weeks ago. So, I have averaged one post every two weeks for over a decade. The posts were more frequent in the early days and are less frequent today.... read more >>

]]>

This is post number 300 of Cleve's Corner blog. The first post was on June 6, 2012, which is 600 weeks ago. So, I have averaged one post every two weeks for over a decade. The posts were more frequent in the early days and are less frequent today.

Contents

Vibrating Logo

For my 300-th post, I want to take another look at our MathWorks logo. Here is a modified version of one of the animations that I entered in the recent MATLAB Flipbook Mini Hack.

       Vibrating Logo

The MathWorks company logo is the solution to a partial differential equation that describes how a disturbance travels through matter. I discussed the logo in a five-part blog post in 2014. Here are links to three of those posts.

Why is it L-shaped?.

The method of particular solutions.

How the view has evolved..

One of my most-liked blog posts is by ten-year old Eden Rajapakse.

Code

This code is available at vibrating_L.

vibrating_L

function vibrating_L
    % MathWorks logo, vibrating L-shaped membrane. See Cleve's Corner, Dec.13, 2023.
    % https://blogs.mathworks.com/cleve/2023/12/13/blog-post-nuber-300-vibrating-logo.

    stop = init_fig;
    fps = 6;
    f = 0;
    % Loop until stop is toggled.
    while stop.Value == 0
        f = f + 1;
        vibrating_logo_frame(f)
        pause(1/fps)
    end

vibrating_logo_frame

    function vibrating_logo_frame(f)
        %
        % One frame of animation.
        if f == 1
            first_frame
        end
        fud = get(gcf,'UserData');
        [mu,L,s] = deal(fud{:});
        t = (f-1)/fps;
        Z = cos(mu(1)*t)*L{1} + sin(mu(2)*t)*L{2} + sin(mu(3)*t)*L{3} +  ...
            sin(mu(4)*t)*L{4} + sin(mu(5)*t)*L{5} + sin(mu(6)*t)*L{6};
        s.ZData = Z;
    end

first frame

    function first_frame
        cla
        axis off

        % First six eigenvalues.
        mu = sqrt([9.6397238445, 15.19725192, 2*pi^2, ...
                   29.5214811, 31.9126360, 41.4745099]);

        % First six eigenfunctions.
        L{1} = 30*membrane(1,25);
        L{2} = 2*membrane(2,25);
        L{3} = -2*membrane(3,25);
        L{4} = 5*membrane(4,25);
        L{5} = -3*membrane(5,25);
        L{6} = 4*membrane(6,25);

        % Surf plot with custom lighting.
        axes('CameraPosition', [-193.4013 -265.1546  220.4819],...
             'CameraTarget',[26 26 10], ...
             'CameraUpVector',[0 0 1], ...
             'CameraViewAngle',9.5, ...
             'DataAspectRatio', [1 1 .9],...
             'Visible','off', ...
             'XLim',[1 51], ...
             'YLim',[1 51], ...
             'ZLim',[-13 40]);
        s = surface(zeros(size(L{1})), ...
             'EdgeColor','none', ...
             'FaceColor',[0.9 0.2 0.2], ...
             'FaceLighting','phong', ...
             'AmbientStrength',0.3, ...
             'DiffuseStrength',0.6, ...
             'Clipping','off',...
             'BackFaceLighting','lit', ...
             'SpecularStrength',1.0, ...
             'SpecularColorReflectance',1, ...
             'SpecularExponent',7);
        light('Position',[40 100 20], ...
             'Style','local', ...
             'Color',[0 0.8 0.8]);
        light('Position',[.5 -1 .4], ...
             'Color',[0.8 0.8 0]);
        set(gcf,'UserData',{mu,L,s})
    end

init_fig

    function stop = init_fig
        % Initialize figure.
        fig = gcf;
        fig.Color = 'k';
        fig.MenuBar = 'none';
        fig.ToolBar = 'none';
        fig.NumberTitle = 'off';
        fig.Clipping = 'off';
        stop = uicontrol;
        stop.Style = 'togglebutton';
        stop.String = 'X';
        stop.FontSize = 12;
        stop.FontWeight = 'bold';
        stop.Units = 'normalized';
        stop.Position = [.92 .92 .06 .06];
        cla
        shg
    end
end


Get the MATLAB code

Published with MATLAB® R2023a

]]>
Bouncing Bucky Ball at Flipbook Mini Hack https://blogs.mathworks.com/cleve/2023/11/16/bouncing-bucky-ball-at-flipbook-mini-hack/?s_tid=feedtopost Thu, 16 Nov 2023 23:01:49 +0000 https://blogs.mathworks.com/cleve/?p=10812

The 2023 MATLAB Central Flipbook Mini Hack contest runs from November 6 until December 3. Over 200 entries have been submitted in the first two weeks.... read more >>

]]>

The 2023 MATLAB Central Flipbook Mini Hack contest runs from November 6 until December 3. Over 200 entries have been submitted in the first two weeks.

Contents

New Rules

This year's mini hack features short animations. The contest software runs the program you submit to make an animated GIF file with exactly 48 frames and an inner-frame delay time of 1/24 second. So, your animation will run for two seconds, then continuously repeat. If you want periodic motion, you need to be back where you started by frame 48.

In previous mini hacks, programs had to be Twitter length -- at most 255 characters long. Now, the new limit is 2,000 characters. Comments and formatting blanks are not counted. Remixes and reuse of other submissions is encouraged.

Participants and other viewers vote on the submissions. There are prizes like Amazon gift cards and T-shirts. MathWorkers may participate, but not win prizes.

Gallery

Take a look at the Gallery.

Personal Favorites

I find the results fascinating. There are so many different creative styles, artistic talents and programming techniques. Here are a few of my personal favorites.

Jenny Bosten

Jenny Bosten is a familiar name on MATLAB Central. She is a Senior Lecturer in Psychology at the University of Sussex, where she is a "visual neuroscientist specialising in colour vision." Her code for Time lapse of Lake view to the West shows she is also a wizard of coordinate systems and color maps.

隆光 中村

I don't know anything about this person. All I see is this name, 隆光 中村, and this ingenious code for Fireworks.

Ned Gulley

Ned is the long-time MathWorker who is the architect of MATLAB Central, and who, this time, is also a prolific participant. One of his more mathematical animations is Orbiting Roots.

Eric Ludham'

Eric is head of the MathWorks development team for Graphics and Charting. Contributions like this Blooming Rose demonstrate his artistic design talent.

Bouncing Bucky Ball

My own contributions are not nearly as attractive as these.

The 2,000 character limit is a good idea. It forced me to look critically at some old code and rewrite it to be simpler and clearer.

This program for a Bouncing Bucky Ball uses the hgtransform object to good effect. I also think it has a nice solution to the problem facing everybody of how to retain state from one frame to the next.

Software

Here is a link to a slightly more complicated version with one togglebutton that provides a random restart capability. Bouncing_Bucky.m

Thanks

Chen Lin, David Wey and Vinay Ramesh are running the Mini Hack this year,


Get the MATLAB code

Published with MATLAB® R2023a

]]>
Exploring Matrices Exercises https://blogs.mathworks.com/cleve/2023/09/25/exploring-matrices-exercises/?s_tid=feedtopost Mon, 25 Sep 2023 17:57:28 +0000 https://blogs.mathworks.com/cleve/?p=10694

Try you hand at a few exercises involving Exploring Matrices.... read more >>

]]>

Try you hand at a few exercises involving Exploring Matrices.

Contents

Qube Simplified

I have simplified the Qube app by removing these four buttons.

  • solve. The <== key now controls the unscrambling operation.
  • scramble. The ==> key now does six random rotations.
  • order. I never found a satisfactory reference for the group theory of Rubik's cube.
  • score. I never found a use for the nuclear norm.

Code for Qube dated 9/24/2023 is included in the Apps mzip archive.

Exploring Matrices Exercises

Here are a few exercises for Exploring Matrices. The answers are available at ExMatAnswers.

Matrix Multiplication

1. Compute by rows, and by columns.

$$ \left( \begin{array}{rrr} 8 & 1 & 6 \\ 3 & 5 & 7 \\ 4 & 9 & 2 \end{array} \right) \left( \begin{array}{r} 1 \\ 1 \\ 1 \end{array} \right) $$

2. Solve for $z$ using inner products of rows, and using linear combinations of columns.

$$ \left( \begin{array}{rrr} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{array} \right) \left( \begin{array}{r} 1 \\ z \\ 1 \end{array} \right) \ = \ \left( \begin{array}{r} 0 \\ 0 \\ 0 \end{array} \right) $$

3. What do the m, n and p buttons on the Multiply app do? What are the other buttons and what do they do?

4. If A is n-by-n and x is n-by-1, how many multiplications are required to compute A x ?

5. If A is m-by-n and B is n-by-p, how many multiplications are required to compute A B ?

Rotations and Scaling

1. What is R(30º)?

$$ R(\theta) \ = \ \left( \begin{array}{rr} \cos{\theta} & \sin{\theta} \\ -\sin{\theta} & \cos{\theta} \end{array} \right) $$

2. Explain https://xkcd.com/184.

3. What is the value of $\theta$ ?

$$ R(\theta) \ = \ \left( \begin{array}{rr} 0.8 & 0.6 \\ -0.6 & 0.8 \end{array} \right) $$

4. What is the value of $\theta$ ?

5. Edit a copy of Rotate.m and replace the house with a hand. You can use my hand or your own hand; see exercise 3.4 in Numerical Computing with MATLAB .

Computer Graphics

1. Show how homogeneous coordinates and matrix-vector multiplication by Tx, Ty or Tz produce translation.

2. What is the range of the rotations used by the pitch, roll, and yaw buttons on the Grafix app?

3. What color in the beacon on top of the plane? How would you change the beacon's color?

4, What is the function of the resolution and offset sliders for the teapot?

5, How many times does the bucky ball bounce off the sides of the plot window?

Matrices and Cubes

1. What is the color of central cubelet in the Color Cube?

2. What do the "<=" , "<==" , "=>" and "==>" buttons on Qube do?

3. What is "God's Number" for a 3-by-3-by-3 Rubik's Cube? What are Q20 and Q26? See Cleve's Corner 2022/09/05.

4. Can you restore the following scrambled cubes with fewer moves than <==, the unscramble key? Use the quarter-turn metric and reset the cube with start or by clicking on stack and Q0. You might also want to set speed to 30 or 45,

  • LRUDFB
  • LRL'R'
  • FLLLRB
  • Q26
  • Reset the random number generator by entering rng(r) for some small integer r in the command window and then generate six random rotations with the ==> key.


Get the MATLAB code

Published with MATLAB® R2023a

]]>
Exploring Matrices https://blogs.mathworks.com/cleve/2023/09/11/exploring-matrices/?s_tid=feedtopost Tue, 12 Sep 2023 03:11:52 +0000 https://blogs.mathworks.com/cleve/?p=10526

I have spent much of my career working to bring abstract linear algebra and practical matrix computation closer together. This project is my latest effort.... read more >>

]]>

I have spent much of my career working to bring abstract linear algebra and practical matrix computation closer together. This project is my latest effort.

Contents

Alibi

Over sixty years ago, as a sophomore contemplating a major in mathematics, I took a course entitled Survey of Modern Algebra. We used a now-classic textbook by MacLane and Birkhoff that featured abstract theorems about groups, rings, fields, vector spaces and linear algebra. I remember the colorful terms alias and alibi had something to do with change of basis and change of position, but I have never seen those terms again.

The next year, I took Numerical Analysis. We did some of the homework on a Burroughs 205 Datatron and I wrote a machine language program to solve simultaneous linear equations. I was hooked.

But at the time I did not realize that the two courses were about the same magnificent object -- the matrix.

Exploring Matrices

Exploring Matrices is a multi-media project that shows matrices in action. Short videos, blog posts, interactive MATLAB software and self-study exercises investigate applications of matrices. The material is intended for students in an undergraduate course in linear algebra or computational science. However, anyone using matrices should find topics that interest them.

The first release of Exploring Matrices has six modules. All of the modules feature animated MATLAB displays and four of the modules include interactive MATLAB "apps". The modules are:

  • Matrix Multiplication
  • Rotation and Scaling
  • Computer Graphics
  • Matrices and Cubes
  • Simulink
  • AI and Gorillas

YouTube Videos

An introduction and six videos ranging in length from one to six minutes, are available on YouTube at

https://youtube.com/playlist?list=PLn8PRpmsu08oGNmtBfFOmgVC0TlXDaLDJ.

The first four of these videos feature animations produced by our four MATLAB apps -- Multiply, Rotate, Grafix, and Qube. The other two videos describe two applications, simulation of control systems and neural networks for facial recognition (of gorillas).

Matrix Multiplication

Some viewers may just be learning the mechanics of matrix multiplication. Other viewers will have encountered it years ago. The traditional algorithm for computing the product of two matrices involves inner products between the rows of the first matrix and the columns of the second. A less familiar algorithm, which involves linear combinations of the columns of the first matrix, is often more efficient and informative. The two approaches produce the same final result from intermediate terms in different orders.

Here is one frame from the animation of these two algorithms generated by our Multiply app. The highlighted element in the first matrix either moves across the rows or goes down the columns.

Rotation and Scaling

Our first matrices are 2-by-2. We see how the matrix

$$ R \ = \ \left( \begin{array}{rr} \cos{\theta} & \sin{\theta} \\ -\sin{\theta} & \cos{\theta} \end{array} \right) $$

rotates points by the angle $\theta$, measured in degrees.

We also see how the matrix

$$ S \ = \ \left( \begin{array}{rr} \sigma & 0 \\ 0 & \sigma \end{array} \right) \ \ \ \ \ \ \ \ $$

makes objects larger and smaller.

The two can be combined with matrix multiplication. For more operations in higher dimensions, matrix multiplication provides a unifying framework.

Here is one frame from the animation of rotation and scaling generated by the Rotate app. The first panel displays a 2-by-2 rotation matrix, the second panel displays a 2-by-2 diagonal scaling matrix, and the third panel displays their product.

Computer Graphics

Operations with the 4-by-4 matrices that are at the heart of modern computer graphics employ a system known as "homogeneous coordinates". The leading 3-by-3 submatrix produces rotation and scaling in three dimensions. The fourth column produces translations.

Here is one frame from an animation of rotation about the x-axis generated by the Grafix app. This is often called "pitch". Rotation about the y- and z-axes are "roll" and "yaw",

Matrices and Cubes

Rubik's Cube, named for its inventor, Ernő Rubik, a Hungarian professor of architecture, is the greatest mathematical puzzle of all time. Our digital simulation of the puzzle, Qube, is powered by rotation matrices.

The model consists of 27 identical copies of a single small cubelet whose sides are colored red, white, blue, yellow, orange and green. Initially, all cubelets have the same orientation. A move is the simultaneous rotation of the nine cubelets in one of the six faces, by 90° or 180°, clockwise or counterclockwise. This leads to $4.3 \times 10^{19}$ possible configurations for a scrambled cube.

The object of the puzzle is to return a scrambled cube to the initial state. Most people are interested in solving the puzzle rapidly, but I am more interested in the number of moves required.

Qube offers animations of many mathematical properties of Rubik's cubes. Here is a frame from one of them.

Simulink

MATLAB's companion product, Simulink, is a block diagram programming environment used to design and simulate systems with multidomain models and to automatically generate the code required to operate embedded processors.

Matrices are involved in dozens of different ways by Simulink, but most users rarely see operations at that detailed level. Our Simulink module shows a model of an automobile being driven on a test track and displays the pitch, roll and yaw recorded by the matrix connecting the coordinate system for the automobile to the coordinate system for the track.

AI and Gorillas

This is a personal story about a project in the early stages of development.

My wife and I first visited gorillas in the Volcano National Park of Rwanda twelve years ago. An American primatologist named Dian Fossey had studied the gorillas between 1966 and her murder by poachers in 1985. Her book Gorillas in the Mist was very popular and was the basis for a critically acclaimed 1988 Hollywood movie starring Sigourney Weaver.

We have become good friends with the people in the Gorilla Doctors organization. These African and American veterinarians attend to the health of the roughly 1,000 gorillas in the park. Most of the gorillas have African names like "Inkundwa" and "Maisha". We envision a gorilla facial recognition system that is available on cell phones and tablets so that new guides and doctors can learn the names of their patients.

Inception-v3 is a convolutional neural network (CNN) that is widely used for image processing. We have a version of the network pretrained on more than a million images from the ImageNet database. This publicly available system knows nothing about gorillas. We must do additional training using photos of our unique subjects.

This is where matrices are applied. Training a CNN involves determining the values of thousands of weights and coefficients. The digital photos, regarded as vectors, are repeatedly multiplied by circulant matrices where each row is a shifted copy of the other rows. Importantly, a modern CNN also contains some nonlinear layers.

Here is one photo from a small test collection. Indundwa appears to have his own selfie stick.

Software

A self-extracting MATLAB source archive of our four apps is available at

https://blogs.mathworks.com/cleve/files/Apps_mzip.m

Thanks

Thanks to Jackson Kustell, Josh Bethoney and Heather Gorr from MathWorks and Jan Ramer and Mike Cranfield from Gorilla Doctors.

Dedication

We dedicate the Gorillas project to the memory of Mike Cranfield, DVM. Mike was Executive Director of the Mountain Gorillas Veterinary Project in Rwanda from 1999 until 2014. Before Rwanda, he held various positions at the Maryland Zoo in Baltimore.

Three months ago, Mike sent us a disc drive containing over 14,000 photographs of gorillas he had taken in Rwanda. We are now sorting and organizing the photos to provide specialized training of the facial recognition neural net.

A month ago, Mike was hospitalized from an apparent attack of West Nile Virus. He passed away on August 27. Ironically, after years of working safely in the mountain jungles of Central Africa, it is likely that he acquired the virus from a mosquito bite at his family's cabin in Canada.


Get the MATLAB code

Published with MATLAB® R2023a

]]>
MiniGallery, Sampler of MATLAB Test Matrices https://blogs.mathworks.com/cleve/2023/06/28/minigallery-sampler-of-matlab-test-matrices/?s_tid=feedtopost Wed, 28 Jun 2023 16:34:09 +0000 https://blogs.mathworks.com/cleve/?p=10382

MATLAB has dozens of test matrices. Here are a few.... read more >>

]]>

MATLAB has dozens of test matrices. Here are a few.

Contents

Mini_Gallery

  • Random. A = sprand(n,n,0.25). Random sparse, density = 0.25.
  • Bucky. A = bucky. Sparse connectivity graph of the geodesic dome, the soccer ball, and the carbon-60 molecule.
  • Wilkinson. A = wilkinson(n). Wn+. Nearly equal double eigenvalues.
  • Band. A = triu(tril(A,2),-2). Elements near diagonal.
  • Triangular. A = triu(A). Elements on and above diagonal.
  • Hessenberg. A = triu(A,-1). Upper triangular plus one subdiagonal. See schur.
  • Permutation. A = sparse(randperm(n),1:n,1). One +1 in each row and column.
  • Companion. c = charpoly(A); A = [-c(2:end); eye(n-1,n)]. Traditional companion matrix.
  • Fiedler. c = charpoly(A); A = fiedler(-c(2:end)). Fiedler companion matrix.
  • Hankel. A = flip(gallery('toeppd',n)). Constant antidiagonals.
  • Toeplitz. A = gallery('toeppd',n). Constant diagonals.
  • Magic. A = magic(n). Magic square.

Collections

Blogs

Software


Get the MATLAB code

Published with MATLAB® R2023a

]]>