Author Archives: zhiwen liang

A DrRacket Programming Question

PROBLEM:

You’ve been asked to design a program having to do with all the owls
in the owlery.

(A) Design a data definition to represent the weights of all the owls.
For this problem call it ListOfNumber.
(B) Design a function that consumes the weights of owls and produces
the total weight of all the owls.
(C) Design a function that consumes the weights of owls and produces
the total number of owls.

 

Solution:

;; ListofNumber is one of:
;; -empty
;; -(cons Number ListofNumber)
;; interp. each number in the list is the weight of owl in pounds

(define L1 empty)
(define L2 (cons 60 (cons 40 empty)))

#;
(define (fn-for-lon l)
(cond [(empty? l) (…)]
[else (… (first l)
(fn-for-lon (rest l)))]))
;; template rules used:
;; -one of: 2 cases
;; -Atomic Dinstinct: empty
;; -compound: (cons Number ListofNumber)
;; -self-reference: (rest l) is ListOfNumber

;;Function
;; ListofNumber -> Number
;; produce the total weights of all in consumed list
(check-expect (sum empty) 0)
(check-expect (sum (cons 60 empty)) 60)
(check-expect (sum (cons 70 (cons 60 empty))) (+ 70 60 0))
; (define (sum l) 0) ;stub
; template used from ListofNumber
(define (sum l)
(cond [(empty? l) 0]
[else (+ (first l)
(sum (rest l)))]))

;;Function
;; ListofNumber -> Number
;; produce the number of owls in consumed wights list
(check-expect (count empty) 0)
(check-expect (count (cons 50 empty)) 1)
(check-expect (count (cons 60 (cons 50 empty))) 2)
; (define (count l) 0) ;stub
; template used from ListofNumber
(define (count l)
(cond [(empty? l) 0]
[else (+ 1
(count (rest l)))]))

 

All 6 test passed.

Real world differential question

After learning many mathematical technics, I found a differential is a useful tool for real-world questions.

What is a differential? If we look at a function on the graph, let see y=x, the slope of the graph is the differential of the function, which is 1 in this case. We know the slope is equal to the rise overrun. Therefore, if we assume the function is f(x), and there is a point on the graph f(x+h). Therefore, the rise is equal to the f(x+h)-f(x) while the run is equal to the (x+h-x), which is h. Since we need to make the h close to 0 in order to find out the slope, so we need to apply the method of limit where h is arbitrarily close to 0.

There is much useful application in real-world questions. For example, in physics, we know that acceleration is equal to the velocity over time, which means the rate of change in times. Therefore, we can say that the acceleration is the differential of the velocity. Therefore, if we know the velocity, we can get the acceleration by differential the velocity.

Analytic function question

Before we start to discuss, let us give the definition of an analytic function. Professor Atassi said that a function f(z) is said to be analytic in a certain range R of the complex plane if f(z) a are differentiable at each point of R and if f(z) is single-valued. For example, let f(z)=1/(1-z), we can see that f(z) is differentiable everywhere except at point when z=1. The difference between the differentiable and the analytic is the sense of real variables, which means that differentiable might exist smooth real functions that are not analytic.

Analytic function is useful because it allows us to find out the continuous derivatives of all order at the point z. For example, for example, if we want to find out the derivative of the previous question, we can just define the interior point of the region, in that case, x=0. Then, we are done all the works instead of derivative each term.

An animation of a traffic light

PROBLEM:

Design an animation of a traffic light.Your program should show a traffic light that is red, then green,then yellow, then red etc. For this program, your changing world state data definition should be an enumeration. To make your lights change at a reasonable speed, you can use the
rate option to on-tick. If you say, for example, (on-tick next-color 1)
then big-bang will wait 1 second between calls to next-color.

 

Solution:

(require 2htdp/image)
(require 2htdp/universe)

;; Constant
(define WIDTH 400)
(define HEIGHT 200)
(define CTR-X (/ WIDTH 2))
(define CTR-Y (/ HEIGHT 2))
(define MTS (empty-scene WIDTH HEIGHT))
(define RED .)
(define GREEN .)
(define YELLOW .)

;; Data Definition
;; TrafficLight is one of:
;; -“red”
;; -“green”
;; -“yellow”
;; interp. the color of the traffic light
;; <examples are redundant for enumeration>
#;
(define (fn-for-traffic-light l)
(cond [(string=? l “red”) (…)]
[(string=? l “green”) (…)]
[(string=? l “yellow”) (…)]))
;; Template rule used:
;; -Atomic Distinct: “red”
;; -Atomic Distinct: “green”
;; -Atomic Distinct: “yellow”

;; Function:

;; TrafficLight -> TrafficLight
;; start with (main “red”)
(define (main tl)
(big-bang tl
(on-tick next-color 1)
(to-draw render)))
;; TrafficLight -> TrafficLight
;; produce the next color
(check-expect (next-color “red”) “green”)
(check-expect (next-color “green”) “yellow”)
(check-expect (next-color “yellow”) “red”)
;(define (next-color tl) “red”)
; template used from TrafficLight
(define (next-color l)
(cond [(string=? l “red”) “green”]
[(string=? l “green”) “yellow”]
[(string=? l “yellow”) “red”]))

;; TrafficLight -> Image
;; render the appropriate image for traffic light
(check-expect (render “red”) (place-image RED CTR-X CTR-Y MTS))
(check-expect (render “green”) (place-image GREEN CTR-X CTR-Y MTS))
(check-expect (render “yellow”) (place-image YELLOW CTR-X CTR-Y MTS))
; (define (render tl) MTS)
; template used from TrafficLight
(define (render tl)
(cond [(string=? tl “red”) (place-image RED CTR-X CTR-Y MTS)]
[(string=? tl “green”) (place-image GREEN CTR-X CTR-Y MTS)]
[(string=? tl “yellow”) (place-image YELLOW CTR-X CTR-Y MTS)]))

All the 6 tests passed.

 

One unction with finitely many removable discontinuities is integrable

One function with finitely many removable discontinuities is integrable. There are few pieces of evidence to proof this point.

First of all, let us think about a function is continuous and differentiable. The core of the integral is to find out the area under a function. It is obviously for us to think that there is a close area under the function in a certain interval. If we take a point away, the area would still stay same because one point would not affect the area. A few dots would not make the area of an image increase or decrease because a dot is too small so that we can ignore it.

Also, if we think the function, let’s say there exist infinite points, the infinite dots can form a certain area. Let’s imagine we paint lots of points on a paper, we will finally fill the whole paper. Similarly, if there are infinite dots, we could not determine the area under the function.

Therefore, in conclusion, one function with finitely many removable discontinuities is integrable.

Make a Cuboid With a Square Base with Minimum Material Waste

If we want to make a cuboid with a square base, how can we save the material most to make the cuboid with a capacity of 108 cube meters (the cuboid has no cover).

In order to solve this question, we have to find out the volume and the total surface of the cuboid. Let x be the side of the base, and y be the length of the cuboid. In this case, we know the volume equals to 108 which equals to (x^2)(h). So we have h=108/x^2. In addition, we know the surface of the cuboid is x^2+4xh where h =108/x^2. So, we can get the equation that S=x^2+432/x. If we derivative it, we can get 2x-432x^-2. If we can find the critical point, we can find the x and h that save the most materials; therefore, making 2x-432x^-2=0, we can get x equals to 6 and h equals to 3.

In conclusion, when the sides of the base equal to 6m and the height equals to 3m would save the most materials to make a cuboid.

A Derivative Math Question

Math is everywhere around our life. For example, when autumn is coming, the leaves fall from the trees in a beautiful curve.

Today, I am going to talk about an example of a derivative question. Nearby the chemistry building, there is a fountain. Before September, the fountain was empty until one day an operator filled it. This is an interesting mathematical question. We can consider the fountain as a cylinder. We can visually inspect the radius of the fountain is about 5 meters long and the height of it approximately 0.5 meters high. The operator told me that he can fill the fountain about 10 cubic meters per minute. “There is a step in the fountain. I need to fill the water until the water covers the step.” The operator said. This situation makes me interesting. If the step is about 0.3 meters high, how fast is the depth of the water increasing at the moment that the water just covers the step?

First, we have to find the formula of the cylinder volume. Here is the formula, V=(πr^2)h. In this case, we have already known that the radius is constant. Therefore, we just need to substitute r=5 into the equation. Then derivative both sides of the formula, so that we can get dv/dt=(5^2*π)dh/dt. Also, we know that the water would fill around 10 cube meters per minute. So, we can find dh/dt=0.127 m/min.

Math Question

First of all, let us restate the question. The question says that in any circle in the universe, we can find antipodal points on the circle of the same temperature. In order to solve this problem, let’s draw a function of it. Which f(x)=T(θ)-T(θ+π), which the T(θ) is any point on the circle and T(θ+π) is the antipodal point of the specific point. In this case, if the function f(x) equals 0, it means T(θ) equals T(θ+π). However, we can’t directly prove the function equals 0. Therefore, we need to use another way to prove it.

It would better if we draw a picture first.

Then, let (0, infinity) of y axis be the positive temperature and  (-infinity, 0) of y axis be the negative temperature. The point T(0) starts moving in the positive interval of the y axis, so that we always can get a positive temperature. Oppositely, we will get a negative temperature T(π). Therefore, we can clearly guarantee that f(0)>0 because a positive number minus a negative number always get a positive number. Similarly, if we move T(π) in the negative interval, T(2π) will move in the positive interval, which f(π)<0.

Before we start to use a theorem to prove it, let me introduce it to you. If we have a function continuous in an interval, we can guarantee that there must have a number x among the interval that corresponds to a number L. This concept may be hard for you to understand. Let me give you an example. If you want to fly from the southern hemisphere to the northern hemisphere, you must have to cross the equator no matter how the pilot drives the airplane. In this case, if we can prove that f(0) is opposite with f(π), we can prove that there must have a value of x=a corresponding to f(a)=0. Therefore, we have already proved that f(0) and f(π) are the opposite sign, we just need to guarantee f(x) is continuous. If we consider the function, then there would always have a temperature on the circle, and the temperature increases or decreases constantly. Therefore, we can directly guarantee that f(x) is continuous so that we can conclude the temperature at Pa is equal to the temperature at Pa+π.

Question Math in Our Life

Math is around our life.

When you go to Mcdonald’s, you would find that the shape of the Mcdonald’s sign is an interesting function if we add a x and y axis on it. If we extend the two sides of it, we can clearly imagine that each side would arbitrarily close to one points. Therefore, if we draw a line pass through the point, we will get the two vertical asymptotes. It is obvious that this function has no horizontal asymptote. There are still other good examples, like the shape of a banana, a path, and etc..

Also, sequence is common in the real life. Heart beating is a typical instance. My heart beats approximately 1 time per 1 second. I could get a sequence when I use a clock to record my heart beating. In this case, I will get a infinity figure if I spend a sufficiently long time to record my heart beating. Therefore, this is a divergent sequence.

In addition, there are some common examples of series. In order to earn more money, people tend to save the money in the bank. There is an annual interest. RBC has the highest interest, which is 0.8% per a year. Pretending I want to save $10,000 to RBC for 3 years. My total amount of the money after 3 years equals 10,000(1+0.8%)^3. If we want to calculate how much money we can get after n years, we just need to rewrite it into 10,000(1+0.8%)^n. According to this case, we won’t lose money; therefore, this is a divergent series.

In conclusion, people are living in a world of Math. Math is everywhere around our life. If you observe your life carefully, you would find more interesting functions, sequences and series!