Search code examples
matlabmultiplication

Multiplication in matlab


4.082*2118 When I write this multiplication in MATLAB software, I get this answer: 1.705868e+04 but I want to show the answer like this: 17058.68 what is my wrong?


Solution

  • In the Matlab console, type format rational. Example:

    >> 4.082 * 2118
    
    ans =
    
       8.6457e+03
    
    >> format rational
    >> 4.082 * 2118
    
    ans =
    
      319890/37    
    
    

    You can also use the rat and rats functions. The rat function can also give you the numerator and the denominator as numbers:

    >> [num, denom] = rat(4.082 * 2118)
    
    num =
    
      319890       
    
    
    denom =
    
          37       
    

    Note that the result is only an approximation. You can improve it by decreasing the tolerance:

    >> [num, denom] = rat(4.082 * 2118, 0)
    
    num =
    
     2161419       
    
    
    denom =
    
         250