convert symbolic to numeric without using double in matlab

To convert a symbolic expression to a numeric value without using double, you can use the vpa (Variable Precision Arithmetic) function in MATLAB. This function evaluates the symbolic expression to a specified number of digits. Here is an example:

main.m
syms x
f = sin(x);
y = vpa(f, 5); % Convert to 5 digits
56 chars
4 lines

In this example, we define a symbolic expression f using the syms function in MATLAB. We then use the vpa function to convert the symbolic expression f to a numerical value with 5 digits of precision and store the result in the variable y. You can change the number of digits of precision as needed.

Alternatively, you can use the subs function in MATLAB to substitute numeric values for symbolic variables in an expression. For example:

main.m
syms x y
f = x^2 + 2*y;
a = 3;
b = 2;
y = subs(f, [x, y], [a, b]);
67 chars
6 lines

In this example, we define a symbolic expression f using the syms function in MATLAB with symbolic variables x and y. We then use the subs function to substitute the numeric values a=3 and b=2 for the symbolic variables x and y, and store the result in the variable y.

related categories

gistlibby LogSnag