Symbolic calculations in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter fog37
  • Start date Start date
  • Tags Tags
    Calculations Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
6 replies · 2K views
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
 
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