EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials Matlab Tutorial Matlab Syms
 

Matlab Syms

Priya Pedamkar
Article byPriya Pedamkar

Updated June 30, 2023

Matlab Syms

 

 

Introduction to Matlab Syms

In MATLAB, syms is used as a shortcut to the inbuilt function sym. This function can be used to create symbolic variables. The Symbolic variables used in MATLAB are not constants like the regular variables; we do not assign values to them. One important function in this toolbox is the syms function, which creates a symbolic object and automatically assigns it to a MATLAB variable with the same name. This allows for convenient manipulation and evaluation of symbolic expressions in MATLAB.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax of Matlab Syms

Syntax for Syms Function in Matlab:

syms variable1 variable2 …... variableN

syms variable1 variable2 …... variabeN [n1 …... nM]

syms f(variable1, variable2, …..., variableN)

Description:

  • syms variable1 variable2 …… variableN is used to create symbolic variables variable1 … variableN. Separate different variables by spaces. ‘syms’ function will clear all the assumptions from variables.
  • syms variable1 variable2….. variableN [n1 … nM] is used to create symbolic arrays variable1 …. variable. Each array will have the size n1- X -…- X -nM & will contain automatically generated symbolic variables.
  • syms f(variable1, vaiable2, ….., variableN)is used to create the symbolic function & symbolic variables, which will represent input arguments of function ‘f.’ Please note that a single call can be used to create more than one symbolic function.

Examples of Matlab Syms

Let us now understand the code to use syms in MATLAB.

Example #1

In the first example, we will use syms function to create a variable. Please keep in mind that we are using the ‘syms’ function here to create the variable dynamically.

Code:

syms A

[Creating symbolic variable A using syms]

A

[Displaying the variable created]

The command syms A will create a symbolic variable ‘A’ & will automatically assign it to a MATLAB variable with the same name.

This is how our input and output will look in the MATLAB command window:

Input:

syms A
A

Output:

Matlab Syms-1.1

As we can see in the output, the command syms A has created a symbolic variable ‘A’ & assigned it to a variable with the same name (A).

Example #2

In this example, we will use syms function to create multiple variables.

Code:

syms A B C

[Creating symbolic variables, A, B, C using syms]

A
B
C

[Displaying the variables created]

The command syms A B C will create 3 symbolic variables A, B & C & will automatically assign these to MATLAB variables with the same name.

This is how our input and output will look like in MATLAB command window:

Input:

syms A B C
A
B
C

Output:

Matlab Syms-2.1

Matlab Syms-2.2

Matlab Syms-2.3

As we can see in the output, the command ‘syms A B C’ has created 3 symbolic variables and assigned them to variables with the same name (A, B, C).

Example #3

In this example, we will use syms function to create a symbolic vector. This output vector will have its elements generated automatically in the workspace.

Code:

syms x [1 5]

[Creating symbolic vector ‘x’ using syms]

The command syms x [1 5] will create a symbolic vector ‘x’ of the size 1 X 5

x

[Displaying the vector created]

This is how our input and output will look like in MATLAB command window:

Input:

syms x [1 5] x

Output:

Output-3.1

As we can see in the output, the command syms x [1 5] has created a symbolic vector of the size 1 X 5.

Example #4

In this example, we will use syms function to create a symbolic matrix with multiple rows. This output matrix will have its elements generated automatically in the workspace.

Code:

syms x [2 4]

[Creating symbolic matrix ‘x’ using syms]

The command syms x [2 4] will create a symbolic matrix ‘x’ of the size 2 X 4

x

[Displaying the matrix created]

This is how our input and output will look like in MATLAB command window:

Input:

syms x [2 4] x

Matlab Syms-4.1

Output:

Output-4.2

As we can see in the output, the command syms x [2 5] has created a symbolic matrix of the size 2 X 4.

Example #5

In this example, we will use syms function to create a symbolic function with 3 variables x, y, z. Below are the steps we will follow:

  1. Create a symbolic function of required variables/arguments.
  2. Specify the formula for the function created.
  3. Pass the arguments to compute the value of the function.

Code:

syms f(x,y,z)

[Creating symbolic function ‘f’ using syms]

f(x,y,z) = 2*x + 5*y - z^2

[Specify the formula for the function created]

f(1,2,3)

[Pass the arguments to compute the value of the function]

This is how our input and output will look like in MATLAB command window:

Input:

syms f(x,y,z)
f(x,y,z) = 2*x + 5*y - z^2
f(1,2,3)

Output:

Output-5.1

Matlab Syms-5.2

As we can see in the output, the command syms f (x, y, z) has created a symbolic function ‘f’.

Conclusion

  • Syms function is used in creating symbolic variables dynamically.
  • These are used to solve various expressions with the help of functions available in MATLAB.
  • Syms function can also be used in creating symbolic functions dynamically.

Recommended Articles

This is a guide to Matlab Syms. Here we also discuss the introduction and syntax of Matlab syms, different examples, and code implementation. You may also have a look at the following articles to learn more –

  1. Matlab Autocorrelation
  2. Matlab Image Resize
  3. Jacobian Matlab
  4. Dot Product MATLAB

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW