How do you use the function eval?
    4 views (last 30 days)
  
       Show older comments
    
how would you plug in 2 variables which both contain a 2x1 matrix?
3 Comments
  Stephen23
      
      
 on 22 Nov 2017
				
      Edited: Stephen23
      
      
 on 2 Sep 2019
  
			@NIkko Magsino: Do NOT use eval for converting symbolic expressions to numeric, or for substituting into symbolic expressions. It is the wrong tool for the job, and whoever wrote that question gave bad advice.
Take a look at the list of Symbolic Toolbox functions:
Note that eval is not listed, but it includes the correct ways to convert to numeric, which is to use the functions double, single, int8, etc. They are clearly listed under the section title "Conversion Between Symbolic and Numeric".
This specific list of symbolic conversion functions is the same:
So whoever wrote that question is not only giving bad advice but has also never bothered to actually read the MATLAB documentation.
Accepted Answer
  Walter Roberson
      
      
 on 22 Nov 2017
        Do not use eval() to turn symbolic expressions into floating point numbers. Use double() if the symbolic expressions contain only constants and functions of constants; use vpa() if the symbolic expressions contain unresolved symbolic variables.
eval() applied to a symbolic variable is not a correct thing to do. Symbolic expressions are in a different programming language that is a hybrid between MATLAB and MuPAD, and if you eval() then MATLAB will attempt to resolve them as-if they are MATLAB code, which they are not. This can be important because some of the symbolic functions take different parameters or take parameters in a different order than the MATLAB function with the same name.
2 Comments
  Walter Roberson
      
      
 on 22 Nov 2017
				The question does not require that you use eval(). eval() is given as a hint. The hint is wrong. You can refer your teacher to me if they need further convincing that eval() of a symbolic expression is not a proper thing to do.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


