How to Add Math Symbols in MATLAB - dummies (2024)

  • Home
  • Technology Articles
  • MATLAB Articles

By: Jim Sizemore and John Paul Mueller and

Updated: 03-27-2017

From The Book: MATLAB For Dummies

You would have a tough time presenting formulas to others without being able to use math symbols. MATLAB provides you with a wealth of symbols that you can use for output purposes. Here are the most commonly used symbols and how you access them.

Fraction

How to Add Math Symbols in MATLAB - dummies (2)

Displaying a fraction onscreen doesn’t always include a numeric fraction; it could be a formula that requires that sort of presentation. Whatever your need, you can display fractions whenever needed. However, to do that, you must use the LaTeX interpreter. This means that your formatting options are limited and that the output won’t necessarily reflect the formatting choices you normally make when using MATLAB.

The fraction requires use of a LaTeX display style that you access using $displaystylefrac. The fraction itself appears in two curly brackets, such as {1}{2} for the symbol 1/2. The entry ends with another dollar sign ($). To see how fractions work with something a little more complex, type TBox12 = annotation(‘textbox’, [.13, .3, .14, .075], ‘String’, ‘$displaystylefrac{x-2y}{x+y}$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); and press Enter.

Square root

MATLAB makes displaying a square root symbol easy. However, getting the square root symbol the right size and with the bar extended over the expression whose root is being taken requires LaTeX.

As with many LaTeX commands, you enclose the string that you want to format in a pair of dollar signs ($). The function used to perform the formatting is sqrt{}, and the value that you want to place within the square root symbol appears within the curly brackets.

To see the square root symbol in action, type TBox13 = annotation(‘textbox’, [.29, .3, .14, .075], ‘String’, ‘$sqrt{f}$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); and press Enter. The variable f will appear in the square root symbol.

Sum

How to Add Math Symbols in MATLAB - dummies (4)

Displaying a summation formula complete with sigma and the upper and lower limit involves using LaTeX with the sum function. You supply all three elements of the display in a single statement: the lower limit first, the upper limit second, and the expression third. Each element appears in separate curly brackets.

The lower limit is preceded by the underscore used for subscripts and the upper limit is preceded by the caret used for superscripts. The entire statement appears within dollar signs ($), as is normal for LaTeX. However, in this particular case, you must include a second set of dollar signs or the expression doesn’t appear correctly onscreen. (The upper and lower limits don’t appear in the correct places.)

To see how summation works, type TBox14 = annotation(‘textbox’, [.45, .285, .14, .1], ‘String’, ‘$$sum_{i=1}^{2n}{|k_i-k_j|}$$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); and press Enter. Notice the use of the double dollar signs in this case. In addition, be sure to include both the underscore and caret, as shown.

Integral

How to Add Math Symbols in MATLAB - dummies (5)

To display a definite integral, you use the LaTeX int function, along with the d function for the slices. The int function accepts three inputs: two for the interval and the third for the function. In many respects, the format is the same as that used for summation.

The beginning of the interval relies on the superscript caret character, while the ending of the interval relies on the subscript underscore character. You must enclose the entire command within double dollar signs ($$) or else the formatting of the superscript and subscript will fail.

To see how to create an integral, type 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’); and press Enter. Notice that the two slices come after the int function and that each slice appears in its own d function.

Derivative

How to Add Math Symbols in MATLAB - dummies (6)

When creating a derivative, you use LaTeX to define a combination of a fraction with superscripts. So, in reality, you’ve already created a derivative in the past — at least in parts. To see how a derivative works, type TBox16 = annotation(‘textbox’, [.13, .21, .14, .085], ‘String’, ‘$displaystylefrac{d^2u}{dx^2}$’, ‘BackgroundColor’, [1, .5, .5], ‘Interpreter’, ‘latex’); and press Enter.

About This Article

This article is from the book:

  • MATLAB For Dummies ,

About the book authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category:

  • MATLAB ,
  • MATLAB For Dummies Cheat Sheet
  • How to Temporarily Change the Current Folder in MATLAB
  • How to Save a Formula or Command as a Script in MATLAB
  • How to Write Your First MATLAB Script
  • How to Make a Flat Bar Chart in MATLAB
  • View All Articles From Book
How to Add Math Symbols in MATLAB  - dummies (2024)

FAQs

How to add mathematical symbols in MATLAB? ›

To insert symbols, structures, and matrices, type a backslash followed by the name of the symbol. For example, type \pi to insert a π symbol into the equation. To discover the name of a symbol or structure, hover over the corresponding button in the Equation tab.

How to write theta symbol in MATLAB? ›

Often, the easiest way to do it is to find somewhere that already has the symbol you want, and copy and paste it.
  1. Θ -- uppercase greek letter -- char(920)
  2. θ -- lowercase greek letter -- char(952)
  3. 𝜃 -- lowercase italic -- char(120579) (might not be available in your font)
  4. ϑ -- greek theta symbol -- char(977)
Feb 8, 2017

How to write a square root symbol in MATLAB? ›

Description. B = sqrt( X ) returns the square root of each element of the array X . For the elements of X that are negative or complex, sqrt(X) produces complex results. where r = abs(z) is the radius and phi = angle(z) is the phase angle on the closed interval -pi <= phi <= pi .

Can you do symbolic math in MATLAB? ›

You can create, run, and share symbolic math code. In the MATLAB® Live Editor, you can get next-step suggestions for symbolic workflows. The toolbox provides functions in common mathematical areas such as calculus, linear algebra, algebraic and differential equations, equation simplification, and equation manipulation.

How do you add characters in MATLAB? ›

To add text to the end of a string, use the plus operator, + . If a variable can be converted to a string, then plus converts it and appends it. You can also concatenate text using the append function.

How do you insert a square root symbol? ›

The number assigned to the square root symbol is '251. ' You can type the square root symbol by holding down the Alt key and then typing 2 5 1.

How to use powers in MATLAB? ›

Description. C = A . ^ B raises each element of A to the corresponding power in B . C = power( A , B ) is an alternative way to compute A.

How do you write squared in MATLAB? ›

The . ^ operator calculates element-by-element powers. For example, to square each element in a matrix you can use A. ^2 .

How to write mu in MATLAB? ›

Include multiple characters in the superscript by enclosing them in curly braces {} . Include the Greek letters α and μ in the text using the TeX markups \alpha and \mu , respectively.

How to use MATLAB commands? ›

To enter commands for MATLAB®, go to the menu and then tap Commands. Tap at the MATLAB cursor (>>) prompt to open the keyboard. Type MATLAB commands as you normally would. For example, the Command Window and keyboard might appear like this.

How to use syms? ›

The syms function creates a variable dynamically. For example, the command syms x creates the symbolic variable x and automatically assigns it to a MATLAB variable with the same name. You can then use the variable x in the MATLAB workspace for symbolic workflow, such as finding the roots of a polynomial.

Can you use symbols in MATLAB? ›

By default, MATLAB® supports a subset of TeX markup. To use additional special characters, such as integral and summation symbols, you can use LaTeX markup instead. This example shows how to insert Greek letters, superscripts, and annotations into chart text and explains other available TeX options.

How do you write a symbolic expression in MATLAB? ›

Create Symbolic Expressions

First, create the symbolic variables a , b , c , and x . Then, create a symbolic expression f that represents the arithmetical expression a x 2 + bx + c . Solve the quadratic equation f = 0 for x by using solve . You can also apply a mathematical function to an arithmetical expression.

How do you add math symbols to text? ›

In Word, you can insert mathematical symbols into equations or text by using the equation tools. On the Insert tab, in the Symbols group, click the arrow under Equation, and then click Insert New Equation. Under Equation Tools, on the Design tab, in the Symbols group, click the More arrow.

References

Top Articles
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 6025

Rating: 5 / 5 (80 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.