text:
### Archive

Archive for the ‘Justincase’ Category

## Derivation of simple linear regression formula

Finally, I have a time to post another mathematics blog post after absence for almost two years. This time I will discuss formula of simple linear regression. Suppose we have a set of data as follow :

$(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$.

We are going to fit those points using a linear equation $Y = \beta_0 + \beta_1 X$. This classical problem is known as a simple linear regression and is usually taught in elementary statistics class around the world. However, due to the rise of computer, students are only given the formula to compute the best estimation of $\beta_0$ and $\beta_1$ without the knowledge on how to derive them. These formula are:

$\beta_1 = \displaystyle{\frac{\sum_{i=1}^n (x_i - \bar{x})(y_i-\bar{y})}{\sum_{i=1}^n (x_i - \bar{x})^2}}$, and

$\beta_0 = \displaystyle{\bar{y}-\beta_1 \bar{x}}$

(1)

where $\bar{x}, \bar{y}$ are the average of $x_i$ and $y_i$ respectively. In this post, I am going to derive these formula using four methods. The goal is always the same, this note will serve as a reminder for me when I forget how to derive these formula. If you learn statistics, these are many statistical assumptions such that this model and this formula work, but we are not going to discuss that here.

Calculus

First, let us take a look at the following figure

We see that there are five points that are fitted using a line. To derive $\beta_0$ and $\beta_1$ using a Calculus, we have to define the so-called error function, $E(\beta_0, \beta_1)$. The error function is defined as the sum of square error of each data. The formula is given as follow,

$E(\beta_0,\beta_1)=\displaystyle{\sum_{i=1}^n (y_i - \hat{y}_i)^2=\sum_{i=1}^n (y_i - (\beta_0 + \beta_1 x_i))^2}$,

where $\hat{y}_i$ is the prediction of the $y$ coordinate using the fitted line. If we take a look at the figure above, the error function is the sum of squares of all the red lines. It is obvious that whenever $\beta_0$ and $\beta_1$ change, the error function changes. Therefore we have to find $\beta_0$ and $\beta_1$ such that the error function is minimal. This is a minimization problem and in Calculus we already know about how to minimize function of two variables. First we have to find the first partial derivative of $E$ with respect to $\beta_0$ and $\beta_1$ and equate them to zero, i.e.

$\frac{\partial E}{\partial \beta_0 }=0$ and $\frac{\partial E}{\partial \beta_1 }=0$.

And we have to find $\beta_o$ and $\beta_1$ that satistfy the above equations. Second, we have to check whether or not $\beta_o$ and $\beta_1$ is the minimum or the maximum point or it could be a saddle point. However, our error function $E$ is a convex function, therefore the solution of the first derivative equation always yields a minimum point. Let us find out what is the expression of the first derivative of $E$,

$\frac{\partial E}{\partial \beta_0} = \sum_{i=1}^n (-2)(y_i-(\beta_0+\beta_1 x_i)) =0$ and $\frac{\partial E}{\partial \beta_1} = \sum_{i=1}^n (-2x_i)(y_i-(\beta_0+\beta_1 x_i)) =0$.

Tidying up the above two equations we will get :

$\sum_{i=1}^n y_i = \beta_0 n + \beta_1 \sum_{i=1}^n x_i$, and $\sum_{i=1}^n x_iy_i = \beta_0 \sum_{i=1}^n x_i + \beta_1 \sum_{i=1}^n x_i^2$,

which are a system of linear equations with two variables. We can solve the above linear equations using Cramer’s rule or any other methods, and we should get the following solution :

$\beta_0 = \frac{(\sum_{i=1}^n y_i)(\sum_{i=1}^n x_i^2)-(\sum_{i=1}^n x_i)(\sum_{i=1}^n x_iy_i)}{n(\sum_{i=1}^n x_i^2)-(\sum_{i=1}^n x_i)^2}$ and

$\beta_1 = \frac{n(\sum_{i=1}^n x_iy_i)-(\sum_{i=1}^n x_i)(\sum_{i=1}^n y_i)}{n(\sum_{i=1}^n x_i^2)-(\sum_{i=1}^n x_i)^2}$.

With a little bit of algebra manipulation, the above form is the same as the one in (1). And this is the end of the Calculus part.

Statistics

In this approach, we assume that one is familiar with the concept of mathematical statistics such as random variables, expectations, variances and co-variances. Suppose $X$ and $Y$ are random variables with mean $\mu_X$ and $\mu_Y$ respectively. Random variable $X$ and $Y$ also have variances $\sigma_X^2$ and $\sigma_Y^2$ and they also have co-variance $Cov(X, Y)$.

We want to find $\beta_0$ and $\beta_1$ such that random variable $Y$ and $\beta_0 + \beta_1 X$ is as close as possible. How are going to measure “as close as possible?” Let us define another random variable $Z=(Y-(\beta_0 + \beta_1 X))^2$. We also need to define a function $g$ as a function of $\beta_0, \beta_1$ as follow :

$g(\beta_0, \beta_1) = E(Z) = E[(Y-\beta_0 - \beta_1 X)^2]$.

Therefore, our problem will be similar to our approach in the first section. We need to find $\beta_0$ and $\beta_1$ such that $g$ is minimum or expectation of $Z$ is minimum. Expanding the equation above, we obtain:

$g(\beta_0, \beta_1)=E(Y^2)-2\beta_0E(Y)-2\beta_1E(XY)+ \beta_0^2+2\beta_0\beta_1E(X)+\beta_1^2E(X^2)$.

The above equation is quadratic in $\beta_0$ and $\beta_1$ so the zeros of the first derivatives of the above expression is the minimum point. The first derivatives with respect to $\beta_0$ and $\beta_1$ are :

$\frac{\partial g}{\partial \beta_0} = -2E(Y)+2\beta_0+2\beta_1E(X)=0$,

$\frac{\partial g}{\partial \beta_1} = -2E(XY)+2\beta_0E(X)+2\beta_1E(X^2)=0$,

which we can rewrite as:

$E(Y)=\beta_0+\beta_1E(X)$,

$E(XY)=\beta_0E(X)+\beta_1E(X^2)$,

Multiplying the first equation by $E(X)$ and subtracting it to the second equation, we obtain:

$\beta_1 = \frac{E(XY)-E(X)E(Y)}{E(X^2)-E(X)^2} = \frac{Cov(X,Y)}{\sigma_X^2}$,

and

$\beta_0 = E(Y) - \beta_1 E(X)=\mu_Y - \beta_1 \mu_X$.

The above solution is in the form of random variables. However, what we have is data which is in the form $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$. So, instead of $\mu_X$ we have $\bar{x}$, and instead of $\mu_Y$ we have $\bar{y}$. The same also applies on variances and co-variance, so in the end, the above solution is the same as equation (1). This is the end of the statistics approach.

Linear Algebra

This time, we are going to derive the formula using linear algebra approach. Personally, I think this approach is the most elegant of all other approaches. However, I need to say that one must know a little bit about linear algebra first before reading this, otherwise it would not make sense. So, using a set of data $(x_1,y_1), (x_2,y_2), \ldots, (x_n,y_n)$, we want to find $\beta_0$ and $\beta_1$. Plugging all the data into the linear equation $y = \beta_0 + \beta_1 x$, we will obtain:

$\beta_0 + \beta_1 x_1 = y_1$,
$\beta_0 + \beta_1 x_2 = y_2$,
$\vdots$
$\beta_0 + \beta_1 x_n = y_n$.

The above systems can be rewritten in matrix form, as follow:

$\left( \begin{array}{cc} 1 & x_1 \\ 1 & x_2 \\ \vdots & \vdots \\ 1 & x_n \end{array}\right) \left( \begin{array}{c} \beta_0 \\ \beta_1 \end{array}\right)= \left( \begin{array}{c} y_1 \\ y_2 \\ \vdots \\ y_n \end{array}\right)$,

or

$Ax =w$,

where $A$ is a $n \times 2$ matrix, $x = (\beta_0,\beta_1)^T$ and $w$ is a vector containing $y_1, \dots, y_n$. In linear algebra, the equation above is known as the over-determined linear equation. It may have a solution but mostly it does not have one. One method to solve such system is using the theory of projection. Suppose we have a linear equation $Ax=w$. According to the theory of linear algebra, this equation has a solution only if $w$ is inside the column space of $A$. In the above case, where we want to find $\beta_0$ and $\beta_1$, our $w$ is clearly not in the column space of $A$.

Therefore, to find the solution of the linear equation, we must bring $w$ to the column space of matrix $A$. We are going to project $w$ to the column space of $A$. We can do many different projections but according to the theory of linear algebra, we must do an orthogonal projections such that our estimation of $\beta_0$ and $\beta_1$ will bring $Ax$ “closest” to $w$. Let us now discuss the projection theory first.

Consider the following figure.

Suppose we want to project $w$ perpendicularly to the vector space $V$. Suppose $w'$ is the result of the orthogonal projection and $V$ is the column space of $A$. Then the linear equation $Ax=w'$ has a solution since $w'$ is inside the column space of $A$. Consider $V^{\perp}$ which is the orthogonal complement of $V$. Clearly, vector $w-w'$ is inside this space. From the theory of linear algebra, we know that if $V$ is the column space of $A$, $V^{\perp}$ is the null space of $A^T$. Therefore we have $A^T (w-w')=0$, or $A^tw'=A^Tw$. Since we know that $w' = Ax$ then we have $A^TA x = A^T w$. If the matrix $A^TA$ is invertible (mostly it is in our case) we can find the solution of our problem which is $x = (A^TA)^{-1}A^T w$.

That’s it, we have done it. If we substitute back every variable to our original variable, we will have our solution, i.e.

$A = \left( \begin{array}{cc} 1 & x_1 \\ 1 & x_2 \\ \vdots & \vdots \\ 1 & x_n \end{array}\right), x= \left( \begin{array}{c} \beta_0 \\ \beta_1 \end{array}\right), w = \left( \begin{array}{c} y_1 \\ y_2 \\ \vdots \\ y_n \end{array}\right)$.

With a little bit of algebra (again), we can easily show that the formula $x=(A^TA)^{-1}A^Tw$ is the same as the equation (1).

Numerical approach

Our last approach is using the theory of numerical methods. Since this approach is numerical, we are not going to get the solution as in the equation (1). This approach will only try to approximate it. This approach will use some of the result obtained in the Calculus approach, which is the error function i.e.,

$E(\beta_0,\beta_1)=\displaystyle{\sum_{i=1}^n (y_i - \hat{y}_i)^2=\sum_{i=1}^n (y_i - (\beta_0 + \beta_1 x_i))^2}$.

However, we are not going to label it as an error function, instead we are going to label it as a cost function. We say this function as a cost function because every time we pick the wrong $\beta_0$ and $\beta_1$ there is a cost that we have to pay. So we have to find the right $\beta_0$ and $\beta_1$ such that the cost is minimum.

There are many numerical methods to solve such a problem, but at this time we are going to discuss only one methods, i.e. gradient descent. The basic idea is we start with arbitrary values of $\beta_0$ and $\beta_1$ and we are going to continually change the value of $\beta_0$ and $\beta_1$ in such a way so that the cost function decreases. Hopefully, we end up at the value where the cost function is minimum.

The following is the general procedure of the gradient descent method :

repeat until convergence {

$\beta_j := \beta_j - \alpha \frac{\partial}{\partial \beta_j} E(\beta_0,\beta_1)$     (for j=0 and j=1)

}

The above procedure will be executed continually until the value of $\beta_0$ and $\beta_1$ convergent, which means that we are getting close to the value where the cost function is minimum. The symbol $\alpha$ is called the learning rate. It always takes a positive value and if this variable is too large, $\beta_j$ will change drastically and we sometimes cannot get the result that we want. But if $\alpha$ is too small, our computation will be very slow, although it is guaranteed that we will get the minimum cost function.

Finally, we need to know some Calculus to derive the partial derivative of the cost function with respect to $\beta_0$ and $\beta_1$. For the readers who know Calculus, they can derive themselves, and we will obtain :

$\frac{\partial }{\partial \beta_0}E=-2\sum_{i=1}^n(y_i - (\beta_0 + \beta_1 x_i))$,

$\frac{\partial }{\partial \beta_1}E=-2\sum_{i=1}^n(y_i - (\beta_0 + \beta_1 x_i))x_i$.

Let’s plug this into the gradient descent algorithm and we will have:

repeat until convergence {

$\beta_0 := \beta_0 - \alpha (-2\sum_{i=1}^n(y_i - (\beta_0 + \beta_1 x_i)))$

$\beta_1 := \beta_1 - \alpha (-2\sum_{i=1}^n(y_i - (\beta_0 + \beta_1 x_i))x_i)$

}

Let’s take an example. Here is a simple python code to illustrate the idea.

import math
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1, 2, 3, 4, 5])
y = np.array([1, 2, 2.5, 4, 4.5])
b0,b1 = 0.0, 0.1
val_x = np.linspace(1.0,5.0,100)
val_y = b0+b1*val_x
plt.plot(x,y,'r.')
plt.plot(val_x,val_y,'b-')
plt.grid(True)
plt.show()

Running the above code, we will get the following picture.

The red dots are the data that we are going to fit. The blue line is just one example of $\beta_0$ and $\beta_1$ that of course, is a poor fit. We are going to fix it using gradient descent method.

def costfunction(b0,b1,x,y):
sum = 0
n = len(x)
for i in range(0,n):
sum = sum + (y[i]-(b0+b1*x[i]))**2
return sum
n = len(x)
sum1,sum2 = 0,0
for i in range(0,n):
sum1 = sum1 + (y[i]-(b0+b1*x[i]))
sum2 = sum2 + (y[i]-(b0+b1*x[i]))*x[i]
return [(-2)*sum1, (-2)*sum2]
b0,b1 = 0.0, 0.1
maxiter = 300
alpha = 0.005
c = np.zeros(maxiter)
c[0] = costfunction(b0,b1,x,y)
for i in range(1,maxiter):
temp1 = b0 - alpha*v[0]
temp2 = b1 - alpha*v[1]
b0 = temp1
b1 = temp2
c[i] = costfunction(b0,b1,x,y)
print("$\beta_0$ = ",b0,"$\beta_1$ = ",b1)
val_x = np.linspace(1.0,5.0,100)
val_y = b0+b1*val_x
plt.plot(x,y,'r.')
plt.plot(val_x,val_y,'b-')
plt.grid(True)
plt.show()

Running the second code above, we would get the desired result.  From the figure above, we see that our fit is close enough with our data.

The theoretical value of $\beta_0$ and $\beta_1$ are 0.1 and 0.9 respectively, but in the code above we will obtain only approximation value that was obtained by performing 300 iterations.

## Taylor method with automatic differentiation

June 14, 2016 1 comment

I teach numerical analysis course and in the one of the chapters, I teach my students about the numerical solution of ordinary differential equations (ODEs). One of numerical solution methods I teach is the so-called Taylor method. This method works by applying the Taylor series to the solution of the differential equation. Suppose we have one-dimensional differential equation as follow:

$\frac{dy}{dt} = f(y)$ and $y(t) = y_0$.

Let’s assume that we only consider an autonomous ODE first.  To find a solution at the next step, $y(t+h)$, we need to apply Taylor expansion, as follow:

$y(t+h) = y(t) + y'(t) h + y''(t)\frac{h^2}{2} +y'''(t)\frac{h^3}{6}+\dots$.

Therefore, depending on how accurate we want our solution is, all we need is to compute the derivatives of $y(t)$. Unfortunately, computing all the derivatives is not an easy task for a computer. We have to derive all the derivatives by ourselves and then input them to the computer.

In this note, I will introduce an automatic differentiation as a tool to compute the derivatives of $y(t+h)$ so that we can compute $y(t+h)$ as accurately as possible. Let us consider the series expansion of $y(t+h)$ as above, but I will use constant $a_i$ to replace the $i-$th derivative of $y(t)$,

$y(t+h) = a_0 + a_1 h + a_2 h^2 + \dots$.

Let us derive the above series with respect to $h$.

$y'(t+h) = a_1 + 2 a_2 h + 3a_3 h^2 + \dots$.

Notice that the derivative at the left hand side of the above equation is actually equal to $f(y(t+h))$ since we know that $y(t+h)$ satisfies the ordinary differential equation. Then we have,

$f(y(t+h)) = a_1 + 2 a_2 h + 3a_3 h^2 + \dots$.

Since $y(t+h)$ is a series of $h$ then $f(y(t+h))$ is also a series of $h$. Then both sides of the above equation are series of $h$, thus we can equate each of the coefficient of $h^j$ to get $a_1$$a_2$ and so on. The most difficult task in this problem is to find the series of $f(y(t+h))$ since the function $f(y)$ can be anything.

Let’s take an example. Suppose we want to integrate the following differential equation,

$\frac{dy}{dt} = y(1-y)$ and $y(0)=0.5$.

Let us choose $h=0.1$ and compute $y(0.1)$. As before, we assume that $y(0.1)$ is a series of $h$ as follows,

$y(0.1) = a_0 + a_1 h + a_2 h^2 + \dots$.

Differentiating both sides of the above equation, we get

$y'(0.1) = a_1 + 2 a_2 h + 3 a_3 h^2 + \dots$.

The right hand side of the above is equal to

$y'(0.1) = y(0.1)(1-y(0.1)) = (a_0 + a_1 h + \dots)(1 - (a_0 + a_1 h + \dots)) = b_0 + b_1 h + b_2 h^2 + \dots$.

Therefore, we get,

$a_1 = b_0$$a_2 = b_1/2$,$a_3 = b_2/3$,  and so on.

The real question is how to find $b_0$, $b_1$ and so on. If the function $f(y)$ only involves operations such as addition, subtraction and multiplication, it would be easy to find the $b$‘s. But if the function $f(y)$ has operations such as division, exponential, logarithm and trigonometric functions then we have to think a bit harder on how to find $b$‘s. We go back to the previous example. Since the operations in this example are only multiplication and subtraction, we can easily compute $b_0$, $b_1$ and so on. Using algebraic modification, we get the following,

$b_0 = a_0 \times (1-a_0)$, thus $a_1 =a_0 \times (1-a_0)$
$b_1 = (a_0 \times -a_1 ) + (a_1 \times (1-a_0))$, thus $a_2 =((a_0 \times -a_1 ) + (a_1 \times (1-a_0)))/2$
$b_2 = (a_0 \times -a_2 ) + (a_1 \times (-a_1))+(a_2 \times (1-a_0))$, thus $a_3 =((a_0 \times -a_2 ) + (a_1 \times (-a_1))+(a_2 \times (1-a_0)))/3$

and so on.

The more $a$‘s we compute, the more accurate our solution is. Using Taylor method this way, we can easily apply this method in a program. It should be clear why this method is called automatic differentiation because we don’t need to manually derive all the derivatives.

Next, I tried to numerically integrate the previous example. Below is the graphic of the error of Taylor method with automatic differentiation versus time. As we can see from the figure, that the error of our numerical integrator is so small and it is almost exact. The number of $a$ I used in this graph is 10.

I use python to numerically integrate this example. You can find the code to produce the above figure in the end of this note. One of the drawbacks of this method is when you change your ODE, you have to change your code as well. In other numerical integrators such as Runge Kutta, we don’t need to change the whole code, we just need to change the ODE and we should get the solution. Together with my student, I am trying to tackle this problem and I hope it will be posted in here.

import math as m
import numpy as np
import pylab as plt

#preliminary constants
order = 10
h = 0.1
t = 0.0
t_end = 5
y0 = 0.5
#defining solution
sol = []
sol.append(y0)
time = []
time.append(t)
#start of the program
while t<t_end:
a = []
a.append(sol[-1])
for k in range(1,order):
if k == 1:
a.append(a[k-1]*(1-a[k-1]))
else:
sum = 0.0
for j in range(0,k-1):
sum = sum + a[j]*(-a[k-1-j])
a.append((sum+a[k-1]*(1.0-a[0]))/k)
sum = 0.0
for i in range(0,order):
sum = sum + a[i]*h**i
sol.append(sum)
t = t + h
time.append(t)
#end of the program

#real solution computation
real_sol = []
for t in time:
temp = m.exp(t)/(m.exp(t)+1.0)
real_sol.append(temp)

#plotting the error versus time
sol = np.array(sol)
real_sol = np.array(real_sol)
time = np.array(time)
error = sol-real_sol
plt.plot(time[:],error[:])
plt.show()

Categories: Justincase, python

## My first try creating a bash script

I am a ubuntu user, but sometimes I also use windows, mainly because my computer in the office is using windows. So, I use both ubuntu and windows. Even, my laptop has both windows and ubuntu. I tried to get rid of windows once, and installed wine to use windows application in my ubuntu. But it runs very slowly and it’s killing me and in the end, I came back to reinstall windows. I mainly use ubuntu for my research. The softwares I use for my research are auto, python, dstool, latex, xfig which run smoothly in ubuntu, even though python and latex can also be installed and run smoothly on windows machine. On the other hand, I use windows to do some regular activities such as browsing the internet, watching movies, checking my email, creating an office documents etc. All of which can be done in ubuntu as well. But there are activities that I must use windows, I sometimes need to use matlab and sometimes I like to play a game that only runs in windows. These two things are the main reason I still come back to use windows. Recently, I learn python so I am now trying to less use matlab.

That is just a background and my main point here is about bash scripting. After a few years using ubuntu, I have not created any bash script. Today, finally I learn to create one script. I created a script to automate my boring routine. When I write a paper, I need some illustrations. I mostly use xfig to create some mathematical images and to be able to use $\LaTeX$ in the figure I need to convert it to an eps file. The produced eps file will be then converted to a pdf file as it is perfectly compatible to my pdflatex command. But before that, I need to crop the resulted pdf file in order to remove white space around the image. Suppose the name of my xfig file is spam.fig. I then write a series of command.

figtex2eps spam.fig
ps2pdf spam.eps
pdfcrop spam.pdf

I want to write a script that do all the above automatically. Thus I created the following script.

#!/bin/bash
# Converts a .fig-file (xfig file) to a .eps-file by using a built-in function figtex2eps
# and then convert it to a .pdf file by using a built-in function ps2pdf
# and finally convert it to a cropped pdf file by using a built-in function pdfcrop
#
# ivanky saputra https://ivanky.wordpress.com
#
# credit to :
# $/home/abel/c/berland/etc/cvsrepository/figtex2eps/prog/figtex2eps$
# $ps2pdf in ubuntu$
# $pdfcrop in ubuntu$
echo "We are going to change the following $1.fig to a cropped pdf file" function quit { exit } if [$1 == ""];
then
echo "no files given";
quit
else
echo "Processing $1.fig............"; figtex2eps$1.fig
ps2pdf $1.eps pdfcrop$1.pdf
echo "Done";
fi

As someone has said that it is better to share your code and data openly as we as human are idiots and will make mistakes, please give me any suggestion to improve mine.

## My first Coursera course

In the middle of this year, I received a Fulbright Visiting Scholar that allowed me to go to Athens, OH, US. I spent four months in Ohio University starting in September, which means that I took a leave in the university I am working. One of my activities while I was in Ohio University was I took a course from Coursera. At that time I was eager to learn and to know python programming language therefore I decided to take the course, An Introduction to Interactive Programming in Python, offered by Rice University taught by the following professors: Joe Warren, Scott Rixner, John Griener, and Stephen Wong.

My first coursera was nothing but really, really good. The class could not definitely be better. The intructors have put so much effort in preparing the class and at the same time they were really enjoyable and fun. I really learned a lot from this class and I recommend everyone to take this class. After nine weeks, I finished the course and proudly said that I got 96.9% with distinction mark.

But what I wanted to tell here is the content of the course. From knowing nothing of Python I now know that the word ‘python’ is originally from the Month Python’s Flying Circus not the reptilia. I also know how useful this new programming language is. Python can be used to build an interactive game, to conduct some scientific computations, to analyse data science and many more. There are already many communities that use Python and they are (still) growing. One more good thing is the fact that it is free. Python works on either Windows, Linux or Mac and the installation on each device is not that difficult. I am using both Windows and Ubuntu. For Windows, I use mainly Python(x,y) and for Ubuntu, I don’t have to do anything as it is already inside. However, in this course, I did not have to use all of these as one of the instructors has built a nice Python web application that is called Codeskulptor. It will allows us to make a python scripts on your web browser so actually you don’t have to install python in your computer.

From the course, I learned to make interactive games. Even though the games I made were not perfect but I think it is playable and fun enough. I learned to make games like rock-paper-scissors-spock-lizzard, number guessing game, stopwatch game, pong, memory, and asteroids. The following links are the python scripts for all of the above games I made during the course. The link will bring you to a codeskulptor website, in which I had already written a python script. You just need to press the play button on the top left of your screen.

1. RPSLS  This game is called rock-paper-scissors-lizzard-spock game. It is an extention of rock-paper-scissors and first appeared in The Big Bang Theory series.

2. Number guessing game This game, as you might guess, is a number guessing game. The computer hide a number between a small number and a big number and you have finite tries to guess what number the computer is hiding.

3. Stopwatch This game will train your reflexes. It will show a stopwatch and you have to press the pause button every whole second.

4. Pong Oh, please tell me you know this game.

5. Memory There are 16 cards facing down, and all of them come in pair. Figure out the pair with the smallest number of tries.

6. Blackjack The blackjack game, yes, it is the blackjack game that you always know.

7. Asteroids Asteroids is an arcade space shooter game and I think I played this game when I was a kid. I played this game using an Atari device.

Other than those games, I made two another python scripts just for fun. The first is a fan and the second is the illustration of Hilbert’s curve. Hope you like it.

Categories: Justincase, python, Teachings

## Finding a Hopf bifurcation from a cube equation

September 27, 2014 1 comment

Let me first state what I found out this week. Forgive me if this result is trivial for you, but this result indeed helped me in my research.

Lemma 1
Suppose we have a cube equation $x^3 + ax^2 + bx + c=0$. The roots of this equation are a couple of purely imaginary roots and a single real root if and only if the following conditions are satisfied $b>0$ and $c=ab$.

The proof is very easy and I am not going to prove this. Apparently, the conditions $b>0$ and $c=ab$ are a necessary and sufficient condition for the cube equations to have a single real root and a couple of purely imaginary roots.

Okay, now let us move to the beginning why I bother with cube equations in the first place.

At the moment I am studying a mathematical model on HIV-1 virus with cell mediated immunity. I just started so I still don’t know all the representation of this model in the real life. But here is the model.

$\dot{x} = \lambda - dx - \beta x v$
$\dot{y} = \beta x v - ay - p y z$
$\dot{v} = k y- u v$
$\dot{w} = c y w - c q y w - b w$
$\dot{z} = c q y w - h z$

Yes, you are right, it is a five dimensional model. The variables $x, y, v, w, z$ are the state variables that are representing the density of uninfected cells, the infected cells, the density of virus, the CTL response cells and the CTL effector cells respectively. Why it is five dimensional, what are the parameters representing and other modeling questions, I still don’t know the answer. At the moment I am interested to find an equilibrium in this system that can undergo a Hopf bifurcation. An equilibrium can have a Hopf if the Jacobian of the system evaluated at this equilibrium has a purely imaginary eigenvalue. Actually this is the first time I handle a five dimensional system so it will be interesting.

Now we know why I need Lemma 1.

In my case, the situation is greatly simplified as all parameters are numbers except two which are $d$ and $b$. From the paper that I read, I found that there are three equilibria in the system, so called $E_0, E_1, E_2$. At the moment I am interested in the equilibrium $E_1$ because I suspected that this equilibrium can have a Hopf bifurcation and because the coordinate of this equilibrium has the following conditon $w=z=0$. Let us have a look at the Jacobian matrix evaluated at $E_1=(x_1,y_1,v_1,0,0)$.

$J = \left( \begin{array}{ccccc} -d-\beta v_1 & 0 & -\beta x_1 & 0 & 0\\\beta v_1 & -a & \beta x_1 & 0 & -p y_1 \\ 0 & k & -u & 0 & 0 \\ 0 & 0 & 0 & cy_1-c q y_1 - b & 0 \\ 0 & 0 & 0 & c q y_1 & -h \end{array} \right)$

As I said before, all the parameters are numbers except $d$ and $b$. Also $E_1$ will be an expression that depends on $d$ and $b$. As a result the matrix above will be depending on $d,b$.

We are interested in what value of $d,b$ such that the matrix above has a purely imaginary eigenvalues. Even though the above matrix is not a block matrix but when we compute the eigenvalues, we can really separate the matrix above. We can obtain the eigenvalues of the above matrix by computing the eigenvalues of the following two matrices:

$A = \left( \begin{array}{ccccc} -d-\beta v_1 & 0 & -\beta x_1 \\ \beta v_1 & -a & \beta x_1 \\ 0 & k & -u \\ \end{array} \right)$ and

$B = \left( \begin{array}{ccccc} - cy_1-c q y_1 - b & 0 \\ c q y_1 & -h \end{array} \right)$.

The eigenvalues of matrix $B$ is easy and it is real. So the problem really is in the computing the eigenvalue of matrix $A$. Consider the matrix $A$ in a simpler notation.

$A = \left( \begin{array}{ccccc} a & b & c \\ d & e & f \\ g & h & i \\ \end{array} \right)$.

The characteristic polynomial of the above matrix is

$p(\lambda) = \lambda^3 - (a+d+g) \lambda^2 + (bd-ae+fh-ei+cg-ai) \lambda + \det(A)$

Therefore to find the value $d,b$ such that we have a Hopf bifurcation, we only need to solve the following conditions:
1. make sure that $(bd-ae+fh-ei+cg-ai)$ is positive and
2. solve $- (a+d+g) \times (bd-ae+fh-ei+cg-ai) = \det(A)$.

I created this note (which is a part of our paper) so that I won’t forget what I had done. We don’t usually show this kind of computation but for me this little computation will be useful. Even though I uses software to compute and investigate the existence of Hopf bifurcation but it does not show the exact value of the parameter.  Using algebraic approach I found the exact value.

Reference of the model
Yu, Huang, and Jiang, Dynamics of an HIV-1 infection model with cell mediated immunity, Communications in Nonlinear Science and Numerical Simulation, 2014, vol. 19.

Additional note: (Two dimensional case) Suppose the Jacobian matrix evaluated at the equilibrium is given below

$B = \left( \begin{array}{ccccc} p & q \\ r & s \end{array} \right)$.

Then the equilibrium has a Hopf bifurcation if the following conditions are satisfied:
1. $\det(B) > 0$ and
2. $trace(B) = 0$.

Categories: bifurcation, Justincase

## Random Numbers in Matlab

In the past two years, I have been supervising bachelor degree students for their final projects. Unfortunately, most of the projects were related to time series, forecasting, stochastics process, financial mathematics and many topics related to application to statistics in finance. To be honest, this is not my strong suit. As a result, we struggled when reading and using many statistical techniques especially the one in time series. With this notes, I hope to understand and to keep remember those techniques. Moreover, as I am teaching Time Series Analysis this semester, I believe this post will be very useful for my students.

In this post, I concentrate on how to generate random numbers with certain distributions in Matlab and its application in my time series lecture. I know that we can easily google on how to do these, but as always, it would be very nice to have this ready in my blog. When I forget to do this, I don’t have to google it again and save myself a few minutes.

Generating random numbers and introduction to subplot, histogram, state commands in matlab

To generate random numbers in Matlab with certain distributions, I  need to type

x1 = normrnd(mean,std,[m,n]); %normal distribution x2 = binornd(N,p,[m,n]); %binomial distribution x3 = exprnd(lambda,[m,n]); %exponential distribution x4 = gamrnd(a,b,[m,n]); %Gamma distribution x5 = rand(m,n); %uniform distribution x6 = poissrnd(lambda,[m,n]); %Poisson distribution

The commands above returns an m x n matrix containing pseudorandom values drawn from normal, binomial, exponential, gamma, uniform and Poisson distributions respectively. Some usefull commands related to random number generator in Matlab are

subplot(2,2,1) %top left figure hist(x1) %histogram of normal random numbers subplot(2,2,2) %top right figure hist(x2) %histogram of binomial random numbers subplot(2,2,3) %bottom left figure hist(x3) %histogram of exponential random numbers subplot(2,2,4) %bottom right figure hist(x4) %histogram of Gamma random numbers

The above commands return histograms of random numbers generated by the previous commands.  The output of those commands is the following figure.

Another useful command regarding random number generators is the ‘state’ option. This is very usefull if we want to repeat our computation that involves random number. The following code will help us understand how to use the state command.

clc; clear; theta = -0.8; phi = 0.9; mu = 0; sigma = 0.1; %-----generating random numbers------------------------- normrnd('state',100); e = normrnd(mu,sigma,[100 1]); %-----generating MA(1) and AR(1) process---------------- y(1) = 0; z(1) = 1; for i = 2:length(e) y(i) = e(i) - theta*e(i-1); z(i) = phi*z(i-1) + e(i); end %-----plotting MA(1) and AR(1) process---------------- subplot(2,1,1) plot(y,'r*-') subplot(2,1,2) plot(z,'b*-')

Using the above command, especially when we write the ‘ state’ option in line 8, it allows us to repeat our computation later. We can show the result of our computation tomorrow exactly the same as our computation we conduct today, even though our code involves a random number.  The result of the above command is plotted in the following figure.

Plotting the auto correlation function and introduction to bar command

In time series analysis, when we have a time series, it is common to plot the sample auto correlation function (ACF) to be compared to time series models we have in the textbooks. The thing is today, our students now rely heavily on statistical softwares to plot the ACF so that they forget how to plot it in the beginning.  Recall that the sample ACF of the observed series $Y_1, Y_2, \dots, Y_n$ is defined as

(1)——–$\displaystyle{r_k = \frac{\sum_{t=k+1}^{n}(Y_t - \bar{Y})(Y_{t-k}-\bar{Y})}{\sum_{t=1}^{n}(Y_t - \bar{Y})^2}}$

The following code shows a MATLAB code that will plot the ACF of both time series generated by the code above.

sumY = 0; sumZ = 0; for i = 1:length(y) sumY = sumY + y(i); sumZ = sumZ + z(i); end ybar = sumY/length(y); zbar = sumZ/length(z); sum2Y = 0; sum2Z = 0; for i = 1:length(y) sum2Y = sum2Y + (y(i)-ybar)^2; sum2Z = sum2Z + (z(i)-zbar)^2; end for k = 1:length(y) sum3Y = 0; sum3Z = 0; for t = k+1 : length(y) sum3Y = sum3Y + (y(t)-ybar)*(y(t-k)-ybar); sum3Z = sum3Z + (z(t)-zbar)*(z(t-k)-zbar); end ry(k) = sum3Y/sum2Y; rz(k) = sum3Z/sum2Z; end subplot(2,1,1); bar(ry); subplot(2,1,2); bar(rz);

The last two commands above will plot the ACF of time series $y$ and $z$ in the bar style as it is always for the ACF, as shown in the following figure.

It doesn’t show, really, the supposed to be acf of MA(1) (above) and AR(1) (below) process. Perhaps this is I have not learned  the sample acf measurement (1).

How to export/import data between Matlab and Excell

Finally, we are going to write a code in Matlab on how to export or import data to/from Excell in Matlab. Again, this is to save myself a few minutes rather than googling it around the internet.

%--------------write data to excell----------------------- y = transpose(y); z = transpose(z); filename = 'ma_ar_data.xlsx'; xlswrite(filename,y,1,'A1'); xlswrite(filename,z,1,'B1'); %-------------read data from excell---------------------- filename = 'ma_ar_data.xlsx'; sheet = 1; xlRange = 'A1:A100'; dataY = xlsread(filename, sheet, xlRange);

The transpose command above puts the variable $y$ generated before to be a column vector.

Conclusion

In this post, I have created various codes so that I am able to remember

• generating random numbers
• using subplot
• using histogram and bar
• exporting/importing data to/from excell
• plotting the ACF

## Liapunov exponent computation

Liapunov exponent method is one of the clever ways to investigate a certain dynamical system to be chaotic. In this post, I shall try to compute Liapunov exponent of one famous discrete dynamical system, i.e. the logistic map. After this, I shall try to compute the Liapunov exponent of a continuous dynamical system.

Actually, I write this post because I want to know how to numerically compute the Liapunov exponent. I often read a book or a website such as wolfram.alpha that shows the Liapunov exponent but it didn’t explain how to get this numerically. After I am able to post this post, and when I forget how to compute this exponent, I’d know where to look.

Suppose we have an initial condition $x_0$ and a nearby initial point $x_0 + \delta_0$, where $\delta_0$ is an initial difference between initial points, which by the way will be extremely small. These two nearby points will be iterated by some map. Let $\delta_n$ be the difference between these two points after n iterations. Consider the following equation

(1) …  $|\delta_n| =|\delta_0 |e^{n \lambda}$.

The coefficient $\lambda$ is called the Liapunov exponent. We want to compute this coefficient. Note that $\delta_n = f^n(x_0)-f^n(x_0+\delta_0)$, where $f$ is the given map. Taking logarithm of (1), we get

(2) … $\lambda = \frac{1}{n} \ln \left|\frac{\delta_n}{\delta_0}\right|=\frac{1}{n} \ln \left|\frac{f^n(x_0)-f^n(x_0+\delta_0)}{\delta_0}\right|=\frac{1}{n} \ln \left|{(f^n)'(x_0)}\right|$

as $\delta_0 \to 0$. The term inside the logarithm can be simplified by using the chain rule: $(f^n)'(x_0) = f'(x_{n-1}) f'(x_{n-2}) \dots f'(x_0)$. Thus (2) becomes

(3) … $\lambda = \frac{1}{n} \sum_{i=0}^{n-1} \ln |f'(x_i)|$.

When $n \rightarrow \infty$, $\lambda$ is defined as the Liapunov exponent. When this exponent is positive, it is a sign of a chaotic attractor.

Let us consider the logistic map that was in my previous post here. Let us fix the parameter value r. Starting at a random initial point, we will iterate the initial point until it reaches the steady state (which will be a fixed point, periodic or aperiodic), say 300 iterates. Now we compute a large number iterates, say 10000 and compute (3) starting from the 301st point. Repeat this procedure for the next r. Then we plot the Liapunov exponent with respect to r. We shall find a figure as follows.

As we can see from the above figure. The map is chaotic in some values of parameter between 3.5 to 4, in which the Liapunov exponent is positive.

The code to produce the above figure is the following

tic; %to compute how long is the computation clear;clc; %clear screem and clear all the previous variables a = 3:0.001:4; %parameter of the logistic map N = 300; %number of iterations until it is stable N1 = 10000; %number of iterations to compute the Liapunov exponent y = zeros(length(a),1); %declares variable for Liapunov exponents for i=1:length(a) x(1) = rand; %random initial conditions% for j = 2:N x(j) = a(i)*x(j-1)*(1-x(j-1)); end sum = 0; for j = 1:N1 x(N+j) = a(i)*x(N+j-1)*(1-x(N+j-1)); sum = sum + log(abs(a(i)-2*a(i)*x(N+j))); end y(i) = sum/10000; fprintf('%d %d\n',i,length(a)); end plot(a,0); hold on; plot(a,y); %plot Liapunov exponent against parameter toc; %display how long computation is clear


text:
# zoo

From zoo v1.0-3
0th

Percentile

##### Z's Ordered Observations

zoo is the creator for an S3 class of indexed totally ordered observations which includes irregular time series.

Keywords
ts
##### Usage
zoo(x, order.by = index(x), frequency = NULL)
## S3 method for class 'zoo':
print(x, style = , quote = FALSE, \dots)
##### Arguments
x
a numeric vector, matrix or a factor.
order.by
a vector by which the observations in x are ordered.
frequency
numeric indicating frequency of order.by. If specified, it is checked whether order.by and frequency comply. If so, a regular "zoo" series is returned, i.e., an object of class c("zoore
style
a string specifying the printing style which can be "horizontal" (the default for vectors), "vertical" (the default for matrices) or "plain" (which first prints first the data and then the index).
quote
logical. Should characters be quoted?
...
further arguments passed to the print methods of the data and the index.
##### Details

zoo provides infrastructure for ordered observations which are stored internally in a vector or matrix with an index attribute (of arbitrary class, see below). The index must have the same length as NROW(x) except in the case of a zero length numeric vector in which case the index length can be any length. Emphasis has been given to make all methods independent of the index/time class (given in order.by). In principle, the data x could also be arbitrary, but currently there is only support for vectors and matrices and partial support for factors.

zoo is particularly aimed at irregular time series of numeric vectors/matrices, but it also supports regular time series (i.e., series with a certain frequency). zoo's key design goals are independence of a particular index/date/time class and consistency with ts and base R by providing methods to standard generics. Therefore, standard functions can be used to work with "zoo" objects and memorization of new commands is reduced.

When creating a "zoo" object with the function zoo, the vector of indexes order.by can be of (a single) arbitrary class (if x is shorter or longer than order.by it is expanded accordingly), but it is essential that ORDER(order.by) works. For other functions it is assumed that c(), length(), MATCH() and subsetting [, work. If this is not the case for a particular index/date/time class, then methods for these generic functions should be created by the user. Note, that to achieve this, new generic functions ORDER and MATCH are created in the zoo package with default methods corresponding to the non-generic base functions order and match. Furthermore, for certain (but not for all) operations the index class should have an as.numeric method (in particular for regular series) and an as.character method might improve printed output (see also below).

If a frequency is specified when creating a series via zoo, the object returned is actually of class "zooreg" which inherits from "zoo". This is a subclass of "zoo" which relies on having a "zoo" series with an additional "frequency" attribute (which has to comply with the index of that series). Regular "zooreg" series can also be created by zooreg, the zoo analogue of ts. See the respective help page and is.regular for further details.

Methods to standard generics for "zoo" objects currently include: print (see above), summary, str, head, tail, [ (subsetting), rbind, cbind, merge (see merge.zoo), aggregate (see aggregate.zoo), barplot, plot and lines (see plot.zoo).

To prettify printed output of "zoo" series the generic function index2char is used for turning index values into character values. It defaults to using as.character but can be customized if a different printed display should be used (although this should not be necessary, usually).

The subsetting method [ work essentially like the corresponding functions for vectors or matrices respectively, i.e., takes indexes of type "numeric", "integer" or "logical". But additionally, it can be used to index with observations from the index class of the series. If the index class of the series is one of the three classes above, the corresponding index has to be encapsulated in I() to enforce usage of the index class (see examples).

Additionally, zoo provides several generic functions and methods to work (a) on the data contained in a "zoo" object, (b) the index (or time) attribute associated to it, and (c) on both data and index:

(a) The data contained in "zoo" objects can be extracted by coredata (strips off all "zoo"-specific attributes) and modified using coredata<-. Both are new generic functions with methods for "zoo" objects, see coredata.

(b) The index associated with a "zoo" object can be extracted by index and modified by index<-. As the interpretation of the index as time in time series applications is more natural, there are also synonymous methods time and time<-. The start and the end of the index/time vector can be queried by start and end. See index.

(c) To work on both data and index/time, zoo provides methods lag, diff (see lag.zoo) and window, window<- (see window.zoo).

In addition to standard group generic function (see Ops), the following mathematical operations are availabe as methods for "zoo" objects: transpose t which coerces to a matrix first, and cumsum, cumprod, cummin, cummax which are applied column wise.

Coercion to and from "zoo" objects is available for objects of various classes, in particular "ts", "irts" and "its" objects can be coerced to "zoo", the reverse is available for "its" and for "irts" (the latter in package tseries). Furthermore, "zoo" objects can be coerced to vectors, matrices and lists and data frames (dropping the index/time attribute). See as.zoo.

Four methods are available for NA handling in the data of "zoo" objects: na.omit which returns a "zoo" object with incomplete observations removed, na.locf which replaces NAs by the last previous non-NA, na.contiguous which extracts the longest consecutive stretch of non-missing values in a "zoo" object and na.approx which uses linear interpolation to fill in NA values.

A typical task to be performed on ordered observations is to evaluate some function, e.g., computing the mean, in a window of observations that is moved over the full sample period. The generic function rapply provides this functionality for arbitrary functions and more efficient versions rollmean, rollmax, rollmedian are available for the mean, maximum and median respectively.

##### Value

• A vector or matrix with an "index" attribute of the same dimension (NROW(x)) by which x is ordered.

zooreg, plot.zoo, index, merge.zoo

##### Aliases
• zoo
• range.zoo
• print.zoo
• as.zoo.factor
• summary.zoo
• str.zoo
• is.zoo
• [.zoo
• tail.zoo
• Ops.zoo
• t.zoo
• cumsum.zoo
• cumprod.zoo
• cummin.zoo
• cummax.zoo
• na.contiguous
• na.contiguous.data.frame
• na.contiguous.list
• na.contiguous.default
• na.contiguous.zoo
• index2char
• index2char.default
• index2char.numeric
• tail.ts
##### Examples
## simple creation and plotting
x.Date <- as.Date("2003-02-01") + c(1, 3, 7, 9, 14) - 1
x <- zoo(rnorm(5), x.Date)
plot(x)
time(x)

## subsetting with numeric indexes
x[c(2, 4)]
## subsetting with index class
x[as.Date("2003-02-01") + c(2, 8)]

## different classes of indexes/times can be used, e.g. numeric vector
x <- zoo(rnorm(5), c(1, 3, 7, 9, 14))
## subsetting with numeric indexes then uses observation numbers
x[c(2, 4)]
## subsetting with index class can be enforced by I()
x[I(c(3, 9))]

## visualization
plot(x)
## or POSIXct
y.POSIXct <- ISOdatetime(2003, 02, c(1, 3, 7, 9, 14), 0, 0, 0)
y <- zoo(rnorm(5), y.POSIXct)
plot(y)

## create a constant series
z <- zoo(1, seq(4)[-2])

## create a 0 dimensional zoo series
z0 <- zoo(, 1:4)

## create a 2 dimensional zoo series
z2 <- zoo(matrix(1:12, 4, 3), as.Date("2003-01-01") + 0:3)

## create a factor zoo object
fz <- zoo(gl(2,5), as.Date("2004-01-01") + 0:9)

## create a zoo series with 0 columns
z20 <- zoo(matrix(nrow = 4, ncol = 0), 1:4)

## arithmetic on zoo ojbects intersects them first
x1 <- zoo(1:5, 1:5)
x2 <- zoo(2:6, 2:6)
10 * x1 + x2

# ifelse does not work with zoo but this works
# to create a zoo object which equals x1 at
# time i if x1[i] > x1[i-1] and 0 otherwise
(diff(x1) > 0) * x1
Documentation reproduced from package zoo, version 1.0-3, License: GPL

### Community examples

Looks like there are no examples yet.

format: plain


text:
# Derivation of Slater-Koster equations

I am trying to derive the Slater-Koster equations (Table. 1 of Ref. 1) for the two-centre approximation of hopping integrals between atomic orbitals. I understand that Slater-Koster approximates the two centre hopping integral as:

$$begin{equation} E_{n,m} = int{psi^*_n (textbf{r}-textbf{R})Hpsi_m (textbf{r}) dV},tag{1} end{equation}$$

assuming that potential, $$V$$ is spherically symmetric.

I tried substituting spherical harmonics, $$Y_{lm}$$ as the atomic orbitals $$psi (textbf{r})$$ but I am struggling to get to the result. First, I am not sure how to write the spherical harmonics $$Y_{lm}$$ not centred at the origin. Then, I can’t see how the integral would separate into two parts representing pi and sigma bonds.

Does anyone know how to derive one of the Slater-Koster equations? For example:

$$begin{equation} E_{p_z, d_{x^2-y^2}} = frac{1}{2}sqrt{3}n(l^2-m^2) V_{pdsigma} -n(l^2-m^2) V_{pdpi},tag{2} end{equation}$$

where $$l,m$$ and $$n$$ are directional cosines of connecting vector $$textbf{R}$$ (i.e. $$l=sin{beta}cos{alpha}=frac{R_x}{R}$$).

References

1. Slater, JC & Koster, GF, "Simplified LCAO Method for the Periodic Potential Problem" Physical Review (1954); link: https://journals.aps.org/pr/abstract/10.1103/PhysRev.94.1498

Matter Modeling Asked on August 19, 2021

The answer by Anyon does not address how to calculate the form of the Slater-Koster two-center integrals (2CI) but rather how to determine the direction cosines that appear in the 2CI's (the $$l$$,$$m$$,$$n$$'s in things like $$sqrt{3}lm*(sdsigma)$$, but not the $$sqrt{3}$$). I am currently trying to explicitly perform the same calculation to include in my comps so I can sympathize with your frustration in the lack of clarity in the literature...

Any who, the most explicit reference I have found that explains how to actually calculate the SK-matrix elements is in this paper (Takegahara et al 1980 J. Phys. C: Solid State Phys. 13 583, Slater-Koster tables for f electrons) where Takegahara extends the original SK table to f electrons.

The fundamental strategy he invokes, which is very tedious, is to calculate the form of hopping elements along the bond direction and then rotate it into a generic orientation to make use of the l,m,n- direction cosines we are familiar with.

Sorry that this is less of an answer and more of a comment, I don't have enough reputation to post any other way.

Answered by user3282375 on August 19, 2021

Spherical harmonics are not themselves full atomic orbitals. Consider the Hydrogen wave function, which separates into a radial part and an angular part. The latter is a spherical harmonic, but the former is some other function (in the case of Hydrogen it's a Laguerre polynomial). In general, we can approximate the angular part for other atoms with the same spherical harmonics, but we usually don't know the radial part analytically. Hence, if you want to directly evaluate Eq. (1) by integration you also need to find the radial part somewhere. The strength of Slater's and Koster's work, however, is that we can avoid this problem entirely, by hiding all radial dependence in the Slater-Koster parameters (in your example they are $$V_{pdsigma}$$ and $$V_{pdpi}$$).

For simplicity, I'll focus on the case of an $$s$$-$$p$$ overlap. This simplifies the geometry, and will let me borrow pictures and notation from this thesis. Let's say we have an $$s$$ orbital at site $$i$$ with wave function $$psi_{is}$$, and a $$p_alpha$$ orbital at site $$j$$ with wave function $$psi_{jp_alpha}$$, where $$alpha in {x,y,z}$$. In Dirac's bra-ket notation, the overlap between them can be written $$E_{s,p_alpha}=langle psi_{is}|H_{2c}|psi_{jp_alpha}rangle = langle S|H_{2c}|P_alpharangle, tag{3}$$ where $$H_{2c}$$ is the two-center Hamiltonian, and we've introduced short-hand notation for the the two wave functions. Of course, behind the bra-ket notation you have exactly the kind of overlap integral shown in Eq. (1).

Next step is to work out the geometry. Let $$vec{r}$$ be the vector connecting sites $$i$$ and $$j$$, and let $$vec{d}$$ be a unit vector along the same direction. We decompose the $$p$$ orbital at site $$j$$ into components parallel to ($$sigma$$) and perpendicular to ($$pi$$) the vector $$vec{d}$$, as shown in this figure:

Figure from Anthony Carlson's 2006 MSc thesis at University of Minnesota.

In this notation, $$sigma$$ and $$pi$$ (and also $$delta$$) is used to denote the component of angular momentum about the axis $$vec{d}$$. $$sigma$$ means zero, $$pi$$ means $$1$$, etc. To proceed, we also define $$vec{a}$$ as pointing along the $$p$$ orbital, and $$vec{n}$$ as a vector perpendicular to $$vec{d}$$ in the plane spanned by $$vec{a}$$ and $$vec{d}$$. Then, the $$p$$ orbital (at site $$j$$) can be decomposed $$|P_alpharangle = vec{a}cdotvec{d}|P_sigmarangle + vec{a}cdotvec{n}|P_pirangle. tag{4}$$ Then, the overlap is simply $$langle S|H_{2c}|P_alpharangle = left( vec{a}cdot vec{d} right) langle S | H_{2c} |P_sigmarangle + left( vec{a}cdotvec{n} right) langle S | H_{2c} | P_pirangle, tag{5}$$ where the second term is zero by symmetry. Further, we can easily express this in terms of directional cosines since we can without loss of generality choose $$vec{a}$$ to be parallel to one of the coordinate axes. With $$d_x=frac{vec{r}cdothat{x}}{|vec{r}|},quad d_y=frac{vec{r}cdothat{y}}{|vec{r}|},quad d_z=frac{vec{r}cdothat{z}}{|vec{r}|}, tag{6}$$ we get $$langle S|H_{2c}|P_alpharangle = d_alpha langle S|H_{2c}|P_alpharangle = d_alpha V_{spsigma}, tag{7}$$ where all radial overlap is hidden in the parameter $$V_{spsigma}$$. In tight-binding models it's common to denote this overlap integral $$t_{spsigma}$$ if it occurs in a hopping term.

The same approach works for other orbital combinations. You just need to set up the geometry and coordinate systems properly, and know where the atomic orbitals point. (Admittedly this can become quite complicated in some systems, e.g. transition metal oxides.) Then the Slater-Koster parameters can be treated as tuning parameters - either tuned to explore possible phenomena in some system, or fit to reproduce some experiment or calculated band structure.

Answered by Anyon on August 19, 2021

## Related Questions

### I get this error in Gaussian09 even though I have enough memory. “Error termination in NtrErr: NtrErr called from FIOCnC.” Any suggestions?

1  Asked on January 5, 2022 by quantumx

### Why are single excitations ignored in the MP2 component of double hybrid functional calculations?

1  Asked on January 5, 2022

### Regarding oscillatory strength theoretical units to experimental ones

1  Asked on January 3, 2022

### How well can we model chemical synthesis?

3  Asked on January 1, 2022 by anyon

### Is it required to sample the full reaction coordinate in umbrella sampling?

1  Asked on January 1, 2022 by bnd

### How to find good universities for matter modeling?

1  Asked on December 25, 2021

### What does the Neighbor command do in LAMMPS?

1  Asked on December 22, 2021

### For software that does not support FCIDUMP format, what format is used and how can we get the software to interact with FCIDUMP integrals?

2  Asked on December 22, 2021

### How do the various programs read or write integrals in FCIDUMP format?

1  Asked on December 20, 2021

### Is there an anisotropy factor (g factor) for TDDFT absorption and circular dichroism calculations?

1  Asked on December 20, 2021 by c-alexander

### Why am I losing bonds when I use PACKMOL on two proteins?

1  Asked on December 20, 2021

### Can we “invert” Density Functional Theory through sufficiently accurate experiment?

1  Asked on December 18, 2021 by kfc

### How do you calculate the “true” chemical potential in classical density functional theory?

1  Asked on December 16, 2021

### Converging the potential of a dilute binary alloy system using the Coherent Potential Approximation. What troubleshooting options could I take?

1  Asked on December 16, 2021 by luphys

### The Hund’s J – Why can this be quantified?

1  Asked on December 16, 2021

### How accurate are the most accurate calculations?

1  Asked on December 13, 2021 by roman-korol

### Is there any software that can generate the electronic DOS of GaAs?

1  Asked on December 13, 2021

### Which Linux distribution is best for Matter Modeling?

9  Asked on December 11, 2021

### What is the role of a chemist in computational chemistry?

4  Asked on December 9, 2021 by georgios-karaiskakis

### How to deduce phase transitions from a phonon calculation?

2  Asked on December 9, 2021 by koroma


text:
# RZGate¶

class RZGate(phi, label=None)[source]

Single-qubit rotation about the Z axis.

This is a diagonal gate. It can be implemented virtually in hardware via framechanges (i.e. at zero error and duration).

Circuit symbol:

     ┌───────┐
q_0: ┤ Rz(λ) ├
└───────┘

Matrix Representation:

$\begin{split}RZ(\lambda) = exp(-i\frac{\lambda}{2}Z) = \begin{pmatrix} e^{-i\frac{\lambda}{2}} & 0 \\ 0 & e^{i\frac{\lambda}{2}} \end{pmatrix}\end{split}$

U1Gate This gate is equivalent to U1 up to a phase factor.

$U1(\lambda) = e^{i{\lambda}/2}RZ(\lambda)$

Reference for virtual Z gate implementation: 1612.00858

Create new RZ gate.

Attributes

 RZGate.decompositions Get the decompositions of the instruction from the SessionEquivalenceLibrary. RZGate.definition Return definition in terms of other basic gates. RZGate.label Return gate label RZGate.params return instruction params.

Methods

 RZGate.add_decomposition(decomposition) Add a decomposition of the instruction to the SessionEquivalenceLibrary. Assemble a QasmQobjInstruction RZGate.broadcast_arguments(qargs, cargs) Validation and handling of the arguments and its relationship. RZGate.c_if(classical, val) Add classical condition on register classical and value val. RZGate.control([num_ctrl_qubits, label, …]) Return a (mutli-)controlled-RZ gate. RZGate.copy([name]) Copy of the instruction. Return inverted RZ gate Return True .IFF. For a composite instruction, reverse the order of sub-gates. RZGate.power(exponent) Creates a unitary gate as gate^exponent. Return a default OpenQASM string for the instruction. Creates an instruction with gate repeated n amount of times. Return a Numpy.array for the gate unitary matrix.


text:
# Recent history for Dmitry hand me the Kalashnikov

5
years
ago
 edited a question Is it possible to have transformations...
5
years
ago
 posted a question Is it possible to have transformations...
5
years
ago
 question is edited Superficial degree of divergence on We...
5
years
ago
 received upvote on question Superficial degree of divergence on Weinberg
5
years
ago
 received upvote on question Superficial degree of divergence on Weinberg
5
years
ago
 edited a question Superficial degree of divergence on We...
5
years
ago
 edited a question Superficial degree of divergence on We...
5
years
ago
 edited a question Superficial degree of divergence on We...
5
years
ago
 posted a question Superficial degree of divergence on We...
5
years
ago
 received upvote on question Doubt while computing the second functional derivative of the Euclidean action of a point particle
5
years
ago
 question answered Doubt while computing the second functional derivative of the Euclidean action of a point particle
5
years
ago
 edited a question Doubt while computing the second funct...
5
years
ago
 question commented on Doubt while computing the second functional derivative of the Euclidean action of a point particle
5
years
ago
 posted a question Doubt while computing the second funct...
5
years
ago
 received upvote on comment Doubts about quark confinement, the pole mass and the quark gluon plasma
5
years
ago
 posted a comment Doubts about quark confinement, the pole mass and the quark gluon plasma
5
years
ago
 received upvote on question Why is it legitimate using bispinors in HQET?
5
years
ago
 question commented on Why is it legitimate using bispinors in HQET?
5
years
ago
 question answered Doubts about quark confinement, the pole mass and the quark gluon plasma
5
years
ago
 received upvote on question Doubts about quark confinement, the pole mass and the quark gluon plasma


text:
# A neat game shared by Tracy Johnston Zager

Saw this tweet from Tracy Johnston Zager earlier today:

The game looked fun, so I thought I’d turn it into a project with my younger son.

Also, as a note, I haven’t really studied much about games, but this game looks a lot like the game of Nim. It may even be exactly on online version of the game of Nim, I’m not sure. I didn’t look into Nim, though, rather I just watch my son play with this game.

I had him read through the rules while I set up the camera. Here are his initial attempts to play the game and his thoughts as he played. He begins to notice some losing positions and explores a few strategies to try to win.

In the second bit of the project I asked him to think about how to analyze this game. His first thought is to work backwards because he know the scenario with two piles of just one drop each is a losing situation if it is your turn.

He also thinks that watching how the computer plays would be good way to learn. The computer does seem to win a lot!

Then we got lucky – I was searching for a game with just two columns of drips and in the set up we found, he saw an easy way to win! It turns out the computer doesn’t win every time! Winning this game creates a few other ideas for how to win the two column game.

For the last part of the project we tried a few three column games. He tries out a few ideas at the beginning that turn out not to work. However, after a bit of experimenting he’s able to get a win!

So, a really fun game to play and a great game to get kids talking about strategy. I liked simplifying the game to two and three columns to narrow the potential strategies, but I’m sure that playing whatever board showed up on the screen would be fun, too.

# Divisor counting problems

Last night my older son asked me for a little help understanding divisor counting problems. He was struggling a little bit with that type of problem at his math club.

Luckily Art of Problem Solivng’s Introduction to Number Theory book has an entire section on divisor counting problems, so it wasn’t difficult at all to find some good problems. We worked through four of them.

Divisor counting is one of my favorite topics – I remember learning about it in high school and being amazed that you could know the number of factors of an integer without listing all of them. That, all by itself, is a neat basic counting idea. Another reason that I like the topic is that it helps me sneak in a little arithmetic practice with the kids, and you’ll see why I like that practice in the first two videos.

Here are the four problems:

(1) Find the number of positive divisors of 999,999.

(2) What is the sum of the three positive numbers less than 1,000 that have exactly 5 positive divisors?

(3) If $n$ has two prime divisors and 9 total divisors, how many divisors does $n^2$ have?

(4) How many divisors of 3,240 are (i) multiples of 3, and [separate question] (ii) how many are perfect squares?


text:
Suggested languages for you:
|
|

## All-in-one learning app

• Flashcards
• NotesNotes
• ExplanationsExplanations
• Study Planner
• Textbook solutions

# Algebraic Functions

You can have a mathematical problem involving both known and unknown values. For example, if you know that the age of your uncle John is twice your age plus four years, and you know that your age is 15, then you can use an algebraic function to work out the age of your uncle.

In this article, we will define what algebraic functions are, the different types of algebraic functions, how to identify algebraic and non-algebraic functions, touch on the differential calculus of algebraic functions, and work through some examples.

• What are algebraic functions?
• Types of algebraic functions
• Algebraic functions vs. non-algebraic functions
• Differential calculus with algebraic functions
• Graphing algebraic functions
• Algebraic functions example problems

## What are Algebraic Functions?

As we learned from our Functions article, there are many classes of functions. One of those classes is algebraic functions.

An Algebraic Function is a function that involves only the algebraic operations: addition, subtraction, multiplication, division, powers, and roots.

We created this class of functions when we allowed for quotients and fractional powers in polynomial functions. If it weren't for these allowances, we would simply have polynomial functions! These additions to the polynomial functions give rise to the types of algebraic functions:

• Polynomial functions
• Rational functions
• Power/Root functions
• This includes functions with fractional powers because they can be written as roots. For example:

### Examples of Algebraic Functions

Based on our definition of an algebraic function, let's list some examples of algebraic functions.

Again, note that algebraic functions include only the operations: , integer exponents and rational exponents.

## Types of Algebraic Functions

The image below shows the types of algebraic functions.

The types of algebraic functions – StudySmarter Originals

### Polynomial Functions

Algebraic functions can take on the form of Polynomial Functions:

Where,

• , , … , are all real number constants

• is a positive integer

Some examples of polynomial algebraic functions are:

• A linear function, like:

• A cubic function, like:

• A quintic function, like:

### Rational Functions

Algebraic functions can take on the form of Rational Functions:

Where,

• and are polynomials.

• .

Some examples of rational algebraic functions are:

### Power Functions

Algebraic functions can take on the form of Power Functions:

Where,

• and are any real numbers.

Some examples of power algebraic functions are:

• The reciprocal function: (note that this is also a rational function).

Be careful here! While they look similar, an exponential function like , is not a power function! Power functions must have the variable as the base, while exponential functions have the variable as the exponent.

#### Root Functions

A specific type of power function is the Root Function:

What makes this a special kind of power function?

• A root function is a power function with fractional exponents, where,

• is any real number.

• and are positive integers greater than 1.

• does not equal.

Some examples of root algebraic functions are:

## Algebraic Functions vs. Non-Algebraic Functions

So, if an algebraic function can include only the operations , exponents (and roots), then what about all those other functions we've learned about? Those are all non-algebraic functions!

Some examples of non-algebraic functions are:

• Trigonometric functions, like:

• Hyperbolic functions, like :

• Exponential functions, like :

• Logarithmic functions, like :

• Absolute value functions, like :

## Differential Calculus with Algebraic Functions

When it comes to graphing algebraic functions, sometimes we need to take Derivatives and Higher-Order Derivatives to find the critical points and inflection points of the graphs of these functions.

### Derivatives of Algebraic Functions – Critical Points

If we want to find the critical points on the graph of an algebraic function, we must know how to take the derivative of the function. This can be found in our article on Derivatives.

What is a critical point?

Let be an interior point in the domain of. We say that is a critical point of the function if:

1. exists and if either:
1. or
2. doesn't exist

f(c) MUST EXIST for x=c to be a critical point!

But what is a critical point, exactly?

Wherever we have a critical point of a function, there is either a horizontal tangent, a vertical tangent, a sharp turn, or a change in concavity at that point.

• If the critical point is , we have a horizontal tangent at that point. This means that either:
• The function has a maximum or minimum point at $$c$$.
• If we have $$f(x)=x^{2}$$, then $$f'(0)=0$$ and $$x=0$$ is a critical point. At this critical point, we have a horizontal tangent and an absolute minimum at $$x=0$$.If we have $$f(x)=x^{2}$$, then $$f'(0)=0$$ and $$x=0$$ is a critical point. At this critical point, we have a horizontal tangent and an absolute minimum at $$x=0$$. — StudySmarter Originals
• Or the function has an inflection point at $$c$$.
• If we have $$f(x)=x^{3}$$, then $$f'(0)=0$$ and $$x=0$$ is a critical point. At this critical point, we have a horizontal tangent and a change in concavity, but no minimum or maximum.If we have $$f(x)=x^{3}$$, then $$f'(0)=0$$ and $$x=0$$ is a critical point. At this critical point, we have a horizontal tangent and a change in concavity, but no minimum or maximum. — StudySmarter Originals
• If the critical point is , we have either:
• A vertical tangent at point $$c$$.
• If we have $$f(x)=x^{\frac{1}{3}}$$, then $$f'(0)=DNE$$ and $$x=0$$ is a critical point. At this critical point, we have a vertical tangent and a change in concavity.
• If we have $$f(x)=x^{\frac{1}{3}}$$, then $$f'(0)=DNE$$ and $$x=0$$ is a critical point. At this critical point, we have a vertical tangent and a change in concavity. — StudySmarter Originals
• Or a sharp turn at point $$c$$.
• If we have $$f(x)=\sqrt[3]{x^{2}}$$, then $$f'(0)=DNE$$ and $$x=0$$ is a critical point. At this critical point, we have a sharp turn and a change in concavity.
• If we have $$f(x)=\sqrt[3]{x^{2}}$$, then $$f'(0)=DNE$$ and $$x=0$$ is a critical point. At this critical point, we have a sharp turn and a change in concavity. — StudySmarter Originals

To find a critical point of a function, we follow these steps:

1. Find the Derivative of the function.

2. Set the derivative equal to 0.

1. Solve for x, if possible.

3. Find all values of x (if any) where the derivative is undefined.

4. All the values of x (if they are within the domain of the original function) found in steps 2 and 3 are the x-coordinates of the critical points.

• Find the y-values of the critical points by plugging the x-values into the original function and solving for the y-coordinate.

### Higher-Order Derivatives of Algebraic Functions – Inflection Points

If we want to find the inflection points on the graph of an algebraic function, we must know how to take the second derivative of the function. This can be found in our article on Higher-Order Derivatives.

What is an inflection point?

If is continuous at and changes concavity at , then the point is an inflection point of .

But what is an inflection point, exactly?

Wherever we have an inflection point on a function, that is where it changes from either:

• Convex to Concave, or
• Concave to Convex

And what do Concave and Convex mean? 1

• Convex (also called Concave Upward or Convex Downward) is when the slope of a function is increasing.

• Concave (also called Concave Downward or Convex Upward) is when the slope of a function is decreasing.

Note that the AP Calculus Exams (and likely your AP Calculus teacher) use the terms Concave Up and Concave Down.

The difference between concave up and concave down – StudySmarter Originals

So, how do we find where a function changes concavity?

• We find the second derivative of the function.

• If the second derivative of a function is positive, then it is Convex.

• If the second derivative of a function is negative, then it is Concave.

## Graphing Algebraic Functions

The graphs of all these types of algebraic functions vary widely from each other. However, the general procedure to graph an algebraic function is as follows:

1. Calculate the x-intercepts by setting and solving for x.

2. Calculate the y-intercepts by setting and solving for y.

3. Find and plot any asymptotes.

4. Find and plot any critical points.

5. Find and plot any inflection points.

6. Calculate some extra points along the curve until you get a good feel for how the curve looks.

7. Plot all these points and draw the curve that connects them.

Graph the function:

Solution:

1. Calculate the x-intercepts by setting and solving for x.

• can be replaced with.

• → set and cross-multiply to solve for.

• → There are no x-intercepts.

2. Calculate the y-intercepts by setting and solving for y.

• can be replaced with.

• → set and solve for.

• → you can't divide by 0! There are no y-intercepts.

3. Find and plot any asymptotes.

• Since the expression as, there is a horizontal asymptote at the line (the x-axis).

• Since the expression as, there is a vertical asymptote at the line (the y-axis).

4. Find and plot any critical points.

• Find the derivative of the function (check out our article on Derivatives for more info):

• Set the derivative equal to 0, and solve for x.

• → while the point where is a possible candidate for a critical point because , there are no critical points because we proved earlier that does not exist.

5. Find and plot any inflection points.

• Find the second derivative of the function (check out our article on Higher-Order Derivatives for more info):

• Set the second derivative equal to 0, and solve for x.

• → the second derivative is never 0, and it is undefined when. There are no inflection points because the original function is not defined at 0.

6. Calculate some extra points along the curve until you get a good feel for how the curve looks.

•  x 1/x -4 -1/4 -3 -1/3 -2 -1/2 -1 -1 0 undefined 1 1 2 1/2 3 1/3 4 1/4
7. Plot all these points and draw the curve that connects them.

• The graph of the reciprocal function 1/x – StudySmarter Originals

### Finding Domain and Range of Algebraic Functions

Finding the domain and range of algebraic functions depends on the type of algebraic function we are considering.

For polynomial functions:

• The domain for all polynomial functions is all real numbers:

• The range for polynomial functions depends on both the order of the polynomial and the y-values of the graph.

• If the order of the polynomial is odd, then the range is always .

• If the order of the polynomial is even, then the range depends on the minimum and/or maximum y-value(s).

Find the domain and range of the function:

Solution:

Since this is a polynomial function:

• The domain is all real numbers:.

To find the range, we recognize that this is the equation of a parabola. We can rewrite the equation in vertex form as:

Where,

• is the vertex of the parabola

Since the leading coefficient is positive, we know the parabola opens upward. This means the vertex is the lowest point of the parabola.

Therefore, the range is .

We can graph the function to double-check our work:

The graph of a polynomial function – StudySmarter Originals

For rational functions:

• Finding the domain of rational functions requires that we follow the rule that the denominator cannot equal 0.

• Finding the range of rational functions requires that we:

• First, solve the function for x

• Then, apply the rule that the denominator cannot equal 0.

Note that if the polynomials within the rational function have orders higher than 2, this process quickly becomes difficult. To find the range of rational functions whose orders are 3 or higher, we would need more differential analysis.

Find the domain and range of the function:

Solution:

Since this is a rational function, we must follow the rule that the denominator cannot equal 0. Therefore, the domain is the set of all real numbers except where the denominator equals 0.

• Domain:

To find the range, we need to find the values of y for which there exists a real number of x such that:

1. Multiply both sides of the equation by.
2. Move all terms with an x to the right of the equals sign. Move all terms without an x to the left of the equals sign.
3. Factor out the x on the right side of the equation.
4. Solve for x.
5. If, the equation has no solution because that would set the denominator equal to 0. Therefore, the range is:
• Range:

We can graph the function to double-check our work:

The graph of a rational function – StudySmarter Originals

For power/root functions:

• Both domain and range of power and root functions depend on the exponent. We need to analyze each function on a case-by-case basis, as the domain and range of these functions are pretty “sensitive” to changes in exponents.

Find the domain and range of the function:

Solution:

To find the domain:

1. Since this is a square root function, we need to keep what is inside the radical greater than or equal to 0.
• So, .
2. Factor what is under the radical.
• → this inequality holds only if both terms are positive or both terms are negative.
• For both terms positive:
• Therefore, must be part of the domain.
• For both terms negative:
• There are no values of x that can satisfy both of these inequalities.
3. Domain:

To find the range:

1. We use the domain to find the range:
• If the domain is , then .
• Therefore, .
2. Range:

We can graph the function to double-check our work:

The graph of a root function – StudySmarter Originals

## Algebraic Functions Example Problems

Which of the following are algebraic functions?

Solutions:

1. This is NOT an algebraic function.
2. This is an algebraic function.
3. This is NOT an algebraic function.
4. This is NOT an algebraic function.
5. This is an algebraic function.
6. This is an algebraic function.
7. This is an algebraic function.
8. This is an algebraic function.
9. This is NOT an algebraic function.
10. This is NOT an algebraic function.
11. This is an algebraic function.
12. This is an algebraic function.

Find the domain of each of the following:

Solutions:

1. We can't divide by 0, so the domain is the set of values of x such that .
• Domain:
2. Again, we can't divide by 0, so we need to determine the values of x where the denominator is 0.
1. for all real numbers of x.
• Domain:
3. Since the square root of a negative number is not a real number, we must determine the values of x that satisfy .
• Domain:
4. Here, the cube root is defined for all real numbers.
• Domain:

## Algebraic Functions – Key takeaways

• Algebraic functions include only the algebraic operations:
• Subtraction: -
• Multiplication:
• Division:
• Powers (aka exponents):, where is any real number
• Roots:, where is any real number and is a positive integer greater than 1.
• The types of algebraic functions are:
• Polynomial functions
• Rational functions
• Power/Root functions
• Any function that contains trigonometric functions, hyperbolic functions, logarithms, variables in the power (or exponent), or an absolute value is not an algebraic function.

## References

1. https://math.stackexchange.com/questions/2364116/how-to-remember-which-function-is-concave-and-which-one-is-convex/2364123#2364123

An algebraic function is a function that involves only the algebraic operations: addition, subtraction, multiplication, division, rational powers, and roots.

Two examples of algebraic functions are rational functions and root functions.

The types of algebraic functions are:

• Polynomial Functions
• Rational Functions
• Power/Root Functions

Solving algebraic functions usually involves finding their domains and/or ranges and graphing them.

Learning algebraic functions are important for several reasons:

• Helps you develop problem-solving skills
• Learn how to structure and organize problems
• Learn how to approach problems that have no solution
• Learn to think abstractly
• Learn to visualize situations

## Final Algebraic Functions Quiz

Question

What are the types of algebraic functions?

Polynomial functions

Show question

Question

What is a non-algebraic function?

Any function that involves something other than the algebraic operations of addition, subtraction, multiplication, division, powers, and roots is a non-algebraic function.

Show question

Question

What is the general procedure to graph an algebraic function?

1. Calculate the x-intercepts by setting y = 0 and solving for x.

2. Calculate the y-intercepts by setting x = 0 and solving for y.

3. Find and plot any asymptotes.

4. Find and plot any critical points.

5. Find and plot any inflection points.

6. Calculate some extra points along the curve until you get a good feel for how the curve looks.

7. Plot all these points and draw the curve that connects them.

Show question

Question

What rule do we need to follow to find the domain of a rational function?

Finding the domain of rational functions requires that we follow the rule that the denominator cannot equal 0.

Show question

Question

How do we find the critical points of an algebraic function?

To find a critical point of a function, we follow these steps:

1. Find the derivative of the function.

2. Set the derivative equal to 0.

1. Solve for x, if possible.

3. Find all values of x (if any) where the derivative is undefined.

4. All the values of x (if they are within the domain of the original function) found in steps 2 and 3 are the x-coordinates of the critical points.

• Find the y-values of the critical points by plugging the x-values into the original function and solving for the y-coordinate.

Show question

Question

What do Concave and Convex mean?

• Convex (also called Concave Upward or Convex Downward) is when the slope of a function is increasing.

• Concave (also called Concave Downward or Convex Upward) is when the slope of a function is decreasing.

Show question

Question

How do we find where a function changes concavity?

• We find the second derivative of the function.

• If the second derivative of a function is positive, then it is Convex.

• If the second derivative of a function is negative, then it is Concave.

Show question

60%

of the users don't pass the Algebraic Functions quiz! Will you pass the quiz?

Start Quiz

## Study Plan

Be perfectly prepared on time with an individual plan.

## Quizzes

Test your knowledge with gamified quizzes.

## Flashcards

Create and find flashcards in record time.

## Notes

Create beautiful notes faster than ever before.

## Study Sets

Have all your study materials in one place.

## Documents

Upload unlimited documents and save them online.

## Study Analytics

Identify your study strength and weaknesses.

## Weekly Goals

Set individual study goals and earn points reaching them.

## Smart Reminders

Stop procrastinating with our study reminders.

## Rewards

Earn points, unlock badges and level up while studying.

## Magic Marker

Create flashcards in notes completely automatically.

## Smart Formatting

Create the most beautiful study materials using our templates.


text:
# Multiplication of primitive roots

1. May 5, 2007

### trisacloon

Hi

I noticed that multiplication of all primitive roots modulo p ,p>3,
congruent to 1 modulo p...

I have tried some examples (13,17,19...) but i couldn't prove the general case
(let g1....gk be primitive roots modulo p,p>3 ==> g1*g2*...*gk=1(p))

I need help to prove or disprove it...

2. May 5, 2007

### Hurkyl

Staff Emeritus
Try multiplying them in a clever order.

3. May 6, 2007

### trisacloon

thanks for the replay

4. May 6, 2007

### robert Ihnot

I would suggest looking at detail, leave no stone unturned!

5. May 7, 2007

### trisacloon

I will rephrase my question...
How can i explain that if g is a primitive root then g^-1 is primitive root?

6. May 7, 2007

### Hurkyl

Staff Emeritus
I would have expected it to be straightforward, although I haven't worked it out explicitly.

Where, when proving the inverse of a primitive root is primitive, do you get stuck?

Last edited: May 7, 2007
7. May 7, 2007

### matt grime

It's a group. The order x and x^-1 are trivially shown to be the same.

8. May 7, 2007

### robert Ihnot

If 1/g^k ==1, Mod M, then of course, g^k==1 Mod M.


text:
# Dimensions of Newton's Law of Gravitation and Coloumb's Law

1. Nov 21, 2009

### Pinu7

As we know, Newton's Law of Gravitation is
$$${\mathbf{F}} = \frac{{Gm_1 m_2 }} {{r^2 }}$$$
and Coulomb's law is

$$${\mathbf{F}} = \frac{{Qq_1 q_2 }} {{r^2 }}$$$

We know from comparing the dimensions of the first equation that G, the gravitational constant, has the dimension
$$$[M^{ - 1} L^3 T^{ - 2} ]$$$

But for Coulomb's law, we assume Q is dimensionless. Why do we make this assumption?

2. Nov 21, 2009

### D H

Staff Emeritus
Where did you get the idea that Q (typically κ, not Q) is unitless?

Dimensional analysis tells you what the units for κ must be:

$$d(\kappa)=d(F)*d(r)^2/d(q)^2 = \frac{FL^2}{Q^2} = \frac{ML^3}{T^2Q^2}$$

where the d() extracts the dimensions of the quantity in question. This is not a dimensionless quantity. The only way it can be dimensionless is if charge is expressed in non-rational units, $$d(q) = \sqrt{ML^3}/T$$

See http://scienceworld.wolfram.com/physics/CoulombsConstant.html


text:
# Juan Carlos Torres

IRC nick(s): Jucato

Role in SMGL: Tome Scribe

Age/Birthdate: 25

Location/Country: Laguna, Philippines

## Common

When did you first start using Linux and why?

I started using GNU/Linux on January of 2006. It was actually the discovery of a free (as in beer) and open source 3D software (Blender) in 2005 that led me to research about a possible free and open alternative to Windows, which eventually led me to GNU/Linux. I won't be ashamed to admit that one, but not the only, reasons for switching back then was it's price. My other reason, which eventually supplanted that first one, is the freedom to configure it to my heart's delight, and even possibly code for it.

How long have you been using the SMGL distribution?

\$ cat /etc/sourcemage-release
Source Mage GNU/Linux 0.9.6.3 i486-pc-linux-gnu
Installed from CD using installer v. 0.9.6.3 on Mon Oct 15 06:19:06 PHT 2007

What piqued your interest in SMGL initially?

It was the magical theme that initially caught my attention, since I'm a fantasy/magic/RPG fan. Eventually, I learned that it used BASH for its package management, and that really added fuel to the fire. The "not immensely popular" and "small but active community" also made SMGL viable for me.

What future do you personally see for SMGL?

I do not see SMGL bursting into the distro scene in Ubuntu-like proportions, and I personally and selfishly prefer it that way (so maybe my prediction is colored by my preference?). That doesn't mean stagnation though. Sorcery and Grimoire are always growing, Justin "flux_control" Boffemmyer is on the verge of a Cauldron breakthrough, and the Tome team has been revived under the flag of Elisamuel "ryuji" Resto (cough). So I see a steady progress for SMGL. But who knows what crazy and exciting plans lurk in the minds of our mages?

Tell us a little bit about yourself. Education/Career/Skills?

I'm a philosopher by education, but not totally by heart. My first love was really computers and programming, and that's where I'm desperately trying to steer my life. Unfortunately, my only real work experience since I graduated in 2004 is a 3-month stint in one of those outsourced call centers. Anyway, I'm currently taking up my second degree, Computer Science, so hopefully that would lead to a career change.

As for my skills, I'm quite confident in my English skills (even if I'm not a native speaker) and I think I'm quite good at writing. I can do a bit of crude computer graphics, as well as do some desktop publishing/layouting or even web pages/sites. Dreaming to add "good programmer" to that list someday…

Any personal messages for the Source Mage users out there?

Persevere (when things don't go right). Don't be lazy (configure your system the way you like it). Learn and use the magic (learn how the system works and take advantage of it). But most of all, have fun!

What other OS programs/software have you worked on?

I've been a contributor to Kubuntu for more than a year, and I'm still currently and deeply involved in KDE, though not yet on the coding side.

## Flamewars

vi or emacs?

vi, but only because I learned it first. Trying to learn emacs at the moment, but the fingers get entangled quite a lot.

KDE or GNOME?

No contest. KDE.

BSD or GPL?

I don't really know…

## Strictly personal

Do you have any family?

Not a family of my own. Still living with my mom. Wished I had a cat..

What other hobbies?

Anime and Tennis. A bit of drawing/graphics here and there. Good (MMO)RPG's

What kind of car do you drive? Or what is your dream car?

No car, no dream. I'd prefer a big bike if I had a choice.


text:
Definition:Riemannian Metric

Definition

Consider a smooth manifold $\mathcal M$ on the real space $\R^n$.

A Riemannian metric on $\mathcal M$ is a metric $\mathrm d s$ between nearby points $\left({x_1, x_2, \ldots, x_n}\right)$ and $\left({x_1 + \mathrm d x_1, x_2 + \mathrm d x_2, \ldots, x_n + \mathrm d x_n}\right)$ by means of the quadratic differential form:

$\displaystyle \mathrm d s^2 = \sum_{i, j \mathop = 1}^n g_{i j} \, \mathrm d x_i \, \mathrm d x_j$

where each $g_{i j}$ is a suitable real-valued function of $x_1, \ldots, x_n$.

Different instances of $g_{i j}$ define different Riemannian geometries on the manifold under discussion.

A manifold with such a Riemannian metric applied is known as a Riemannian manifold.

Source of Name

This entry was named for Bernhard Riemann.

Historical Note

The concept of a Riemannian metric was originated by Bernhard Riemann in his trial lecture (published as Ueber die Hypothesen, welche der Geometrie zu Grande liegen) to apply for position of Privatdozent (unpaid lecturer) at Göttingen.


text:
Forced Driven oscillator

1. Dec 27, 2009

drszdrsz

1. The problem statement, all variables and given/known data

http://fatcat.ftj.agh.edu.pl/~i7zebrow/rysunek.jpg
tring constant is k,
object mass is $$M_{1}$$
Damping friction is b
and we wiggle the top end of spring in the above diagram with amount Asin(wt)
(Where A is a amplitude and w is a frequency).
2. Relevant equations
Spring Force:
$$Fs=-kx$$
Damping force is:
$$Fb=-b\frac{dx}{dt}$$
3. The attempt at a solution
I don't need full solution.I just looking for differential equation for this problem.My attempt is:
$$M_{1}\frac{d^{2}x}{dt^{2}}+b\frac{dx}{dt}+kx=Asin(\omega t)$$
I am sure about left side of the eguation but the right side is propably wrong I hope that someone can tell me where I made an mistake.

Last edited by a moderator: Apr 24, 2017
2. Dec 27, 2009

RoyalCat

Look at the dimensions, you are comparing force with distance. That is dimensionally inconsistent!

Consider the extension of the spring as a function of time, how does the oscillation of the end-point affect it? How does this translate into the force the spring exerts on the mass?

3. Dec 27, 2009

drszdrsz

Do you mean that the force of spring should looks like this:

$$Fs=-k(x-Asin(wt))$$
and now the differential equation will be:
$$M_{1}\frac{d^{2}x}{dt^{2}}+b\frac{dx}{dt}+kx=k*Asin( \omega t)$$
Now the differential is dimensionally consistent.But, is that correct??

Last edited: Dec 27, 2009
4. Dec 27, 2009

RoyalCat

That's how I would approach the problem, you might want to wait for confirmation from someone else that that's the way to go.

As for actually solving the differential equation, assume that the response, $$x(t)$$ is also a sinusoid. (Think about it, you're driving it at a certain frequency, why would it do anything but oscillate at that frequency?)

That is to say, assume a general solution of the form $$x(t)=B_0\sin{(\omega t)}$$ and then find $$B_0$$ and the conditions under which that is indeed a solution.

5. Dec 27, 2009

drszdrsz

Ok thanks a lot.

ps.
I'm not sure about solution. there mus be transitory solution too(otherwise the stationary solution that is sinusoid).

6. Dec 27, 2009

RoyalCat

To find the transient solution, all you need to do is add 0 to both sides! Remember that the sum of solutions is also a solution for such linear differential equations!
Do you remember doing this to find transients?

If not, this is how it's done (Very long and interesting lecture on the subject!):
http://ocw.mit.edu/OcwWeb/Physics/8-03Fall-2004/VideoLectures/detail/embed04.htm [Broken]

Last edited by a moderator: May 4, 2017
7. Jan 1, 2010