Introduction
That is the third in a sequence of articles on Octave beginning with Octave, An Different to the Excessive Price of MATLAB. Octave is a free, each free as in beer and free as in speech, MATLAB appropriate numerical programming software obtainable below the GNU Normal Public License. Partially as a result of MATLAB has turn out to be the de facto trade normal for numerical programming, Octave is of explicit curiosity to people, corporations, and organizations engaged in numerical and mathematical programming and analysis and improvement.
Octave has some limitations. The bottom Octave software has no symbolic manipulation options. It isn’t a pc algebra system (CAS) resembling Mathematica or Maple. It can’t, for instance, carry out symbolic integration, symbolic differentiation, issue polynomials, and so forth. Octave does have the symbolic toolbox obtainable via the Octave Forge repository of Octave toolboxes, however the symbolic toolbox is kind of restricted. A greater choice for symbolic manipulation duties is to make use of the Maxima laptop algebra system together with Octave. Octave additionally lacks the flexibility to generate TeX or LaTex mathematical output, the de facto normal of mathematical publication. Maxima can even generate TeX output for inclusion in papers or WordPress weblog posts.
Maxima
Maxima is a pc algebra system descended from MACSYMA, one of many authentic laptop algebra techniques. MACSYMA was developed at MIT partially to be used in theoretical physics. Maxima is offered each as supply code and pre-compiled binaries for all three main laptop platforms: Unix/Linux, Microsoft Home windows, and Mac OS. Maxima is free software program, each free as in beer and free as in speech, obtainable below the GNU Normal Public License (GPL). wxMaxima is a Graphical Person Interface (GUI) for Maxima obtainable as each supply code and pre-compiled binaries for all three main laptop platforms. wxMaxima has human readable menu gadgets and buttons for a lot of widespread symbolic manipulation and mathematical features. wxMaxima additionally has “notebooks” much like Mathematica notebooks. There’s appreciable documentation on Maxima; readers are referred to the superb on-line and printed documentation on Maxima. This text is concentrated on utilizing Maxima as an adjunct to Octave.
Maxima can carry out each symbolic differentiation and integration. Symbolic differentiation is illustrated within the display screen shot of Maxima above. Some optimization algorithms, used, for instance, for mannequin becoming, require the spinoff of the operate being optimized; the operate is normally being minimized. If the operate is quite advanced, deriving the derivatives of the operate with respect to the parameters over which the optimization is carried out by hand could be time consuming, tedious, and error susceptible. The writer has used Maxima efficiently to carry out the differentiation of a mannequin operate. One can then convert the Maxima output, the spinoff produced by Maxima’s symbolic differentiation, into an expression that can be utilized in Octave through the use of the fortran(expression) command in Maxima. The Maxima fortran command generates FORTRAN code for the Maxima expression. In lots of circumstances, the FORTRAN expressions are an identical to Octave/MATLAB mathematical expressions. In some circumstances, the FORTRAN code generated by Maxima should be edited barely to create legitimate Octave/MATLAB code.
For instance, the Cauchy-Lorentz distribution is a generally used mathematical mannequin of a peak.
[tex]displaystyle {{A}over{{{left(x-muright)^2}over{W^2}}+1}}[/tex]
The Cauchy-Lorentz distribution is the frequency response of a forced-damped harmonic oscillator. It’s broadly utilized in physics, arithmetic, and engineering below plenty of totally different names.
In utilizing the Cauchy Lorentz distribution to mannequin a peak in knowledge, one usually desires to find out the values of the parameters A, mu, and W representing the magnitude of the height (A), the place of the height (mu), and the width of the height (W) that most closely fits the info. To do that, some mannequin becoming algorithms want the derivatives of the Cauchy Lorentz distribution with respect to every parameter A, mu, and W.
That is the spinoff of the Cauchy Lorentz distribution with respect to the width parameter W from symbolic differentiation in Maxima:
[tex]displaystyle {{2,left(x-muright)^2,A}over{left({{left(x-muright)^2 }over{W^2}}+1right)^2,W^3}}leqno[/tex]
This spinoff is reasonably advanced. Calculating this spinoff by hand is time consuming and error susceptible. Think about computing the spinoff of an especially advanced mathematical mannequin with a whole bunch of phrases by hand. The likelihood of error even by a highly-skilled mathematician may be very excessive. It was for that reason that instruments like Maxima had been developed.
That is the FORTAN code generated by making use of the Maxima fortran(expression) operate to the Maxima expression for the spinoff of the Cauchy Lorentz with respect to the width W
2*(x-mu)**2*A/(((x-mu)**2/W**2+1)**2*W**3)
That is truly legitimate Octave/MATLAB code. If the variables x, mu, A, and W are scalar variables in Octave, this FORTRAN expression will consider appropriately. Right here is the calculation in Octave when x, mu, A, and W are all scalar variables with the worth 1.0.
octave-3.2.4.exe:25> x = 1 x = 1 octave-3.2.4.exe:26> 2*(x-mu)**2*A/(((x-mu)**2/W**2+1)**2*W**3) ans = 0 octave-3.2.4.exe:27>
Nonetheless, in Octave the variable x is usually a vector. If x is a vector, the expression above will produce an error in Octave:
octave-3.2.4.exe:25> 2*(x-mu)**2*A/(((x-mu)**2/W**2+1)**2*W**3) error: for A^b, A should be sq. octave-3.2.4.exe:25>
The explanation for this error is that in Octave and MATLAB a number of the operators resembling * and / usually are not by default interpreted as aspect by aspect operators when utilized to vectors and matrices. For instance, the operator * is matrix multiplication by default in Octave and MATLAB. A component by aspect operator is an operator that’s utilized individually to every aspect in every vector or matrix that’s an operand. In Octave and MATLAB, the aspect by aspect operators are .*, ./, .+, .-, and so forth. For instance, if one has two vectors a and b in Octave, the operator * will give an error:
octave-3.2.4.exe:34> a a = 1 2 3 4 5 octave-3.2.4.exe:35> b b = 1 2 3 4 5 octave-3.2.4.exe:36> a * b error: operator *: nonconformant arguments (op1 is 1x5, op2 is 1x5) octave-3.2.4.exe:36>
Nonetheless, in Octave and MATLAB, one can multiply every aspect of every vector by the corresponding aspect of the opposite vector utilizing the aspect by aspect operator .* thus:
octave-3.2.4.exe:36> a .* b ans = 1 4 9 16 25 octave-3.2.4.exe:37>
Within the output of the aspect by aspect (or elementwise) operator .*, the primary aspect is 1*1, the second aspect is 2*2, and so forth.
Thus, the FORTRAN expressions generated by Maxima usually are not legitimate Octave/MATLAB code for vectors and matrices, just for scalar variables. One can convert the FORTRAN expression to a sound Octave expression for vectors by changing the non-elementwise operators to aspect by aspect operators the place the operands are vectors, normally by including a previous dot. Right here is the edited code for the instance spinoff:
operate [result] = mydiff_edited(x, A, mu, W) % operate [result] = mydiff(x, A, mu, W) % FORTRAN code from wxMaxima edited to help an array x as enter % outcome = 2*(x-mu).**2*A ./ (((x-mu).**2 ./ W.**2+1).**2*W**3) finish
If x is outlined as a vector in Octave resembling:
x = [0.0:0.1:10.0]; % x values from 0.0 to 10.0 in steps of 0.1
after which this operate is used to compute the worth of the spinoff of the Cauchy Lorentz distribution with respect to the width parameter W:
knowledge = mydiff_edited(x, 1.0, 1.0, 1.0); plot(knowledge);
Maxima can even generate legitimate TeX code for mathematical publication via its inbuilt tex(expression) command. This command can be invoked via a menu merchandise within the wxMaxima GUI (proven under).
Some TeX generated by Maxima:
tex(1/(1+x^2));
generates the TeX code:
$${{1}over{x^2+1}}$$
which shows in WordPress after eradicating the $$ tags which WordPress doesn’t want as:
[tex]displaystyle {{1}over{x^2+1}} [/tex]
The entire mathematical formulation on this article are TeX generated by Maxima on this approach.
Conclusion
Octave has in depth numerical evaluation and programming options. Octave has the particular benefit that it’s principally appropriate with MATLAB, which is at the moment the de facto trade normal for numerical programming. Most Octave scripts will run below MATLAB and plenty of MATLAB scripts will run below Octave with no modifications. If a person or software program developer has an occasional want for symbolic manipulation options resembling symbolic integration and differentiation, one can use Maxima as an adjunct to Octave. Equally, one can use Maxima to generate TeX code for mathematical publications. If one must carry out in depth symbolic manipulation, one might have to make use of Maxima or related instruments as one’s main software.
Each Octave and Maxima have the benefit that they’re free, each free as in beer and as in speech, and obtainable as supply code. There are various circumstances the place a merger, change in company technique, chapter, and even the whim of an govt has resulted in a proprietary improvement platform being discarded or deprecated to the detriment of finish customers, builders, and different clients. A well-known instance is FoxPro, as soon as one of many main database packages, which Microsoft acquired and has now introduced might be discontinued in favor of Microsoft’s different database merchandise. In distinction, open supply improvement instruments resembling Octave and Maxima could be saved alive and certainly improved by their finish customers, builders, and clients if wanted.
© 2011 John F. McGowan
In regards to the Writer
John F. McGowan, Ph.D. is a software program developer, analysis scientist, and marketing consultant. He works primarily within the space of advanced algorithms that embody superior mathematical and logical ideas, together with speech recognition and video compression applied sciences. He has in depth expertise growing software program in C, C++, Visible Primary, Mathematica, MATLAB, and plenty of different programming languages. He’s most likely finest identified for his AVI Overview, an Web FAQ (Steadily Requested Questions) on the Microsoft AVI (Audio Video Interleave) file format. He has labored as a contractor at NASA Ames Analysis Middle concerned within the analysis and improvement of picture and video processing algorithms and know-how. He has printed articles on the origin and evolution of life, the exploration of Mars (anticipating the invention of methane on Mars), and low-cost entry to house. He has a Ph.D. in physics from the College of Illinois at Urbana-Champaign and a B.S. in physics from the California Institute of Know-how (Caltech). He could be reached at [email protected].
Sponsor’s message: Try Math Higher Defined, an insightful e book and screencast sequence that can allow you to see math in a brand new gentle and expertise extra of these superior “aha!” moments when concepts all of the sudden click on.