![matlab symbolic toolbox eval matlab symbolic toolbox eval](https://images.techhive.com/images/article/2014/08/circus-ponies-notebook-mac-icon-100372512-large.jpg)
Similarly we can construct a function, either inline or anonymous, from the derivative of f: fxin=inline(char(diff(f))) The result is a function that will operate on a vector input, as follows: ff()
![matlab symbolic toolbox eval matlab symbolic toolbox eval](https://it.mathworks.com/content/dam/mathworks/mathworks-dot-com/cmsimages/images/s/117542_wm_symbolicmathtoolbox_fig1_small.jpg)
Then eval evaluates the resulting string. (If we had simply typed fin=inline(f) we'd get an error message, since f is not a string.) The inline function fin now accepts an argument: fin(4)įinally, there is another possible syntax: ff = eval(vectorize(f))įf going on here is that vectorize is like char, though it is more flexible in that it will produce a string that can take a vector input.
![matlab symbolic toolbox eval matlab symbolic toolbox eval](https://i.ytimg.com/vi/skRmDYty900/maxresdefault.jpg)
What's going on here is that the inline command requires a string as an input, and char turns f from a symbolic expression to the string 'x^2-sin(x)'. We can also turn f into an inline function with the command: fin=inline(char(f)) What is going on here is that the x in f gets replaced by whatever the argument to the function is. There are a few ways to convert f to a function. We can evaluate f(4) by substituting 4 for x, or in other words, by typing subs(f,x,4) In the case of several symbolic variables, we can specify the one with respect to which we want to differentiate. Notice that MATLAB recognizes what the "variable" is. The next lines will show that we can differentiate f, but we cannot evaluate it, at least in the obvious way, since f(4) will give an error message (try it!).