Posts

Prove that (f+g)(x) is an odd function, if f and g are odd functions (Stewart, Calculus)

Suppose f(x) and g(x) are odd functions. Prove that (f+g)(x) is also an odd function.  Answer:  1. Strategy By definition, f is an odd function if and only if f(-x) = - f(x) To show (f+g) is an odd function, we need to show (f+g)(-x) = - (f+g)(x) 2. Explanation Since $f(x)$ and $g(x)$ are odd functions $\Rightarrow f(-x) =-f(x)$ and $g(-x) =-g(x)$ By definition of sum of functions. $(f+g)(-x) =f(-x)+g(-x)$ $=-f(x)-g(x)$ $=-(f(x)+g(x))$ $=-(f+g)(x)$ (by definition of sum of functions) $\Rightarrow(f+g)(-x) =-(f+g)(x)$ $\Rightarrow f+g$ is an odd function. Q.E.D. 

Proof: f + g is an even function, if f and g are even functions. (Stewart, Calculus)

Question: Suppose f(x) and g(x) are even functions. Prove that (f+g)(x) is also an even function.  Answer: 1. Strategy Definition: a function h(x) is an even function if h(x) = h(-x) To prove (f+g)(x) is an even function, we need to show (f+g)(x) = (f+g)(-x)  2. Explanation  Recall $(f+g)(x)=f(x)+g(x)$ (by definition of sum of functions) Since $f(x)$ and $g(x)$ are even functions $\Rightarrow f(x)=f(-x)$ and $g(x) = g(-x)$ $\Rightarrow(f+g)(x)=f(x)+g(x)=f(-x)+g(-x)=(f+g)(-x)$ $\Rightarrow(f+g)(x)=(f+g)(-x)$ $\Rightarrow(f+g)$ is an even function. Q.E.D. 

[Java] Excercise: compare two given arrays and determine their equality

Motivation: In Java, c heck if Two Arrays are Equal or not Equal. a={1,2,3,4,5,6} b={2,3,1,4,5,4,4} Time complexity: $O(n^2)$ (because of the bubble sort algorithm) - Version 1: 1 process. double-nested loop statement. - Version 2: 2 processes. 1) bubble sort algorithm: $O(n^2)$, 2) single-nested loop statement O(n) - Version 3: 1 process. 1) Arrays . equals ( a , b ): $O(n^2)$ (still $n^2$) - Version 4: 2 processes. 1) check lengths of arrays, 2) sort arrays, 3) compare elements of arrays. Still $O(n^2)$ because of sorting arrays. Java codes import java.util.Arrays ; public static void main ( String [] args ) { int a [] = { 1 , 2 , 3 , 4 , 5 , 6 }; int b [] = { 2 , 3 , 1 , 4 , 5 , 4 , 4 }; boolean result = true ; // version 1 // determine whether two arrays are equal, by comparing elements one-by-one: version 1 // this is theta(n^2) algorithm for ( int i = 0 ; i < a . length ; i ++) { for ( int j = 0 ; j < b . len

[Math] Taking a square root of a number: finding an upper limit for factors of a non-prime number (Eratosthenes)

Eratosthenes has discovered that "a non-prime number has its factor (other than 1) that is less than the square root of the number."  1) Task: finding an upper limit for factors of a non-prime number.    2) Motivation: suppose number = 100 square root (100) = 10 factors of 100 = {1, 2, 4,5, 10, 20, 25, 50, 100}  Note that factors of 100 exist  before the square root of 100 (= 10). Namely, 1, 2, 4, 5 are those. With exception of 1, we have found prime factors of 10 that are less than 2,4, and 5. That's good enough information to determine that 100 is not a prime number.   3) An idea for mathematical proof would be: 1. suppose a number is a non-prime number. That is, this number = M * N where M>N > 0  2. multiplying N to both sides of the inequality  M>N results M*N > N^2  3. by design, this number = M*N > N^2 4. taking the square root, we have (M*N)^(1/2) > N  conclusion: a factor of a non-prime number is less than this number itself.    4

[Python] NOT operator examples

Image
  NOT operator takes 1 argument and gives you output based on the validity of the argument. If the argument is true, then the result of NOT operator(argument) is false.   If the argument is false, then the result of NOT operator(argument) is true.  I will provide a few examples: expression boolean value (true, false) of expression  NOT (boolean value of expression) 1 > 2 false true 3 == 3 true false "rain" == "Rain" false true "snow" == "snow" true false In Python codes:

[Python] Answers to: Why error messages are shown a line-by-line way? Why not shown as a block of codes?

It would be nice if errors in a program are shown at once.  Unfortunately, (I think) Python's error outputs are structured so that a line by line error messages are shown.    I think the "one-by-one" error message is shown because we are using Python as the programing language. Because 1) Python is an 'interpreter' language, 2) an interpreter language translates a code line by line into a machine language, 3) a machine executes a line by line, 4) when a line contains an error, then the machine stops executing and presents an error message.    I also think the youtube video below helps how an interpreter language (like Python) presents an error message ( https://www.youtube.com/watch?v=3iLUls6Z_tw - title: compiler vs interpreter)   

[Python] Sublime Text: set a build on Python 2.7 creating a sublime-build file (solution to WinError 2 problem)

Image
If anyone attempts to install Sublime Text, faces an error message [WinError 2], and notices your Python code does not work (like I did), I suggest you to do the following: (note: I am working this on Windows 10)  Situation: error message on my computer when I run "Build" by pressing ctrl+B  1. Make sure your Python code is saved (e.g. I saved my HelloWorld.py file on my C:\Brian\PythonLab)  2. Go to Tools > Build System > New Build System 3. on the untitled.sublime-build, type the following {     "cmd": ["( your directory for Python goes here )", "-u", "$file"],     "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",     "selector": "source.python" } In my case, I installed Python 2.7 on the directory C:\python27 Note that the directory should be represented using double \ (\\).  That is, C:\\Python27\\python.exe  So in my case: { "cmd": ["C:\\Python27\\python.exe