As mentioned earlier, MATLAB provides a computational environment and programming for users, allowing numerical computation with matrices, graphing functions or information charts, implementing algorithms, creating user interfaces, and linking with programs written in various other programming languages. While it's easy to insert symbols and mathematical formulas into Word, how do you do it in Matlab? The following steps on adding mathematical symbols in MATLAB will guide you in detail.
Here's how to add mathematical symbols in MATLAB
1. Fractions
Displaying fractions on the screen isn't always straightforward; it can involve formulas requiring a specific presentation style. Whenever necessary, you can make fractions visible. However, to achieve this, you need the assistance of the LaTex compiler. This implies that your formatting options will be limited, and the result may not necessarily reflect the formatting choices you typically make when using MATLAB.
Fractions require the use of LaTex display style accessed by using $displaystylefrac. Fractions are displayed within square brackets, for example, {1}{2} displays as 1/2. The entry concludes with a dollar sign ($). To see how fractions work with a slightly more complex formula, input:
TBox12 = annotation(‘textbox’, [.13, .3, .14, .075], ‘String’, ‘$displaystylefrac{x-2y}{x+y}$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); then press Enter.
2. Square Root
Displaying square roots in MATLAB is quite straightforward. However, for the square root symbol to appear correctly sized with the radical over the expression, LaTeX comes to the rescue.
Similar to many other LaTeX commands, the string concludes with a pair of symbols ($)
To see how the square root symbol works, enter:
TBox13 = annotation(‘textbox’, [.29, .3, .14, .075], ‘String’, ‘$sqrt{f}$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); then press Enter.
The variable f will appear within the square root symbol.
3. Summation Formula
Displaying a complete summation formula with sigma and upper and lower limits involves LaTeX combined with the SUM function. Provide all 3 components of the display: the first is the lower limit, the second is the upper limit, and the third is the expression. Each element appears within its own set of square brackets.
Before the upper limit, add an underscore, used for the lower index, and a caret, placed before the upper limit, used for the upper index. The entire command is enclosed in symbols ($), much like LaTex.
However, in this specific case, you must add a second ($) symbol, or the expression will not display correctly on the screen. (The upper and lower limits won't appear in the correct positions.)
To see how the summation formula works, enter:
TBox14 = annotation(‘textbox’, [.45, .285, .14, .1], ‘String’, ‘$$sum_{i=1}^{2n}{|k_i-k_j|}$$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); then press Enter.
Note the use of the ($) symbol in this case. Also, remember to include both the underscore and double braces.
4. Integration
To display an integration formula, you use a combination of LaTex and the d function. The int function accepts 3 inputs: 2 for the range and 1 for the function. The formatting is similar to the one used for the summation formula.
The start of the range depends on the exponent of the character above, and the end part depends on the exponent of the underscore character. The entire command is enclosed in double symbols ($$) or else the formatting of the characters above and below will be incorrect.
To see how to create an integration formula, enter:
TBox15 = annotation(‘textbox’, [.61, .285, .22, .1], ‘String’, ‘$$int_{y1(x)}^{y2(x)}{f(x,y)}d{dx}d{dy}$$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); then press Enter.
Note that the two parts after the int function are within their own d functions.
5. Derivative
When creating a derivative formula, you must use LaTeX to specify the combination of a fraction with exponents. To see how derivatives work, enter:
TBox16 = annotation(‘textbox’, [.13, .21, .14, .085], ‘String’, ‘$displaystylefrac{d^2u}{dx^2}$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); then press Enter.
With the above method for adding mathematical symbols in MATLAB, you can easily incorporate mathematical formulas such as square roots, integrals, derivatives, etc., into MATLAB and use them for numerical calculations. Wishing you success.
If you're unsure how to install Matlab, check out some Matlab installation tips we've provided here.