Code that was working under R2012b and do not work any more under R2016a: fcts solve and eval
1 次查看(过去 30 天)
显示 更早的评论
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))));
0 个评论
采纳的回答
Michelle Wu
2017-3-13
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)
更多回答(1 个)
Walter Roberson
2017-3-14
Never eval() a symbolic expression. Symbolic expressions are not written in MATLAB: they are in a language that is close to MATLAB.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!