MATLAB Symbolic calculations in MATLAB

Click For Summary
The discussion centers on the use of symbolic calculations versus numerical methods in MATLAB. Symbolic calculations provide exact derivatives and insights into functions that numerical methods cannot, making them preferable for deriving equations that will be used in further calculations. Numerical methods, while often necessary for complex functions where analytical solutions are difficult or impossible to obtain, can be time-consuming and less accurate. The conversation highlights the importance of symbolic derivatives in optimization problems, particularly when dealing with non-convex functions where global minima are not guaranteed. Users are encouraged to explore MATLAB's symbolic toolbox for efficient problem-solving and to utilize resources like MATLAB's forums and help guides for further assistance.
fog37
Messages
1,566
Reaction score
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
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
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?
 
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
Thanks!

I will look into the topics you mentioned.
 
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.
 
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
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K