In [9]:
#Addition using +
2 + 2
Out[9]:
In [10]:
#Subtraction using -
3 - 4
Out[10]:
In [11]:
#Multiplication using *
3 * 4
Out[11]:
In [12]:
#Division using /
12 / 4
Out[12]:
In [13]:
#Powers using ^
2^4
Out[13]:
In [15]:
#typeof() (we will learn more about types in an upcoming lesson)
typeof(3.0)
Out[15]:
In [16]:
#typeof(+)
typeof(+)
Out[16]:
In [18]:
#Addition using +()
+(2, 2, 4, 6, 3, 4, 7)
Out[18]:
In [19]:
#Subtraction using -()
-(3, 4)
Out[19]:
In [20]:
#Multiplication using *()
*(3, 4)
Out[20]:
In [21]:
#Division using /()
/(12, 4)
Out[21]:
In [22]:
#Powers using ^()
^(2, 4)
Out[22]:
In [23]:
#Fractions using //
3 // 4
Out[23]:
In [24]:
#The numerator num()
num(3 // 4)
Out[24]:
In [25]:
#The denominator den()
den(3 // 4)
Out[25]:
In [26]:
#Simplification using fractions, ie.e 6 // 9
6 // 9
Out[26]:
In [27]:
#Calculating the remainder of division using rem()
rem(5, 3)
Out[27]:
In [28]:
#Calculating both the floor and the remainder using divrem()
divrem(5, 3)
Out[28]:
In [29]:
#Forcing order through the use of parentheses
2 - 4 * 3
Out[29]:
In [30]:
#Now with parentheses
(2 - 4) * 3
Out[30]:
In [31]:
#Rounding to the nearest integer using the round() function
#Example using 3.4
round(3.4)
Out[31]:
In [32]:
#To the nearest integer using the round() function
#Example using 3.5
round(3.5)
Out[32]:
In [33]:
#Towards positive infinity using the ceil() function
#Example using 3.001
ceil(3.001)
Out[33]:
In [34]:
#Towards positive infinity using the ceil() function
#Example using -3.999
ceil(-3.999)
Out[34]:
In [35]:
#Towards negative infinity using floor()
#Example using 3.999
floor(3.999)
Out[35]:
In [36]:
#Towards negative infinity using the floor() function
#Example using -3.001
floor(-3.001)
Out[36]:
In [37]:
#Towards zero using the trunc() function
#Example using 3.999
trunc(3.999)
Out[37]:
In [38]:
#Towards zero using the trunc() function
#Example using -3.999
trunc(-3.999)
Out[38]:
In [39]:
#Finding the greatest common divisor using the gcd() function
#What is the greatest numbers that will divide into 4, 8, and 20?
gcd(4, 8, 20)
Out[39]:
In [40]:
#Finding the least common multiple using the lcm() function
#What is the least common multiple of 2, 3, 5, 10 (takes successive multiple of all these values and find
#the least (lowest) common value)?
lcm(2, 3, 5, 10)
Out[40]:
$ \left| -a \right| = a $
In [41]:
#Calculating the absolute value using the abs() function
abs(-10)
Out[41]:
$ {\left| -a \right|}^{2} $
In [42]:
#Calculating the absolute valued squared using the abs2() function
abs2(-10)
Out[42]:
$ \sin \cos \ \tan \\ \csc \sec \cot \\ \sinh \cosh \tanh $ and many more
In [43]:
#Calculating the sine of pi using sin(pi)
sin(pi)
Out[43]:
In [44]:
#Usingthe d-ending for degrees, i.e. sind(180)
sind(180)
Out[44]:
In [45]:
#Calculating the hypotenuse of a right-angled triangle using the hypot() function
hypot(3, 4)
Out[45]:
In [47]:
#Using sign() for the sign of the sine of pi
sign(sind(180))
Out[47]:
In [48]:
#Comparison using ==
3 == 3
Out[48]:
In [49]:
#Is greater than using >
3 > 3
Out[49]:
In [50]:
#Is greater than or equal to using >=
3 >= 3
Out[50]:
In [51]:
#Is less than using <
3 < 3
Out[51]:
In [52]:
#Is less than or equal to using <=
3 <= 3
Out[52]:
In [53]:
#Is not equal to using !=
3 != 3
Out[53]:
In [54]:
#What is the type of NaN using typeof(NaN)
typeof(NaN)
Out[54]:
In [55]:
#Is NaN equal to NaN?
NaN == NaN
Out[55]:
In [56]:
#Is NaN greater than NaN
NaN > NaN
Out[56]:
In [57]:
#What is the type of Inf?
typeof(Inf)
Out[57]:
In [59]:
#Is Inf + 1 greater than Inf?
(Inf + 1) < Inf
Out[59]:
In [60]:
#Comparing values using the isequal(x, y) function
#Just FYI, isequal(NaN, NaN) is true
isequal(3, 3)
Out[60]:
In [61]:
#Checking to see of a value is finite using the isfinite() function
isfinite(3)
Out[61]:
In [62]:
#Checking to see if a number is infinite using the isinf() function
isinf(3)
Out[62]:
In [63]:
#Checking to see if a value is NaN using the isnan() function
isnan(NaN)
Out[63]:
In [64]:
#The peculiarity of -0.0 == 0.0 vs isequal(-0.0, 0.0)
-0.0 == 0
Out[64]:
In [65]:
#
isequal(-0.0, 0)
Out[65]:
In [66]:
#We could also use ==() instead of isequal(), etc...
==(3, 3)
Out[66]:
In [67]:
#Calculating the square roots using the sqrt() function
sqrt(9)
Out[67]:
In [68]:
#Calculating the cube roots using the cbrt() function
cbrt(27)
Out[68]:
In [69]:
#Calculating the natural exponential using the exp() function
exp(1)
Out[69]:
In [70]:
#For more accuracy when x is near zero in the case of exp(x-1) use the expm1(x) function
expm1(0.0001)
Out[70]:
In [71]:
#Calculating the natural logarithm using the log() function
log(100)
Out[71]:
In [72]:
#Specifying a base for the logarithm using the log(base, value) function (there are also the log2() and log10() functions)
log(10, 100)
Out[72]:
In [73]:
#For more accuracy when x is near zero in the case of log(1+x) use the log1p() function
log1p(0.0001)
Out[73]:
In [1]:
#The notation for a complex number using im
2 + 2im
Out[1]:
In [2]:
#Constructing a complex number using the complex() function
complex(2, 2)
Out[2]:
In [3]:
#The real part of a complex number using the real() function
real(2 + 2im)
Out[3]:
In [5]:
#The imaginary part of a complex number using the imag() function
imag(2 + 4im)
Out[5]:
In [7]:
#The complex conjugate of a complex number using the conj() function
conj(2 - 2im)
Out[7]:
In [9]:
#The absolute value of a complex number using the abs() function
abs(3 + 4im)
Out[9]:
In [10]:
#The square of the absolute value using the abs2() function
abs2(3 + 4im)
Out[10]:
In [11]:
#The argument (in radians) of a complex number using the angle() function
angle(3 + 4im)
Out[11]:
In [12]:
#Calculating the square root of -1 using sqrt(1im^2), that is, calculating the imaginary number
sqrt(1im^2)
Out[12]:
In [1]:
using Gadfly
In [2]:
f(x) = sin(x)
Out[2]:
In [3]:
g(x) = cos(x)
Out[3]:
In [4]:
plot([f, g], -2pi, 2pi)
Out[4]:
In [88]:
plot([sin, cos], -2pi, 2pi)
Out[88]:
In [83]:
h(x) = (x - 1)^3 + 1
Out[83]:
In [84]:
plot(h, -5, 5)
Out[84]:
In [85]:
plot(x -> 1 / x, -4, 4)
Out[85]:
In [86]:
plot(x -> 1 / x, 0, 5)
Out[86]:
In [87]:
plot(x -> erf(x), -3, 3)
Out[87]:
In [ ]: