Main Differences Between Symbolic Variables and Symbolic Functions
Show older comments
What are the main differences between them? I know that to evaluate a symbolic variable we use subs and to evaluate a symbolic function, say f(x), we type f(x). Are there any other differences?
1 Comment
Steven Lord
on 6 Feb 2022
Is there a specific concern or question you have about symbolic variables and symbolic functions?
Accepted Answer
More Answers (2)
I'm really not sure what you are asking. One is a function of another variable, the other is a variable. A variable may be a constant, it may contain an expression, etc. In MATLAB, think of a variable as a container.
syms y(x)
Here y is an explicit function of the variable x. We can differentiate it, and MATLAB understands how the functionality works.
diff(y)
A common use for such a construct is to formulate a differential equation. It makes things easy to write, here, in essentially one line (not counting the syms call before):
ysol = dsolve(diff(y) == y + x,y(1) == 2)
As I said, symbolic variables can be thought of as containers, just like any normal variable in MATLAB. Since x already exists in symbolic form here...
z = 3 + x
So z contains an expression. A symbolic variable may contain a simple constant, or even a rather golden one...
phi = (1 + sqrt(sym(5)))/2
And while we can differentiate a symbolic variable, we need to be careful.
syms u v
w = u + 2*v
diff(w,u)
In that derivative, did we want MATLAB to understand if the derivative of v with respect to u is non-zero? Change things slightly now...
syms v(u)
w = u + 2*v
diff(w,u)
The point being, we define a symbolic function when we want to explicitly define a functional relationship. Otherwise, a variable is often adequate for most purposes.
Rishabh Singh
on 4 Feb 2022
0 votes
Hi Kareem,
You can refer to following question for understanding of Symbolic variables. In simple terms symbolic toolbox mimics mathematical syntax on paper to MATLAB environment. You can perform analytical calculations over symbolic functions. You can refer to documentation for more information.
Hope this helps.
1 Comment
Kareem Elgindy
on 6 Feb 2022
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!