Symbolic calculations in MATLAB

In summary, symbolic calculations in Matlab are advantageous for evaluating exact derivatives, using them in other equations and gaining insight into a problem. Numerical calculations are generally preferred when symbolic calculations are not possible, such as in cases where an equation cannot be solved for a variable. Symbolic calculations can also be useful in engineering for easily evaluating different systems.
  • #1
fog37
1,569
108
Hello Everyone,

I am not sure of when to use symbolic calculation and symbolic function in Matlab. For instance, we can set the domain of a function x=1:10 and plot the function y= x.^3+3 numerically to plot a graph and calculate numerically the derivatives, etc.

That said, I am not sure of what advantages symbolic calculations would provide.

thank you
 
Physics news on Phys.org
  • #2
1) Using an iterative numerical estimate of a derivative can be very time consuming and inaccurate compared to evaluating an exact symbolic derivative.
2) There are a great many occasions when the equation of the derivative is used in other equations and formulas. That can not be done with a numerical algorithm for the derivative.
3) The symbolic formula for the derivative can give insight into a problem that a numerical algorithm will not give you. In your example it would often be useful to know that the derivative is 3x2
 
  • Like
Likes QuantumQuest
  • #3
Thank you. It is much more clear.

So numerical calculations are essentially preferable whenever symbolic calculations cannot be done.

For example, I have an function f(x) involving various different trigonometric functions of the independent variable x. It is easy find the derivative df(x)/dx of such a function but it is hard (maybe impossible?) to set df(x)/dx = 0 and solve for x analytically to find the roots x. Does that mean that the only way to find the roots is numerically? How do we call this type of situation, i.e. we have a function set equal to zero but we cannot by mathematical manipulation solve for x?
 
  • #4
What sorts of projects are you doing?

In general as I think @FactChecker was saying: you'll want to get the derivative (gradient) symbolically. There is an entire field in computing related to automatic differentiation.

For many / most real world problems, you can't easily solve directly for the set := 0 case. This opens the can of worms for optimization. Basic tools in computing are gradient descent and Newton's method (esp. with a tacit Hessian). If you take a course in optimization or machine learning, you should pick these up along the way.

If your problem is not convex, there is generally no guaranty that you'll get to a global minimum. But there are lots of good methods out there for driving down cost functions.
 
  • Like
Likes FactChecker
  • #5
Thanks!

I will look into the topics you mentioned.
 
  • #6
Like others have said convergence is dependent upon the actual problems. Let's say you wanted to solve for an instance where sin(x) = 0.7

syms x
eqn = sin(x) == 0.7;
solx = solve(eqn,x)

https://www.mathworks.com/help/symbolic/solve.html
matlabs forums and help guides are powerful and useful. Use them!

fog37 said:
That said, I am not sure of what advantages symbolic calculations would provide.

In the field of engineering, I have used symbolic calculations to easily evaluate different systems. If i were to do it numerically, it would require more coding to get the results.
 
  • #7
fog37 said:
x=1:10 and plot the function y= x.^3+3

syms f(x)
f(x) = x^3+3;
df = diff(f,x)

this will give you the derivative. now whenever you want to evaluate a new f(x), just change the equation
 

FAQ: Symbolic calculations in MATLAB

What is MATLAB and what are symbolic calculations?

MATLAB is a high-level programming language and interactive environment commonly used in engineering, mathematics, and scientific research. Symbolic calculations in MATLAB refer to the ability to manipulate and solve mathematical equations using symbolic variables instead of numerical values.

How do I perform symbolic calculations in MATLAB?

To perform symbolic calculations in MATLAB, you need to use the Symbolic Math Toolbox. This toolbox provides functions and tools for creating and manipulating symbolic variables, equations, and expressions. You can also use the "syms" command to define symbolic variables and the "solve" function to solve equations symbolically.

What are the advantages of using symbolic calculations in MATLAB?

Symbolic calculations in MATLAB can save time and effort when dealing with complex mathematical problems. They also allow for more flexibility in equations, as symbolic variables can be used instead of fixed numerical values. Additionally, symbolic calculations can provide exact solutions, whereas numerical methods may introduce errors.

Can symbolic calculations be used in combination with numerical calculations in MATLAB?

Yes, symbolic calculations can be used in conjunction with numerical calculations in MATLAB. This is because MATLAB allows for mixed operations involving both symbolic and numerical variables. This allows for a more comprehensive approach to solving mathematical problems.

Are there any limitations to using symbolic calculations in MATLAB?

One limitation of symbolic calculations in MATLAB is that they can be computationally intensive for large and complex equations. Additionally, the Symbolic Math Toolbox may not have all the functions and capabilities of specialized symbolic math software. It is important to consider the specific needs of your problem when deciding whether to use symbolic calculations in MATLAB.

Similar threads

Replies
2
Views
2K
Replies
5
Views
2K
Replies
10
Views
2K
Replies
1
Views
5K
Replies
5
Views
1K
Replies
1
Views
1K
Replies
1
Views
971
Replies
11
Views
3K
Replies
2
Views
3K
Back
Top