Code that was working under R2012b and do not work any more under R2016a: fcts solve and eval

1 view (last 30 days)
Hi, I have following short code that was working under Matlab R2012b (see result below) and do not work any more under R2016a!
Could you examine this!
Thank you
fm = 1000;
BW_Hz = 100;
delta_OMEGA = BW_Hz/fm;
ai = sqrt(2);
bi = 1;
syms x;
y=bi^2*x^8 -delta_OMEGA^2*bi*x^6 +(delta_OMEGA^2*ai^2-2*bi^2-2*delta_OMEGA^2*bi)*x^4 -delta_OMEGA^2*bi*x^2 + bi^2;
alphas1b=solve(y,x)
alphas1c=eval(alphas1b)
R2012b : OK --------
alphas1b =
1.0360030147808337582053932803524
0.96524815635941929264411150626075
-0.96524815635941929264411150626075
-1.0360030147808337582053932803524
- 0.035333235097304614354828859673636 + 0.99937558630254651692473420806315*i
- 0.035333235097304614354828859673636 - 0.99937558630254651692473420806315*i
0.035333235097304614354828859673636 + 0.99937558630254651692473420806315*i
0.035333235097304614354828859673636 - 0.99937558630254651692473420806315*i
alphas1c =
1.0360
0.9652
-0.9652
-1.0360
-0.0353 + 0.9994i
-0.0353 - 0.9994i
0.0353 + 0.9994i
0.0353 - 0.9994i
R2016a : ERRORS --------
alphas1b =
-root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 1)^(1/2)
-root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 2)^(1/2)
-root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 3)^(1/2)
-root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 4)^(1/2)
root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 1)^(1/2)
root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 2)^(1/2)
root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 3)^(1/2)
root(z^4 - z^3/100 - 2*z^2 - z/100 + 1, z, 4)^(1/2)
Error using evalin
Undefined function or variable 'z'.
Error in sym/eval (line 11)
s = evalin('caller',vectorize(map2mat(char(x))));

Accepted Answer

Michelle Wu
Michelle Wu on 13 Mar 2017
This is due to a change in the design of function 'solve' starting in R2014b. The solver now returns exact representations of the solutions. To get numeric results, you may want to try function 'vpasolve' instead of 'solve' in the newer release.
As a workaround, please replace line 'alphas1b=solve(y,x)' in your code with the following code to call the numeric solver:
alphas1b=vpasolve(y,x)

More Answers (1)

Walter Roberson
Walter Roberson on 14 Mar 2017
Never eval() a symbolic expression. Symbolic expressions are not written in MATLAB: they are in a language that is close to MATLAB.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!