>> 4 + 5 ans = 9 >>
+ plus - minus * times / divide \ divide ^ power % comment
^ first * / \ next + - last
>> 2*5^2-3/4+1 ans = 50.25 >> (2*5)^2-3/(4+1) ans = 99.4000
pi 3.1415926... inf infinity NaN not a number i imaginary unit j imaginary unit for electrical eningeers!
>> 1/0 ans = Inf >> 0/0 ans = NaN >> i^2 ans = -1 >> j^2 ans = -1 >> sin(pi) ans = 1.2246e-16 % wha...?
What does this mean? This is scientific notation shorthand:
1.2246e-16 means . So the answer is nearly zero.
But why is
sin(pi) not exactly zero? Because computers can store and compute only finite truncations of real numbers. Matlab can't represent exactly, only a truncation of that is accurate to sixteen decimal digits.
>> 0.4 - 0.3 - 0.1 ans = 2.7756e-17 % wha...?
Here the issue is that computers use binary representations of numbers, not decimal representations. None of the three numbers 0.4, 0.3, and 0.1 can be represented exactly in binary. They're instead represented with binary fractions very nearly equal to 0.4, 0.3, and 0.1. Usually you don't see the difference, but sometimes, like here, you do.
If you want to evalue the same expression repeatedly with different variables, reset the value of the variables and use the arrow keys to “scroll up” to the expression. Then hit “enter”
>> x = 3; >> y = x^2 - 2*x + 5 y = 8 >> x = 1; >> y = x^2 - 2*x + 5 y = 4
; supress format compact format loose format long format short
diary on diary off
who whos clear x clear all
ls or dir pwd cd