How can you Convert Sym to Double when the sym has already been numerically solved?

I am attempting to create an array of values using symbolic variables, solve for a specific variable, input the rest of the unknowns, then convert the symbolic variable previously solved for back to a double. In attempting to do this, I recieved the following warning:
In Fixed_Number_GA_Codes (line 122)
Warning: Unable to solve symbolically. Returning a numeric solution using vpasolve.
This is totally acceptable to have the numeric solution, but in the workspace the array I'm working with remains in symbolic form. Attempting to use sym2poly again on the numeric solutions converts them back to fraction form, and they remain symbolic. Is there any way to make this array a standard double with numeric values after already numerically solving the values? For reference, the code is pasted below:
E_p=2*atan(sqrt((1-Earth(6))/(1+Earth(6)))*tan(theta_p/2))
kepler_p=(t*sqrt(Sun(1)/((Earth(4))^3)))==E_p-(Earth(6)*sin(E_p))
for i=1:100
kepler_p_t(i)=subs(kepler_p,t,t_vals(i));
theta_p_t(i)=solve(kepler_p_t(i),theta_p);
Where the Earth and Sun arrays provide numeric values, and the only symbolic variable is theta_p, which is what is is being solved for after substituting in numeric t_vals.

 Accepted Answer

Use the double funciton.

1 Comment

I can’t run the posted code because it refers to variables that aren’t provided.
I linked to the Symbolic Math Toolbox double function, so be sure to use that specific function. Check to see if there are symbolic variables in the expression, since the presence of symbolic variables will prohibit the conversion to a double variable. All symbolic variables must be evaluated first.
If that’s not possible (the variables need to be kept in the array), use the matlabFunction function to convert the array to an anonymous function of the existing variables. Then evaluate the anonymous function as necessary in the numeric (not symbolic) part of your code.
If you’re using the variables as a ga fitness function, note that the fitness function must return a scalar output.
.

Sign in to comment.

More Answers (0)

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!