Indian
Indian

Reputation: 1007

Evaluation of symbolic expressions in Octave

Let us suppose that we run the following set of commands in Octave:

pkg load symbolic %loads the symbolic math package 
syms x y %declare x and y symbols 
f = x^2 - 2*x + 3; 
V = [-5:0.25:5]'; 
V_x = subs(f, x, V)

At this point V_x is a symbolic expression in Octave. Now, if this were to be MATLAB, one would run eval(V_x) and everything would be converted to numbers. However, eval does not seem to run in Octave as in MATLAB.

What should be done to convert the symbolic array into numbers?

Upvotes: 3

Views: 4514

Answers (2)

Goofyseeker311
Goofyseeker311

Reputation: 141

and how about getting variable precision (number of digits) in the evaluated symbolic output, ie, staying in the vpa symbolic space but solving all the sym internal functions to digits

eval still outputs in the default octave output_precision and format long limitations, so that is of no use.

this is one way (sym variable y holds the value):

sympref digits 1000
syms x
eqn = x==y
vpasolve(eqn)

Upvotes: 0

Suever
Suever

Reputation: 65460

double has been overloaded for symbolic variables so you can use double to explicitly convert the symbolic result to it's numeric representation

V_x_num = double(V_x);

This works in MATLAB as well as Octave.

Upvotes: 3

Related Questions