Symbolic calculations in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter fog37
  • Start date Start date
  • Tags Tags
    Calculations Matlab
Click For Summary

Discussion Overview

The discussion revolves around the use of symbolic calculations versus numerical calculations in MATLAB, particularly in the context of derivatives and solving equations. Participants explore the advantages of symbolic computation and the challenges associated with numerical methods in various scenarios.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Debate/contested

Main Points Raised

  • Some participants suggest that symbolic calculations can provide exact derivatives, which are more efficient and insightful compared to numerical estimates that may be time-consuming and inaccurate.
  • Others argue that symbolic derivatives can be used in further equations, which is not possible with numerical derivatives.
  • A participant raises a question about the difficulty of solving certain equations analytically, particularly when involving trigonometric functions, and wonders if numerical methods are the only option in such cases.
  • Another participant mentions the relevance of automatic differentiation and optimization methods, noting that many real-world problems do not allow for straightforward solutions.
  • One participant shares a specific example of using symbolic calculations in engineering to evaluate systems more efficiently than numerical methods would allow.
  • A participant provides a MATLAB code snippet demonstrating how to compute derivatives symbolically.

Areas of Agreement / Disagreement

Participants express varying opinions on the advantages of symbolic versus numerical calculations, with no clear consensus on when one method is definitively preferable over the other. The discussion remains unresolved regarding the best approach for specific types of problems.

Contextual Notes

Participants note that the effectiveness of numerical methods can depend on the specific problem being addressed, and there are limitations in solving certain equations analytically.

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   Reactions: 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   Reactions: 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
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K