

Many operations on symbolic expressions are ambiguous unless the independent variable is specified. Subs(f,X,lambda-Y) % substitute (lambda - Y) for X in f ans = Subs(f,) % substitute 3 for X, 10 for Y in f ans = We can prevent this by substituting sym(3) Once all of the symbolic variables are numeric, the result is numerically evaluated. Subs(f,X,3) % substitute 3 for X in f ans = The subs() function can be used to substitute one value for another, including a numeric value for symbolic one. We will make use of these in the sections to come.

Symbolic matrices are created in much the same way numeric matrices are. You can convert an expression to C code as follows ccode(g) You can convert an expression to latex as follows latex(g) Exponents, for example are printed on the line above, trying to mimic how you might The pretty() function tries to display a symbolic expression in a prettier way. H = compose(f,g) % functional composition: f(g(X)) f =įunctions of multiple variables can also be created. We can build up more complicated symbolic expressions by defining functions of these variables. To convert a constant symbolic expression to a regular Matlab double value, use the double() function. Q = sym(22/14 + 18/402) % add two fractions exactly r = W = r*2-3/t % notice that r is not evaluated

T = sym(2/3) % Need to use sym here, not syms Symbolic variables are treated differently than regular variables in Matlab and must be created using the sym() or syms() functions.Ĭonstant symbols can be defined too, which are not evaluated numerically. Online Documentation Working with Symbolic Variables

For more information, see the online documentation. So is there just no longer any way at all to specify/restrict the range of symbolic functions? Or is there another way to do it?Įdit: In case it makes a difference, the version of MatLab I'm using is R2022b.There is more to this package than we can describe here. That's what the "related documentation" says anyway. I did search online and found stuff saying to do it like thisīut it seems that, while those were valid in older versions of MatLab, they're no longer supported. I used assume to tell it the independent variables (time and angle) are real-valued, but it won't seem to like me do the same thing for velocity so long as I define it as a function. I'm trying to solve a differential equation where the dependent variable is velocity and hence it doesn't make sense to have complex-valued solutions, but I keep getting a solutions from the dsolve function that explicitly includes i.
