Our technical support group recently received a request for a tool that would convert IBM System/360 hexadecimal floating point numbers to the IEEE-754 format. I am probably the only one left at MathWorks that actually used IBM mainframe computers. I thought we had seen the last of hexadecimal arithmetic years ago. But, it turns out that the hexadecimal floating point format is alive and well.... read more >>
]]>Our technical support group recently received a request for a tool that would convert IBM System/360 hexadecimal floating point numbers to the IEEE-754 format. I am probably the only one left at MathWorks that actually used IBM mainframe computers. I thought we had seen the last of hexadecimal arithmetic years ago. But, it turns out that the hexadecimal floating point format is alive and well.
The System/360 is a family of mainframe computers that IBM introduced in 1965 and that dominated the computer industry until PCs came along twenty years later. They range in size from desk-sized to systems that fill a large room.
Here is a photo of a mid-sized model.
System/360, Model 60. Photo from Ken Shirrif's blog, IBM 360/System Summary.
The System/360 architecture is byte-oriented, so it can handle business data processing as well as scientific and engineering computation. This leads to base-16, rather than base-2 or base-10, floating point arithmetic.
* Binary f*2^e 1/2<=f<1 * Decimal f*10^e 1/10<=f<1 * Hexadecimal f*16^e 1/16<=f<1
Floating point formats played an important role in technical computing in the early days. This table from FMM lists formats that were in use in the 1970s, before IEEE-754 was introduced in 1985.
The System/360 hexadecimal format is used in many industries for the preservation of data files.
CREWES. Teaching exploration seismology. Comprehensive MATLAB toolbox for use with the textbook "Numerical Methods of Exploration Seismology with algorithms in Matlab" by Gary F. Margrave, a geoscience professor at the University of Calgary.
Library of Congress. Government.
NASA. Astronautics.
SAS. Statistics and business analytics. SAS wrapers for C.
Enthought. Python wrappers for C.
Hex_ieee. I have two twenty-line MATLAB functions, ieee2ibm and ibm2ieee, that convert IEEE-754 floating point to and from IBM hexadecimal format.
Three statements in the middle of ieee2ibm are the key to the entire operation. The first statement is
[~,e] = log2(x)
With two output arguments, log2 returns the mantissa and exponent of an IEEE-754 floating point number. The mantissa is not needed here.
The second key statement
e = ceil(e/4)
makes e divisible by 4. This turns e into the appropriate hexadecimal exponent so that the third statement
f = x.*16.^(-e)
can produce the hexadecimal mantissa.
function z = ieee2ibm(x) Convert IEEE-754 to IBM System 360 hexadecimal. z = ieee2ibm(x) Input x, real column vector. Output z, length(x)-by-16 char. Example: ieee2ibm(-118.625) = 'C276A00000000000'.
s = sign(x); % -1, 0, or 1 x = abs(x); x(x < 16^(-65)) = 0; % Underflow x(x >= 16^63) = (1-eps/2)*16^63; % Overflow
[~,e] = log2(x); % base 2 exponent e = ceil(e/4) % base 16 exponent f = x.*16.^(-e); % base 16 mantissa
E = uint64((e+64)*2^56); % Assemb1e output F = uint64(f*2^56); S = uint64((1-s)*2^62); % 1 or 0 z = dec2hex(S + E + F); % z = 'ZZFFFFFFFFFFFFFF' end
function x = ibm2ieee(z) Convert IBM System 360 hexadecimal to IEEE-754. x = ibm2ieee(z) Input z, n-by-16 char. Output x, n-by-1 double. Example: ibm2ieee('C276A00000000000') = -118.625.
E = hex2dec(z(:,1:2)); % Disassemble input F1 = hex2dec(z(:,3:8)); % < 16^6 F2 = hex2dec(z(:,9:end)); % < 16^8 s = sign(128-E); % -1 or 1
e = E-(s>0)*64-(s<0)*192; % base 16 exponent f = F1/16^6 + F2/16^14; % base 16 mantissa x = s.*f.*16.^e; end
Underflow. Anything < 16^(-65) is too small and is flushed to zero. There are no denormals.
Overflow. Anything >= 16^63 is too large. There is no inf or NaN.
* 1.0 4110000000000000 * 0.1 401999999999999A * -pi C13243F6A8885A30 * 5.3976e-79 0010000000000000 * 7.2370e+75 7FFFFFFFFFFFFFF8
S/360 hexadecimal has 7 exponent bits, while IEEE-754 has 11. Consequently, hexadecimal has a much smaller range, 5.4e-79 to 7.2e+75 versus 2.2e-308 to 1.8e+308.
The base-16 normalization implies that hexadecimal effectively has between 53 and 56 mantissa bits. Counting the hidden bit, IEEE-754 also has 53. So, the accuracy of the two is pretty much the same.
My functions ieee2ibm and ieee2ibm described above, modified to handle both single and double, plus hex_test, which does what its name implies, are available at Hex_ieee.
Homework: What happens?
ok = 0; for k = 1:10 x = single(k/10); ok(k) = hex_test(x); end ok
Get
the MATLAB code
Published with MATLAB® R2024a
The graphics in my post about R^2 were produced by an updated version of a sixty-year old program involving the U.S. census. Originally, the program was based on census data from 1900 to 1960 and sought to predict the population in 1970. The software back then was written in Fortran, the predominate technical programming language a half century ago. I have updated the MATLAB version of the program so that it now uses census data from 1900 to 2020.... read more >>
]]>The graphics in my post about R^2 were produced by an updated version of a sixty-year old program involving the U.S. census. Originally, the program was based on census data from 1900 to 1960 and sought to predict the population in 1970. The software back then was written in Fortran, the predominate technical programming language a half century ago. I have updated the MATLAB version of the program so that it now uses census data from 1900 to 2020.
The latest version of the census application is now available at censusapp2024. Here are the data and the opening screenshot.
[t,p]=UScensus;fprintf('%12d%12.3f\n',[t,p]')
1900 75.995 1910 91.972 1920 105.711 1930 123.203 1940 131.669 1950 150.697 1960 179.323 1970 203.212 1980 226.505 1990 249.633 2000 281.422 2010 308.746 2020 331.449
Today, MATLAB makes it easier to vary parameters and visualize results, but the underlying mathematical principles are unchanged:
One new observation is added to the data every 10 years, when the United States does the decennial census. Originally there were only 7 observations; today there are 13. The program now allows you to fit the data exactly by interpolation with a polynomial of degree 12 or fit it approximately by polynomials of degree less than 12.
Here are the least-squares fits with linear, cubic, and degree seven polynomials and the interpolating polynomial. As the polynomial degree increases, so does R^2, until R^2 reaches one with the exact fit.
Do any of these fits look like they could be used to predict future population growth?
In addition to polynomials, you can choose interpolation by three different piecewise Hermite cubics.
Since these fits interpolate the data, all their R^2 values are one. But before 1900 and after 2020 these functions are cubic polynomials that are not designed for extrapolation.
It is also possible to do nonlinear least squares fits by an exponential, a logistic sigmoid, and an exponential of an exponetial known as the Gompertz model.
An article by Kathleen and Even Tjørve, from the Inland Norway University of Applied Sciences in Elverum, Norway, in the journal PLOS ONE has this to say about Gompertz. "The Gompertz model has been in use as a growth model even longer than its better known relative, the logistic model. The model, referred to at the time as the Gompertz theoretical law of mortality, was first suggested and first applied by Mr. Benjamin Gompertz in 1825. He fitted it to the relationship between increasing death rate and age, what he referred to as 'the average exhaustions of a man’s power to avoid death” or the 'portion of his remaining power to oppose destruction.' "
Which fits are suitable for predicting future population size?
Despite their large R^2 values, polynomials of any degree are not suitable because outside of the time interval they behave like polynomials and do not provide realistic predictions.
Splines were never intended for extrapolation.
That leaves the exponentials. The simple exponential model grows exponentially and is not suitable. The Gompertz fit does approach a finite asymptotic limit, but the value is an astronimical a = 2101, corresponding to 2.1 $\times 10^9$ inhabitants. Hopefully, that is out of the question.
The logistic fit has an asymptotic limit of a = 655.7. We recently passed the value of t where p(t) reaches a/2, namely c = 2018. So, the logistic model predicts that the long-term size of the U.S. population will be about twice its current value. Is that realistic? Probably not.
The British statistician George Box once said, "all models are wrong, some are useful." This is true of the models of the U. S. Census that I have discussed over the past sixty years.
Here is censusapp2024 after all its buttons have been pushed. The extrapolation date is set to 2040. White noise has been added to the data. The model is a fourth-degree polynomial with an R^2 = 0.99. The R^2 value and the error estimates produced by errs account for errors in the data, but not in the model.
This particular model does a lousy job of predicting even twenty years in the future. Some of the other models are better, many are worse. Hopefully, their study is worthwhile.
I have made blog posts about the census before, in 2020 and in 2017.
Predicting population growth is featured in Computer Methods for Mathematical Computations, by George Forsythe, Mike Malcolm and myself, published by Prentice-Hall in 1977. That textbook is now available from an interesting smorgasbord of sources, including Google Scholar, Amazon, dizhasneatstuff, Abe Books, Internet Archive, PDAS, WorldCat (Chinese).
censusapp2024 is available at censusapp2024.
Get
the MATLAB code
Published with MATLAB® R2024a
The coefficient of determination, R-squared or R^2, is a popular statistic that describes how well a regression model fits data. It measures the proportion of variation in data that is predicted by a model. However, that is all that R^2 measures. It is not appropriate for any other use. For example, it does not support extrapolation beyond the domain of the data. It does not suggest that one model is preferable to another.... read more >>
]]>The coefficient of determination, R-squared or R^2, is a popular statistic that describes how well a regression model fits data. It measures the proportion of variation in data that is predicted by a model. However, that is all that R^2 measures. It is not appropriate for any other use. For example, it does not support extrapolation beyond the domain of the data. It does not suggest that one model is preferable to another.
I recently watched high school students participate in the final round of a national mathematical modeling competition. The teams' presentations were excellent; they were well-prepared, mathematically sophisticated, and informative. Unfortunately, many of the presentations abused R^2. It was used to compare different fits, to justify extrapolation, and to recommend public policy.
This was not the first time that I have seen abuses of R^2. As educators and authors of mathematical software, we must do more to expose its limitations. There are dozens of pages and videos on the web describing R^2, but few of them warn about possible misuse.
R^2 is easily computed. If y is a vector of observations, f is a fit to the data and ybar = mean(y), then
R^2 = 1 - norm(y-f)^2/norm(y-ybar)^2
If the data are centered, then ybar = 0 and R^2 is between zero and one.
One of my favorite examples is the United States Census. Here is the population, in millions, every ten years since 1900.
t p ____ _______ 1900 75.995 1910 91.972 1920 105.711 1930 123.203 1940 131.669 1950 150.697 1960 179.323 1970 203.212 1980 226.505 1990 249.633 2000 281.422 2010 308.746 2020 331.449
There are 13 observations. So, we can do a least-squares fit by a polynomial of any degree less than 12 and can interpolate by a polynomial of degree 12. Here are four such fits and the corresponding R^2 values. As the degree increases, so does R^2. Interpolation fits the data exactly and earns a perfect core.
Which fit would you choose to predict the population in 2030, or even to estimate the population between census years?
R2_census
Thanks to Peter Perkins and Tom Lane for help with this post.
Get
the MATLAB code
Published with MATLAB® R2024a
The Closest Pair of Points problem is a standard topic in an algorithms course today, but when I taught such a course fifty years ago, the algorithm was not yet known.... read more >>
]]>The Closest Pair of Points problem is a standard topic in an algorithms course today, but when I taught such a course fifty years ago, the algorithm was not yet known.
Imagine you are driving a car on the Harbor Freeway in southern California with typical Los Angeles traffic conditions. Among the many things you might want to know is which pair of vehicles is nearest each other.
This is an instance of the Closest Pair of Points problem:
It is convenient to represent the points by a vector of complex values. The distance between points z(k) and z(j) is then
d = abs(z(k) - z(j))
Here are a few points in the unit square. The closest pair is highlighted.
The first algorithm you might think of computes the distances between all possible pairs of points and finds the minimum. This is a brute force approach that requires only a few lines of code.
function d = Pairs(z) % Pairs. % d = Pairs(z) is the minimum distance between any two elements % of the complex vector z.
n = length(z); d = Inf; for k = 1:n for j = k+1:n if abs(z(k) - z(j)) < d d = abs(z(k) - z(j)); end end end end
DivCon stands for Divide and Conquer. In outline, the steps are:
function d = DivCon(z,sorted) % DivCon. % d = DivCon(z) is the minimum distance between any two elements % of the complex vector z. % % d = DivCon(z,true) is a recursive call with ascending real(z).
n = length(z); if n <= 3 d = Pairs(z); else if nargin < 2 || ~sorted [~,p] = sort(real(z)); z = z(p); end m = floor(n/2);
% Left half dl = DivCon(z(1:m),true)
% Right half dr = DivCon(z(m+1:end),true);
% Choose d = min(dl,dr);
% Center strip ds = Center(z,d); d = min(ds,d); end end
The delicate case involves the strip of points near the center dividing line. The width of the strip is the closest distance found in the recursion. Any closer pair with one point in each half must be in this strip.
function d = Center(z,d) % Center(z,d) is used by DivCon to examine the % strip of half-width d about the center point.
n = length(z) m = floor(n/2); xh = real(z(m)); [~,p] = sort(imag(z)); z = z(p); s = []; for i = 1:n if abs(real(z(i)) - xh) < d s = [s; z(i)]; end end
ns = length(s); for k = 1:ns for j = k+1:ns if (imag(s(j)) - imag(s(k))) < d && abs(s(k) - s(j)) < d d = abs(s(k) - s(j)); end end end end
Let n be the number of points. An asymptotic execution-time complexity analysis involves n approaching infinity.
It is not hard to see that the complexity of the brute force algorithm implemented in Pairs is O(n^2).
There are dozens of pages on the web devoted to showing that the complexity of the divide and conquer algorithm implemented in DivCon and Center is O(n*log(n)). The best page that I have seen is the YouTube video by Ling Qi. The key to the analysis is showing that the inner loop in Center is executed at most 7 times for any n.
We measured the execution time of Pairs(z) and DivCon(z) for n from 1,000 to 40,000 and computed the ratios of the two times. The complexity analysis predicts that this ratio is asymptotically
O(n/log(n))
Here are the timing results and a least square fit by n/log(n).
A self-extracting MATLAB archive is available at https://blogs.mathworks.com/cleve/files/TestDivCon_mzip.m
Ling Qi, IDeer7, Closest Pair of Points (Divide and Conquer) Explained. https://www.youtube.com/watch?v=6u_hWxbOc7E.
Cormen, Thomas H.; Leiserson, Charles E.; Rivest, Ronald L.; Stein, Clifford. Introduction to Algorithms (4th ed.). MIT Press and McGraw-Hill. ISBN 0-262-04630-X. 1312 pp.
Get
the MATLAB code
Published with MATLAB® R2023a
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.
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.
This one-page note turned out to be one of my most widely cited publications.
.
.
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.
MathWorks introduced the MATLAB Distributed Computing Toolbox in November 2004. We improvised this demo setup at our first Supercomputing Conference, SC2004 in Pittsburg,
.
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.
.
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.
.
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
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.
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.
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.
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.
https://blogs.mathworks.com/cleve/files/swinging_sticks.m
Get
the MATLAB code
Published with MATLAB® R2024a
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.
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
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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
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
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.
The codes for this post are available here quahogs_driver.m and here varpro.m.
Thanks to Greg Pelletier for the bug report and to Tom Lane for his statistical expertise.
Get
the MATLAB code
Published with MATLAB® R2023a
Season's Greeings Get the MATLAB code (requires JavaScript) Published with MATLAB®... read more >>
]]>
Get
the MATLAB code
Published with MATLAB® R2023a
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.
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.
The method of particular solutions.
One of my most-liked blog posts is by ten-year old Eden Rajapakse.
This code is available at 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
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
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
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