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))));

채택된 답변

Michelle Wu
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
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 CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by