Code that was working under R2012b and do not work any more under R2016a: fcts solve and eval
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Charles Praplan
el 8 de Mzo. de 2017
Comentada: Stephen23
el 14 de Mzo. de 2017
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 comentarios
Respuesta aceptada
Michelle Wu
el 13 de Mzo. de 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)
Más respuestas (1)
Walter Roberson
el 14 de Mzo. de 2017
Never eval() a symbolic expression. Symbolic expressions are not written in MATLAB: they are in a language that is close to MATLAB.
1 comentario
Ver también
Categorías
Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!