Why does the SOLVE command sometimes return an expression rather than a value when solving an equation or set of equations in MATLAB 7.7 (R2008b)?

The following set of commands when executed in MATLAB 7.7 (R2008b) throws an error.
syms f
n=1;
f1 = solve(cos((2*n+1)*pi-f)+((2*n+1)*pi-2*f)*sin(f)-cos(f));
f1=double(f1);
The error messages include:
Error using ==> sym.double at 29
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.

 Accepted Answer

This bug has been fixed in Release 2011b (R2011b). For previous product releases, read below for any possible workarounds:
When solving an equation or set of equations, sometimes MuPad returns an expression rather than a value. Hence, executing the command "double" on an expression throws the error. Also, sometimes when MuPad evaluates the expression numerically rather than symbolically, this behavior is observed. One possible workaround for such issues is to solve the expression again to obtain the value. This can be done in the following ways:
1)
syms f;
n=1;
f1 = solve(cos((2*n+1)*pi-f)+((2*n+1)*pi-2*f)*sin(f)-cos(f));
f1 = solve(f1);
f1=double(f1);
2)
syms f
n=1;
f1 = solve(cos((2*n+1)*pi-f)+((2*n+1)*pi-2*f)*sin(f)-cos(f));
f1 = feval(symengine,'rhs',f1)
f1=double(f1);
Another workaround is to use the SUBS command to substitute symbolic variables in an expression with numerical values from variables in the workspace. This can be useful for functions such as ILAPLACE that evaluate an expression symbolically. An example is shown below.
syms s;
foo = ilaplace(1/(s+5))
t = 0:1e-2:5;
y = subs(foo);
figure;
plot(t,y);
Please note that the methods above do not always work for such issues and the choice of method depends on the nature of the equations being solved.

More Answers (0)

Products

Release

R2008b

Community Treasure Hunt

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

Start Hunting!