text:
# Betelgeuse will go supernova？？

1. Jul 26, 2009

### magnetar

2. Jul 26, 2009

### Astronuc

Staff Emeritus
Betelgeuse is being monitored.

Betelgeuse, Red Supergiant In Constellation Orion, Has Shrunk By 15 Percent In 15 Years
http://www.sciencedaily.com/releases/2009/06/090609220555.htm

Red giant star Betelgeuse mysteriously shrinking (UC Berkeley News)
http://berkeley.edu/news/media/releases/2009/06/09_betelim.shtml

Where do supernovae come from?

Two Dying Red Supergiant Stars Produced Supernovae
http://www.sciencedaily.com/releases/2009/03/090319142405.htm

AAVSO really needs to update this - http://www.aavso.org/vstar/vsots/1200.shtml [Broken]

Last edited by a moderator: May 4, 2017
3. Jul 28, 2009

### Chronos

Betelguese will someday go supernova, but, probably not today. The oscillations observed over the last century do not appear unusual for such a star. It will do should do this oscillation thing many times before it gives up the ghost. Best guess is it has at least a hundred million years left before the big event.

4. Jul 30, 2009

### magnetar

Last edited by a moderator: Apr 24, 2017
5. Jun 2, 2010

### Unix Ronin

My understanding is it is extremely unlikely Betengeuse will last that long. It's a gigantic star (the ninth largest known), burning through its fuel at a prodigious rate, and is believed to be significantly less than ten million years old. At this point in its stellar evolution, its chances of lasting another million years before it goes supernova are considered slim, and a hundred million years is almost certainly out of the question.

6. Jun 7, 2010

### brother time

I agree with this information however, many people think the supernova will occur in the next 1000 years. the star is about 640 light years away and is as Unix said, very old. It would be cool to see but we are unlikely to see it.
cheers, BT

7. Jun 9, 2010

### Orion1

Type II-P supernova

$$t_{L} = 11 \cdot 10^{9} \; \text{y}$$

$$\boxed{\tau_{rs} = t_{L} \left(\frac{m_{\odot}}{m_s} \right)^{2.47908}}$$

$$m_{\odot}$$ - solar mass
$$m_s$$ - stellar mass

Betelgeuse mass:
$$m_s = 18 \; m_{\odot}$$

Stellar lifetime for red supergiant star with Betelgeuse mass:
$$\boxed{\tau_{rs} = 8.501 \cdot 10^6 \; \text{y}}$$

Betelgeuse may explode in a type II supernova within the next thousand years.

Reference:
http://en.wikipedia.org/wiki/Betelgeuse#Fate"
http://en.wikipedia.org/wiki/Semiregular_variable_star" [Broken]

Last edited by a moderator: May 4, 2017
8. Jun 9, 2010

9. Jun 9, 2010

### Staff: Mentor

Re: Betelgeuse will go supernova??

Sorry, 10 million years in stellar terms is a newborn. 10 billion years would be a lot.

10. Jun 9, 2010

### brother time

It's a supergiant. they don't live very long.
cheers, BT

11. Jun 11, 2010

### nismaratwork

There is a lot about this class of star, and Betelgeuse in particular that is somewhat mysterious, including mass-loss. I think it's a bit hopeful to think it will explode within a thousand years, but your point with Borek is still valid; these stars do not live for 10 million years, never mind a billion. I think the best estimate of age is 8.5 million years, and it would be impressive if it saw 9 million.

format: plain


text:
1. Science
2. Chemistry
3. 20b confused me i thought my prediction was right but...

# Question: 20b confused me i thought my prediction was right but...

###### Question details

20b confused me. I thought my prediction was right, but I guess not. Please explain.


text:
# Math Help - Limit when x goes to infinity.

1. ## Limit when x goes to infinity.

I'm not completely sure if this goes under calculus or not (Norwegian system is a bit different)

Anyway, i was wondering if anyone could explain the methodology for solving this limit, as you see the answer should be 2, but i'm not getting that.

http://www3.wolframalpha.com/Calcula...s=4&w=130&h=40

And once i wrote it out it became more obvious, divide numerator and denominator by 3^(5x), then x-> unlimited, (2 + 0) / (1 + 0)

2. ## Re: Limit when x goes to infinity.

Yes, that is correct.


text:
# How to delete a hidden file in Java? [closed]

File[] hiddenFiles = directory.listFiles((FileFilter) HiddenFileFilter.HIDDEN);
for (File hiddenFile : hiddenFiles) {
String hidden = hiddenFile.getCanonicalPath();
File file = new File(hidden);
file.deleteOnExit();
}

I tried this one for deleting a hidden file but this one is not working. Is there any other solution?

## closed as off-topic by Biffen, user1492578, Alex K, smirkingman, Jonathan ArgentieroJan 12 '17 at 12:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – Biffen, John Bupit, smirkingman, Jonathan Argentiero
If this question can be reworded to fit the rules in the help center, please edit the question.

• what exactly is not working? does the program not find the hidden file or can it not delete said file? and if I had to guess I would say that you need to change new File("hiddenfile"); to new File(hidden); – Angry Red Panda Jan 12 '17 at 10:37
• @Guru Are you trying to delete hiddenFiles? That code comes nowhere near of achieving that. – Biffen Jan 12 '17 at 10:41
• Ya i changed. But still not working. – Guru Jan 13 '17 at 6:30
• @CaptainTreibholz I actually tried by giving the path as static. While uploading i removed the path. That created a confusion. new File("path\to\hiddenfile"); This is what i actually tried to ask. – Guru Jan 13 '17 at 6:43

There is no difference between deleting a hidden file and a regular file. It should all work well but in your case you are trying to delete file called "hiddenFile". I suggest you remove quotes.

File[] hiddenFiles = directory.listFiles((FileFilter) HiddenFileFilter.HIDDEN);
for (File hiddenFile : hiddenFiles) {
hidenFile.delete();
}
}

• I tried this already. I couldn't delete that. When i tried to print the result. The result is false. System.out.println( hiddenFile.delete()); = false – Guru Jan 13 '17 at 6:38
• The problem must be somewhere else; perhaps you have no permissions to delete it. I suggest you do a quick test; change your code to use NIO2/Files rather than java.io.File: try { java.nio.file.Files.delete(hiddenFile.toPath()); } catch (IOException e) { e.printStackTrace(); } It should allow you to print the error you have. Generally Oracle recommends using NIO2 (Files) rather than File for operations like this. Hope this helps. Some more read about NIO2 and deleting is here: docs.oracle.com/javase/tutorial/essential/io/delete.html – Witold Kaczurba Jan 13 '17 at 8:50
• java.nio.file.DirectoryNotEmptyException: path/to/file at sun.nio.fs.UnixFileSystemProvider.implDelete(UnixFileSystemProvider.java:242) at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103) at java.nio.file.Files.delete(Files.java:1079) at scrm.hidden.main(hidden.java:17) T – Guru Jan 13 '17 at 12:46
• Looks like you among the files you have a hidden directory that is not empty and you are trying to delete it. You can filter out directories using .isDirectory(). Or write an algorithm that reculsively deletes contents of it. There is good number of online examples how to do that. – Witold Kaczurba Jan 14 '17 at 18:22

You should use the path for accessing the file. Don't use File file = new File("hiddenfile"); but use File file = new File(hidden); since that is the directory path of your file.

• Ya i changed. But still not working. – Guru Jan 13 '17 at 6:30


text:
Journal topic
Mech. Sci., 11, 115–123, 2020
https://doi.org/10.5194/ms-11-115-2020
Mech. Sci., 11, 115–123, 2020
https://doi.org/10.5194/ms-11-115-2020

Research article 20 Apr 2020

Research article | 20 Apr 2020

# Dynamic modal analysis of double-sided meshing nutation drive with double circular arc spiral bevel gears

Dynamic modal analysis of double-sided meshing nutation drive with double circular arc spiral bevel gears
Zheng Lin1,2, Ligang Yao2, and Zhiyu Xie2 Zheng Lin et al.
• 1College of Mechanical and Electrical Engineering, Wuyi University, Wuyishan 354300, China
• 2School of Mechanical Engineering and Automation, Fuzhou University, Fuzhou 350116, China

Correspondence: Ligang Yao (ylgyao@fzu.edu.cn)

Abstract

In order to reduce the vibration of the double-sided meshing nutation drive with double circular arc spiral bevel gears, the dynamic modal of the nutation system is analyzed. The bending-torsional-axial coupling nonlinear dynamic model of the double-sided meshing nutation drive system with time-varying meshing stiffness, meshing damping, transmission error and tooth backlash is established, and the equation of motion of the system is derived. The natural frequencies and corresponding modal modes of the nutation system are calculated, and the effects of the average meshing stiffness of gears and the bearing support stiffness of nutation gears on the modal of the system are analyzed. The modal analysis of double circular arc spiral bevel gears is carried out, and the ten order natural frequencies and their corresponding modes are obtained. The results show that the nutation drive system and the double circular arc spiral bevel gears do not resonate during transmission.

1 Introduction

The bevel gear nutation transmission mechanism is a new type of coaxial transmission, which has the advantages of large transmission ratio, simple and compact structure, small volume and large bearing capacity (Lin et al., 2010), and has been widely used in various industrial equipment. Many experts and scholars have designed various types of nutation mechanisms and conducted corresponding research. Gupta and White (1975) studied the kinematics of the nutating mechanical drive and deduced the nutating unbalanced motion equation. Uzuka et al. (2009) designed different nutation motors based on the principle of nutation, including nutation magnetic motor, nutation air motor (Oda et al., 2010), etc., and also analyzing the magnetic field of the nutation magnetic motor (Kadota et al., 2013). Itzhak (2008) performed kinematics and kinetics of rotors and wobbling bodies in nutation drive. Nelson and Cipra (2005) studied the basic principles of nutating mechanisms and analyzed the respective characteristics of nutating gear mechanism and planetary gear mechanism. Huang et al. (2016) designed a novel non-contact nutation drive mechanism, and the experimental analysis was carried out. Fanghella et al. (2015, 2016) studied the kinematics, efficiency and dynamic balancing of planetary gear train based on nutating bevel gears and performed a balanced simulation analysis. Yao et al. (2010) designed a double circular arc spiral bevel gear nutation drive and a non-contact nutation drive mechanism, and derived the calculation formula of the nutation mechanism transmission ratio, and established the tooth surface meshing equations of different tooth profiles (Gu et al., 2006; Lin and Yao, 2012). The influence of machining error and assembly error on the characteristics of the nutation drive had been analyzed (Cai et al., 2017). Then the Mathematical modeling and characteristics analysis for the nutation gear drive based on error parameters had been established (Ji et al., 2016).

The double-sided meshing nutation drive of double circular arc spiral bevel gears is a new transmission system consisting of two pairs of double-arc spiral bevel gears meshed at different sides. External loads, time-varying meshing stiffness and gear tooth error will generate dynamic excitation to the system when working. Under the condition of high speed and heavy load, the system may produce severe vibration and noise. At present, the existing literature mainly studies the structure design, gear meshing analysis and strength analysis of nutation mechanism, while the research on the dynamics of double-sided meshing nutation drive with double-arc spiral bevel gears is rare.

In order to reveal the universal law of the dynamic characteristics of nutation drive system, this paper studies the non-linear dynamic modeling, derivation of equation of motion, system inherent modal and gear modal of double-sided meshing nutation drive system with double circular arc spiral bevel gears.

2 Dynamic modeling of double-sided meshing nutation drive

## 2.1 Dynamic model

The structure of double-side meshing nutation drive is shown in Fig. 1. It is mainly composed of four double circular arc spiral bevel gears, input horizontal axis and nutation eccentric sleeve. The input horizontal axis and nutation eccentric sleeve are fixed together and the angle θ between the central axis is nutation angle. When the mechanism moves, the motor drives the input horizontal axis and the nutation eccentric sleeve to rotate, thereby driving the internal bevel gears 1 and 3 which are fixed together to perform the nutating motion. The nutation internal bevel gears 1 and 3 are respectively meshed with the fixed external bevel gear 2 and output external bevel gear 4 on the left and right sides, and the power is output by the external bevel gear 4. The double-sided meshing nutation drive can be regarded as a planetary gear transmission with less tooth difference.

Figure 1The structure of double-side meshing nutation drive.

In the dynamic modeling of double-sided meshing nutation drive, the system model is simplified to some extent, and the following assumptions are made: (1) The friction of tooth surface during gear meshing is not considered; (2) The system damping is regarded as general viscous damping; (3) The influence of the error between axes on the system is neglected; (4) The deformation of shaft and bearings is not considered, and the bearing clearance is neglected; (5) When nutation gear 1 and nutation gear 3 are fixed together, they are regarded as a whole, gear 1 and gear 3 have the same degree of freedom, the vibration displacement of the two gears is the same, and there is no mutual torsion between the two gears; (6) The torsional pendulum vibration has less influence on the system, ignoring the torsional pendulum vibration.

Based on the above assumptions, the bending-torsion-axis coupling analysis model of the double-sided meshing nutation drive system is established by using the lumped parameter method, as shown in Fig. 2. The gears are regarded as lumped mass and lumped inertia, the supporting shaft is regarded as a rigid body without mass, and the elastic support of the bearing is simulated by spring and damper.

Figure 2Physical model of nutation drive.

In Fig. 2, Oxyz is a space meshing coordinate system, Ox0y0z0 is a follow-up coordinate system which rotates with nutation gears 1 and 3. The origins of the two coordinate systems coincide with the conical points of each bevel gear. T1 and T4 are input torque and load torque respectively. xi, yi and zi are the translational vibration displacements of the gears in the x, y and z directions respectively. The subscript i=13, 2, 4 respectively represent the nutation gears 1 and 3, fixed external bevel gear 2 and output external bevel gear 4. θi is the angular vibration displacement of each gear in the z direction. kik and Cik (i=13, 2, 4; k=x, y, z) are the support stiffness and support damping of each gear in three coordinate directions respectively. kmj, Cmj and enj(t) are the meshing stiffness, meshing damping and static transmission error of each gear pair. The subscript j=1, 2 respectively denote the gear pair 1 which is meshed by the fixed bevel gear 2 and the nutation bevel gear 1, and the gear pair 2 which is meshed by the output bevel gear 4 and the nutation bevel gear 3.

The generalized displacement array of the double-sided nutation drive system can be expressed as:

$\begin{array}{}\text{(1)}& \mathbit{X}={\left[{x}_{\mathrm{2}},\phantom{\rule{0.125em}{0ex}}{y}_{\mathrm{2}},\phantom{\rule{0.125em}{0ex}}{z}_{\mathrm{2}},\phantom{\rule{0.125em}{0ex}}{\mathit{\theta }}_{\mathrm{2}},\phantom{\rule{0.125em}{0ex}}{x}_{\mathrm{13}},\phantom{\rule{0.125em}{0ex}}{y}_{\mathrm{13}},\phantom{\rule{0.125em}{0ex}}{z}_{\mathrm{13}},\phantom{\rule{0.125em}{0ex}}{\mathit{\theta }}_{\mathrm{13}},\phantom{\rule{0.125em}{0ex}}{x}_{\mathrm{4}},\phantom{\rule{0.125em}{0ex}}{y}_{\mathrm{4}},\phantom{\rule{0.125em}{0ex}}{z}_{\mathrm{4}},\phantom{\rule{0.125em}{0ex}}{\mathit{\theta }}_{\mathrm{4}}\right]}^{\mathrm{T}}\end{array}$

## 2.2 Equation of motion

The relative displacements λn1 and λn2 along the normal direction of the meshing point due to vibration and error between the meshing points of the two bevel gears in the gear pairs 1 and 2 are represented as:

$\begin{array}{}\text{(2)}& \begin{array}{rl}{\mathit{\lambda }}_{n\mathrm{1}}& ={x}_{n\mathrm{1}}-{x}_{n\mathrm{2}}-{e}_{n\mathrm{1}}\left(t\right)\\ & ={a}_{\mathrm{11}}{x}_{\mathrm{13}}+{a}_{\mathrm{12}}{y}_{\mathrm{13}}+{a}_{\mathrm{13}}{z}_{\mathrm{13}}+{a}_{\mathrm{12}}{\mathit{\theta }}_{\mathrm{13}}{r}_{m\mathrm{1}}\\ & -\left({a}_{\mathrm{21}}{x}_{\mathrm{2}}+{a}_{\mathrm{22}}{y}_{\mathrm{2}}+{a}_{\mathrm{23}}{z}_{\mathrm{2}}+{a}_{\mathrm{22}}{\mathit{\theta }}_{\mathrm{2}}{r}_{m\mathrm{2}}\right)-{e}_{n\mathrm{1}}\left(t\right)\end{array}\end{array}$

$\begin{array}{}\text{(3)}& \begin{array}{rl}{\mathit{\lambda }}_{n\mathrm{2}}& ={x}_{n\mathrm{3}}-{x}_{n\mathrm{4}}-{e}_{n\mathrm{2}}\left(t\right)\\ & ={a}_{\mathrm{31}}{x}_{\mathrm{13}}+{a}_{\mathrm{32}}{y}_{\mathrm{13}}+{a}_{\mathrm{33}}{z}_{\mathrm{13}}+{a}_{\mathrm{32}}{\mathit{\theta }}_{\mathrm{13}}{r}_{m\mathrm{3}}\\ & -\left({a}_{\mathrm{41}}{x}_{\mathrm{4}}+{a}_{\mathrm{42}}{y}_{\mathrm{4}}+{a}_{\mathrm{43}}{z}_{\mathrm{4}}+{a}_{\mathrm{42}}{\mathit{\theta }}_{\mathrm{4}}{r}_{m\mathrm{4}}\right)-{e}_{n\mathrm{2}}\left(t\right)\end{array}\end{array}$

In Eqs. (2) and (3),

$\begin{array}{}\text{(4)}& \left\{\begin{array}{l}{a}_{\mathrm{11}}=-\mathrm{cos}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}{\mathit{\alpha }}_{n}+\mathrm{sin}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\right)\\ -\mathrm{sin}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}{\mathit{\delta }}_{\mathrm{1}}\mathrm{cos}{\mathit{\alpha }}_{n}-\mathrm{sin}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}{\mathit{\alpha }}_{n}\right)\\ {a}_{\mathrm{12}}={a}_{\mathrm{22}}={a}_{\mathrm{32}}={a}_{\mathrm{42}}=\mathrm{cos}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\\ {a}_{\mathrm{13}}=\mathrm{sin}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}{\mathit{\alpha }}_{n}+\mathrm{sin}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\right)\\ -\mathrm{cos}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}{\mathit{\delta }}_{\mathrm{1}}\mathrm{cos}{\mathit{\alpha }}_{n}-\mathrm{sin}{\mathit{\delta }}_{\mathrm{1}}\mathrm{sin}{\mathit{\alpha }}_{n}\right)\\ {a}_{\mathrm{21}}=-\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{2}}\mathrm{sin}{\mathit{\alpha }}_{n}+\mathrm{sin}{\mathit{\delta }}_{\mathrm{2}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\right)\\ {a}_{\mathrm{23}}=\mathrm{sin}{\mathit{\delta }}_{\mathrm{2}}\mathrm{sin}{\mathit{\alpha }}_{n}-\mathrm{cos}{\mathit{\delta }}_{\mathrm{2}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\\ {a}_{\mathrm{31}}=-\mathrm{cos}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}{\mathit{\alpha }}_{n}+\mathrm{sin}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\right)\\ -\mathrm{sin}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}{\mathit{\delta }}_{\mathrm{3}}\mathrm{cos}{\mathit{\alpha }}_{n}-\mathrm{sin}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}{\mathit{\alpha }}_{n}\right)\\ {a}_{\mathrm{33}}=\mathrm{sin}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}{\mathit{\alpha }}_{n}+\mathrm{sin}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\right)\\ -\mathrm{cos}\mathit{\theta }\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}{\mathit{\delta }}_{\mathrm{3}}\mathrm{cos}{\mathit{\alpha }}_{n}-\mathrm{sin}{\mathit{\delta }}_{\mathrm{3}}\mathrm{sin}{\mathit{\alpha }}_{n}\right)\\ {a}_{\mathrm{41}}=-\left(\mathrm{cos}{\mathit{\delta }}_{\mathrm{4}}\mathrm{sin}{\mathit{\alpha }}_{n}+\mathrm{sin}{\mathit{\delta }}_{\mathrm{4}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\right)\\ {a}_{\mathrm{43}}=\mathrm{sin}{\mathit{\delta }}_{\mathrm{4}}\mathrm{sin}{\mathit{\alpha }}_{n}-\mathrm{cos}{\mathit{\delta }}_{\mathrm{4}}\mathrm{sin}\mathit{\beta }\mathrm{cos}{\mathit{\alpha }}_{n}\end{array}\right\,\end{array}$

where, δi (i=1, 2, 3, 4) is the pitch cone angle of each bevel gear, β is the helical angle, αn is the normal pressure angle, rmi (i=1, 2, 3, 4) is the radius at the meshing point of each gear.

The normal dynamic load of gear pair in meshing can be expressed as,

$\begin{array}{}\text{(5)}& {F}_{nj}={k}_{mj}\left(t\right)f\left({\mathit{\lambda }}_{nj}\right)+{C}_{mj}{\stackrel{\mathrm{˙}}{\mathit{\lambda }}}_{nj},\end{array}$

where, j=1, 2 represent the gear pairs 1 and 2, kmj(t) represent time-varying meshing stiffness of gear pairs, f(λnj) represent clearance function.

The clearance function is as follows:

$\begin{array}{}\text{(6)}& f\left({\mathit{\lambda }}_{nj}\right)=\left\{\begin{array}{ll}{\mathit{\lambda }}_{nj}-{b}_{j}/\mathrm{2}& {\mathit{\lambda }}_{nj}>{b}_{j}/\mathrm{2}\\ \mathrm{0}& \left|{\mathit{\lambda }}_{nj}\right|\le {b}_{j}\\ {\mathit{\lambda }}_{nj}+{b}_{j}/\mathrm{2}& {\mathit{\lambda }}_{nj}<-{b}_{j}/\mathrm{2}\end{array}\right\,\end{array}$

where, bj (j=1, 2) is the tooth backlash of each gear pair.

Considering the time-varying meshing stiffness, transmission error, meshing damping and tooth backlash, the dynamic differential equations of double-sided meshing nutation drive system are obtained as,

$\begin{array}{}\text{(7)}& \left\{\begin{array}{l}{m}_{\mathrm{2}}{\stackrel{\mathrm{¨}}{x}}_{\mathrm{2}}+{C}_{\mathrm{2}x}{\stackrel{\mathrm{˙}}{x}}_{\mathrm{2}}+{k}_{\mathrm{2}x}{x}_{\mathrm{2}}+{a}_{\mathrm{21}}{F}_{n\mathrm{1}}=\mathrm{0}\\ {m}_{\mathrm{2}}{\stackrel{\mathrm{¨}}{y}}_{\mathrm{2}}+{C}_{\mathrm{2}y}{\stackrel{\mathrm{˙}}{y}}_{\mathrm{2}}+{k}_{\mathrm{2}y}{y}_{\mathrm{2}}+{a}_{\mathrm{22}}{F}_{n\mathrm{1}}=\mathrm{0}\\ {m}_{\mathrm{2}}{\stackrel{\mathrm{¨}}{z}}_{\mathrm{2}}+{C}_{\mathrm{2}z}{\stackrel{\mathrm{˙}}{z}}_{\mathrm{2}}+{k}_{\mathrm{2}z}{z}_{\mathrm{2}}+{a}_{\mathrm{23}}{F}_{n\mathrm{1}}=\mathrm{0}\\ {J}_{\mathrm{2}}{\stackrel{\mathrm{¨}}{\mathit{\theta }}}_{\mathrm{2}}+{a}_{\mathrm{22}}{F}_{n\mathrm{1}}{r}_{m\mathrm{2}}={T}_{\mathrm{1}}\\ {m}_{\mathrm{13}}{\stackrel{\mathrm{¨}}{x}}_{\mathrm{13}}+\mathrm{2}{C}_{\mathrm{13}x}{\stackrel{\mathrm{˙}}{x}}_{\mathrm{13}}+\mathrm{2}{k}_{\mathrm{13}x}{x}_{\mathrm{13}}\\ -{a}_{\mathrm{21}}{F}_{n\mathrm{1}}+{a}_{\mathrm{41}}{F}_{n\mathrm{2}}=\mathrm{0}\\ {m}_{\mathrm{13}}{\stackrel{\mathrm{¨}}{y}}_{\mathrm{13}}+\mathrm{2}{C}_{\mathrm{13}y}{\stackrel{\mathrm{˙}}{y}}_{\mathrm{13}}+\mathrm{2}{k}_{\mathrm{13}y}{y}_{\mathrm{13}}\\ -{a}_{\mathrm{22}}{F}_{n\mathrm{1}}+{a}_{\mathrm{42}}{F}_{n\mathrm{2}}={L}_{\mathrm{1}}/{r}_{m\mathrm{1}}+{L}_{\mathrm{3}}/{r}_{m\mathrm{3}}\\ {m}_{\mathrm{13}}{\stackrel{\mathrm{¨}}{z}}_{\mathrm{13}}+\mathrm{2}{C}_{\mathrm{13}z}{\stackrel{\mathrm{˙}}{z}}_{\mathrm{13}}+\mathrm{2}{k}_{\mathrm{13}z}{z}_{\mathrm{13}}\\ -{a}_{\mathrm{23}}{F}_{n\mathrm{1}}+{a}_{\mathrm{43}}{F}_{n\mathrm{2}}=\mathrm{0}\\ {J}_{\mathrm{13}}{\stackrel{\mathrm{¨}}{\mathit{\theta }}}_{\mathrm{13}}-{a}_{\mathrm{22}}{F}_{n\mathrm{1}}{r}_{m\mathrm{1}}+{a}_{\mathrm{42}}{F}_{n\mathrm{2}}{r}_{m\mathrm{3}}=\mathrm{0}\\ {m}_{\mathrm{4}}{\stackrel{\mathrm{¨}}{x}}_{\mathrm{4}}+{C}_{\mathrm{4}x}{\stackrel{\mathrm{˙}}{x}}_{\mathrm{4}}+{k}_{\mathrm{4}x}{x}_{\mathrm{4}}-{a}_{\mathrm{41}}{F}_{n\mathrm{2}}=\mathrm{0}\\ {m}_{\mathrm{4}}{\stackrel{\mathrm{¨}}{y}}_{\mathrm{4}}+{C}_{\mathrm{4}y}{\stackrel{\mathrm{˙}}{y}}_{\mathrm{4}}+{k}_{\mathrm{4}y}{y}_{\mathrm{4}}-{a}_{\mathrm{42}}{F}_{n\mathrm{2}}=\mathrm{0}\\ {m}_{\mathrm{4}}{\stackrel{\mathrm{¨}}{z}}_{\mathrm{4}}+{C}_{\mathrm{4}z}{\stackrel{\mathrm{˙}}{z}}_{\mathrm{4}}+{k}_{\mathrm{4}z}{z}_{\mathrm{4}}-{a}_{\mathrm{43}}{F}_{n\mathrm{2}}=\mathrm{0}\\ {J}_{\mathrm{4}}{\stackrel{\mathrm{¨}}{\mathit{\theta }}}_{\mathrm{4}}-{a}_{\mathrm{42}}{F}_{n\mathrm{2}}{r}_{m\mathrm{4}}=-{T}_{\mathrm{4}}\end{array}\right\,\end{array}$

where, mi and Ji (i=13, 2, 4) are the lumped mass and moment of inertia of each gear; L1 and L3 are the gyroscopic moments generated by nutation motion of two nutation bevel gears, and the direction is along the axis Oy.

## 2.3 Meshing stiffness analysis

In the meshing process of double circular arc spiral bevel gears, meshing stiffness varies with the number of meshing points of convex and concave teeth, and the meshing stiffness has time-varying. By using the finite element contact analysis, the contact force and deformation of the gear teeth in the meshing period are obtained. Then the meshing stiffness values of gear pairs at different times are calculated, and these discrete points are connected by straight lines, as shown in Fig. 3.

Figure 3Fitting curve of time-varying meshing stiffness. (a) Meshing stiffness of the gear pair 1. (b) Meshing stiffness of the gear pair 2.

In order to transform the time-varying meshing stiffness broken line into a continuous function curve with time as independent variable, the time-varying meshing stiffness kmj(t) is fitted into Fourier progression form.

$\begin{array}{}\text{(8)}& {k}_{mj}\left(t\right)={k}_{mj}+\sum _{r=\mathrm{1}}^{l}{k}_{rj}\mathrm{cos}\left(r{\mathit{\omega }}_{mj}t+{\mathit{\phi }}_{rj}\right),\end{array}$

where, kmj is the average meshing stiffness of the gear pair, r (r=1, 2, …, l) is the order of Fourier expansion harmonic term, krj is the stiffness amplitude of the r order harmonic component of the gear pair, ωmj is the meshing angular frequency, φrj is the meshing phase of the r order harmonic component.

To simplify the calculation, the curve of time-varying meshing stiffness is obtained by fitting the 7th order Fourier progression as shown by the red dotted line in Fig. 3. And the average meshing stiffness of the gear pair 1 is calculated as ${k}_{m\mathrm{1}}=\mathrm{2.1168}×{\mathrm{10}}^{\mathrm{8}}$ N m−1, and the average meshing stiffness of the gear pair 2 is ${k}_{m\mathrm{2}}=\mathrm{2.2229}×{\mathrm{10}}^{\mathrm{8}}$ N m−1.

3 Modal analysis of nutation drive system

## 3.1 Inherent characteristics of system

Theoretical modal analysis solves the inherent characteristics of the system, i.e. the natural frequency and the modal shape. Therefore, the influence of external loads can be neglected, and the damping term can also be neglected because the influence of damping is small. Thus, the free equation of motion of double-sided meshing nutation drive can be established.

$\begin{array}{}\text{(9)}& \mathbf{M}\stackrel{\mathrm{¨}}{\mathbf{X}}+\mathbf{KX}=\mathrm{0},\end{array}$

where, the mass matrix M=diag (m2, m2, m2, J2, m13, m13, m13, J13, m4, m4, m4, J4), the stiffness matrix K is a 12 by 12 matrix, which is not listed in the text due to limited space.

The intrinsic characteristics of the nutation drive system are solved in the MATLAB software, and the eig command is used to solve the problem. In solving the free equation of motion of nutation drive system, the average meshing stiffness of two pairs of gears is used to calculate the natural frequencies and modal shapes of nutation drive system. The parameters of bevel gears of nutation drive solved in this paper are shown in Table 1. The values of support stiffness and support damping of nutation drive system are shown in Table 2.

Table 1The parameter of bevel gears.

Table 2The parameter of support stiffness and damping.

The natural frequencies of the double-sided meshing nutation drive are calculated as shown in Table 3, and the corresponding modal shapes are shown in Fig. 4. The degrees of freedom 1 to 4 are the degrees of freedom of the fixed external bevel gear 2, the degrees of freedom of 5 to 8 are the degrees of freedom of the nutation bevel gears 1 and 3, and the degrees of freedom of 9 to 12 are the degrees of freedom of the output external bevel gear 4. The natural frequency of the first 5th order of the nutation drive system is small, the natural frequency after the sixth stage is large, and the natural frequencies span of the system is also large. In general, the natural frequencies of the first to tenth order have a greater impact on the system. There is a natural frequency double root solution in the system, that is, the natural frequency values of the 4th and 5th order both are 7880 Hz.

Figure 4Modal shape of each order natural frequency.

Table 3Natural frequencies of nutation drive.

## 3.2 Influence of meshing stiffness and bearing support stiffness on modal

In order to analyze the influence of meshing stiffness on modal, the natural frequencies of nutation drive system are calculated by taking the average meshing stiffness of two pairs of gears as 150 %, 200 % and 250 % of the original average meshing stiffness kmj (j=1, 2). The natural frequencies of nutation system with different average meshing stiffness are shown in Fig. 5.

Figure 5Natural frequency with different average meshing stiffness.

Figure 5 shows that the average meshing stiffness has a great influence on the high order natural frequencies, and mainly affects the natural frequencies of the 10th, 11th and 12th order. The average meshing stiffness has little effect on the lower order, only the natural frequencies of the 5th and 7th order increase slightly. The lower order of natural frequencies have great influence on the system, so the change of average meshing stiffness has little influence on the nutation drive system.

Considering that there are two nutation gears in nutation drive system to make the nutation movement, the natural frequencies of nutation drive system are calculated by taking the bearing support stiffness of nutation gears as 150 %, 200 % and 250 % of the original support stiffness. The comparison of natural frequencies of nutation system under different bearing supporting stiffness of nutation gears is shown in Fig. 6.

Figure 6Natural frequency with different bearing support stiffness of nutation gears.

It can be seen from Fig. 6 that the bearing support stiffness of nutation gears has a great influence on the natural frequency of intermediate order, especially on the sixth and seventh order. However, the bearing support stiffness of the nutation gears has little influence on the low-order and high-order, and the natural frequencies of the 10th to 12th order remain unchanged with different bearing supporting stiffness of nutation gears.

4 Modal analysis of double circular arc spiral bevel gears

Using ANSYS Workbench software to analyze the modal of double circular arc spiral bevel gears, the first ten natural frequencies and corresponding vibration modes of double circular arc spiral bevel gears can be obtained. In this paper, the material of double circular arc spiral bevel gear is set as structural steel, elastic modulus E is 206 GPa, Poisson's ratio is 0.29, mass density is 7850 kg m−3. The mesh models of double circular arc spiral bevel gears 1 and 2 are shown in Fig. 7.

Figure 7The mesh models of double circular arc spiral bevel gears.

Figure 8The 1st and 2nd order modes of bevel gear 1: torsional vibration.

By setting the order of modal solution and solving the modal of bevel gears, the vibration mode diagrams of double circular arc spiral bevel gears can be obtained. Taking the vibration mode diagram of internal bevel gear 1 as the example, the 1st and 2nd order modes are torsional vibration, and the end face of bevel gear oscillates back and forth along the radial straight line passing through the axis, as shown in Fig. 8.

Figure 9The 3rd and 4th order modes of bevel gear 1: folding vibration.

Figure 10The 5th order mode of bevel gear 1: umbrella type vibration.

Figure 11The 6th order mode of bevel gear 1: circumferential vibration.

The 3rd and 4th order modes of the internal bevel gear 1 are folding vibration. The bevel gear 1 appears as V-shaped along the axis, and the regular polygon on the end face, as shown in Fig. 9.

The 5th order mode of the internal bevel gear 1 is an umbrella type vibration, and the bevel gear teeth are contracted into an umbrella shape along the large end in the axial direction, as shown in Fig. 10.

The 6th order mode of the internal bevel gear 1 is a circumferential vibration, as shown in Fig. 11. The bevel gear has substantially no vibration and displacement in the axial direction, and a circumferential vibration on the end face.

The 7th and 8th order modes of the internal bevel gear 1 are bending vibration. The regular wave pattern appears in the axial direction of the gear, and the regular polygon appears on the end face, as shown in Fig. 12.

The 9th and 10th order modes of internal bevel gear 1 are radial vibration, as shown in Fig. 13. The bevel gear expands and contracts along the radial direction. The end face appears elliptical mode of vibration, and there is basically no vibration in the axial direction.

Figure 12The 7th and 8th order modes of bevel gear 1: bending vibration.

Figure 13The 9th and 10th order modes of bevel gear 1: radial vibration.

The natural frequencies and vibration modes of four bevel gears are obtained as shown in Table 4. It can be seen from Table 4 that the first and second order modes of the four bevel gears are torsional vibration, the intermediate-order modes are umbrella type vibration, folding vibration and circumferential vibration, and the high-order modes is bending vibration and radial vibration. When the frequencies of adjacent orders of the same gear are similar, the vibration modes are basically the same.

Table 4Natural frequencies and vibration modes of bevel gears.

Table 5Comparison of low-order natural frequencies between nutation drive system and bevel gears.

At low-order (1–5th order), the comparison between the natural frequency of nutation drive system obtained by numerical solution and the natural frequencies of four bevel gears obtained by finite element analysis is shown in Table 5. The natural frequencies of bevel gears 1 and 3 are smaller than those of bevel gears 2 and 4, and the natural frequencies of bevel gears 2 are the largest. Because gears 1 and 3 are connected together and the structural parameter values of gears are close, the increasing law of natural frequencies of each order is similar. At the same time, it can be seen from table 5 that the low-order natural frequencies of the four bevel gears are different from the natural frequencies of the nutation drive system, so the double-sided meshing nutation drive with double circular arc spiral bevel gears generally does not produce resonance.

5 Conclusions

The bending-torsional-axial coupling nonlinear dynamic model of double-sided meshing nutation drive system has been established, which includes time-varying meshing stiffness, meshing damping, transmission error, tooth clearance and other factors. And then the equation of motion of the double-sided meshing nutation drive system is derived.

The natural frequencies and corresponding modal modes of the nutation drive system are calculated according to the free equation of motion. The influence of the meshing stiffness and bearing support stiffness of nutation gears on the modal of nutation drive are analyzed. The results show that the average meshing stiffness mainly affects the high-order natural frequencies of nutation drive system, while the bearing support stiffness of nutation gears mainly affects the low-order natural frequencies of nutation drive system.

The modal analysis of the double circular spiral bevel gear is carried out, and the first ten natural frequencies of the double circular spiral bevel gear and their corresponding vibration modes are obtained. The natural frequencies of nutation drive system and double circular arc spiral bevel gears are different, and there is no resonance.

Data availability
Data availability.

All data included in this study are available upon request by contact with the corresponding author.

Author contributions
Author contributions.

LY proposed the idea and methodology. ZL and ZX applied the methodology, performed analytical solutions. ZL surveyed the literature and wrote the paper.

Competing interests
Competing interests.

The authors declare that they have no conflict of interest.

Financial support
Financial support.

This research has been supported by the National Natural Science Foundation of China (grant no. 51775114), the Fujian Provincial Industrial Robot Basic Components Technology Research and Development Center (grant no. 2014H21010011), and the Fujian Provincial Young and Middle-aged Teacher Education and Scientific Research (grant nos. JAT160510 and JAT190777).

Review statement
Review statement.

This paper was edited by Ali Konuralp and reviewed by two anonymous referees.

References

Cai, Y. W., Yao, L. G., Xie, Z. Y., and Zhang, J.: Influence analysis of system parameters on characteristics of the nutation drive with double circular arc spiral bevel gears, Forsch. Ingenieurwes., 81, 125–133, https://doi.org/10.1007/s10010-017-0245-x, 2017.

Fanghella, P., Bruzzone, L., and Ellero, S.: Dynamic balancing of a nutating planetary bevel gear train, Mech. Mach. Sci., 25, 23–33, https://doi.org/10.1007/978-3-319-09858-6_3, 2015.

Fanghella, P., Bruzzone, L., and Ellero, S.: Kinematics, efficiency and dynamic balancing of a planetary gear train based on nutating bevel gears, Mech. Based Des. Struc., 44, 72–85, https://doi.org/10.1080/15397734.2015.1047956, 2016.

Gu, B., Yao, L. G., Wei, G. W., Cai, Y. J., and Dai, J. S.: The analysis and modeling for nutation drives with double circular-arc helical bevel gears, Mater. Sci. Forum, 505–507, 949–954, https://doi.org/10.4028/www.scientific.net/MSF.505-507.949, 2006.

Gupta, P. K. and White, H. V.: On the kinematics of a nutating mechanical drive, J. Appl. Mech, 42, 507–509, https://doi.org/10.1115/1.3423617, 1975.

Huang, D. J., Ding, S. H., Su, X. L., Qiu, J. W., Liu, Z. W., Shi, L. S., and Yao, L. G.: Design and experimental analysis for a novel non-contact nutation drive mechanism, Journal of Fujian University of Technology, 14, 51–54, https://doi.org/10.3969/j.issn.1672-4348.2016.01.012, 2016.

Itzhak, G.: On the kinematics and kinetics of mechanical seals, rotors, and wobbling bodies, Mech. Mach. Theory, 43, 909–917, https://doi.org/10.1016/j.mechmachtheory.2007.06.004, 2008.

Ji, W. T., Yao, L. G., and Zhang, J.: Mathematical modeling and characteristics analysis for the nutation gear drive based on error parameters, J. Chongqing Univ. Eng. Ed., 15, 149–158, https://doi.org/10.11835/j.issn.1671-8224.2016.04.003, 2016.

Kadota, Y., Inoue, K., Uzuka, K., Suenaga, H., and Morita, T.: Noncontact operation of a miniature cycloid motor by magnetic force, IEEE-ASME T. Mech., 18, 1563–1571, https://doi.org/10.1109/TMECH.2012.2208225, 2013.

Lin, Z. and Yao, L. G.: General mathematical model of internal meshing spiral bevel gears for nutation drive, Appl. Mech. Mater., 101–102, 708–712, https://doi.org/10.4028/www.scientific.net/AMM.101-102.708, 2012.

Lin, Z., Yao, L. G., and Huang, S. J.: Transmission ratio analysis and controllable tooth profile modeling for the nutation drive with double circular-arc external and internal spiral bevel gears, Adv. Mat. Res., 97–101, 3128–3134, https://doi.org/10.4028/www.scientific.net/AMR.97-101.3128, 2010.

Nelson, C. A. and Cipra, R. J.: Similarity and equivalence of nutating mechanisms to bevel epicyclic gear trains for modeling and analysis, J. Mech. Design, 127, 269–277, https://doi.org/10.1115/1.1829068, 2005.

Oda, S., Suzumori, K., Uzuka, K., and Enomoto, I.: Development of nutation motors (improvement of pneumatic nutation motor by optimizing diaphragm design), J. Mech. Sci. Technol., 24, 25–28, https://doi.org/10.1007/s12206-009-1157-y, 2010.

Uzuka, K., Enomoto, I., and Suzumori, K.: Comparative assessment of several nutation Motor Types, IEEE-ASME T. Mech., 14, 82–92, https://doi.org/10.1109/TMECH.2008.2004035, 2009.

Yao, L. G., Gu, B., Huang, S. J., Wei, G. W., and Dai, J. S.: Mathematical modeling and simulation of the external and internal double circular-arc spiral bevel gears for the nutation drive, J. Mech. Design, 132, 021008, https://doi.org/10.1115/1.4001003, 2010.


text:
# Up The Nose lyrics

Album: I Scream Sunday

There it goes up the nose
There it goes up the nose
There it goes up the nose
And the family goes down the drain

There it goes up the nose
There it goes up the nose
There it goes up the nose
And the family goes down the drain

This is your brain in hell

There it goes up the nose
There it goes up the nose
There it goes up the nose
And the family goes down the drain

There it goes up the nose
(Lines, rails, snow trails)
There it goes up the nose
And the family goes down the drain
The family goes down the drain
The family goes down the drain!!!!

Submitted by Guest


text:
# Proofs In Plane Geometry

Properties Of Circles
1. tan. $\perp$ rad.
2. rt. $\angle$ in semicircle
3. $\angle$s in same seg.
4. $\angle$ at centre = 2 $\angle$ at circ.
5. $\angle$s in opp. seg. ($a+c=b+d=180^\circ$)
6. tan. from ext. pt.
Congruent & Similar Triangles
$$\begin{array}{|c|c|} \hline \text{Congruent triangles} & \text{Similar triangles}\\\hline \text{SSS, SAS, AAS, RHS} & \text{SSS, SAS, AAA}\\\hline \end{array}$$
Midpoint Theorem
If $D$ and $E$ are the midpoints of $AB$ and $AC$ respectively, then $DE$ // $BC$ and $DE=\dfrac{1}{2}BC$.
Tangent-Chord Theorem (Alternate Segment Theorem)
If $DE$ is a tangent to the circle at $B$, then $\angle CAB=\angle CBE$ and $\angle ACB=\angle ABD$.
×


text:
# How do you find the coefficients for a conic in a rotated system?

Mar 4, 2015

This is a good question, but a little bit vague. I'll try to guess:

When you say, "a conic," do you (1) have an equation and you want to rotate the axes to get a simpler equation? Or do you (2) have a graph or some points that the curve goes through?

The general conic equation is a relation between x and y:

$A {x}^{2} + B x y + C {y}^{2} + D x + E y + F = 0$

(1) • If you want to rotate this curve to "get rid of" the xy-term, you can substitute coordinates u and v, rotated by angle $\theta$, where

$u = x \cos \theta + y \sin \theta$
$v = - x \sin \theta + y \cos \theta$

or to substitute in the general conic equation,

$x = u \cos \theta - v \sin \theta$
$y = u \sin \theta + v \cos \theta$

If you use the specific angle $\theta$ where

$\cot \left(2 \theta\right) = \frac{A - C}{B}$

then you will get an equation in u and v that has no xy-term.

(2) • If you just have some points that the conic goes through, you need five points to determine a unique conic. You then have 5 equations in the 6 variables A, B, C, D, E, F.

They are scalable so this determines a unique conic. For example ${x}^{2} + {y}^{2} - 25$ is the same circle as $3 {x}^{2} + 3 {y}^{2} - 75 = 0$.

Note: If you have six or more points, they may not all lie on the same conic.

// dansmath strikes again! //

p.s. Here's the story, and an example, from Stewart's Calculus:
http://www.stewartcalculus.com/data/ESSENTIAL%20CALCULUS/upfiles/topics/ess_at_13_ra_stu.pdf


text:
# Why can I apply $HS^\dagger$ and then measure in the computational basis to measure $Y$?

I come from a CS background

I was reading Neven and Farhi's paper ("Classification with Quantum Neural Networks on near Term Processors"), and I am trying to implement the subset parity problem using Qiskit, and solve it using a quantum Neural Network.

There is one thing that doesn't make sense to me though. In the paper, they measure "the Pauli Y gate on the readout qubit" (perhaps this phrasing is wrong, as I have to admit that whenever one does not measure in the computational basis, the whole thing doesn't make sense to me anymore). In one of the questions I already asked on this site, I was told that measuring in a basis other than the computational basis is simply the same as applying a matrix to the qubit and then measuring it in a computational basis.

Through various research, I was able to determine that, for this problem "to measure the Pauli Y gate the readout qubit", I had to apply $$HS^{\dagger}$$ and then measure in the computational basis in order to obtain the same result. It works, but I don't understand why it has to be this matrix in particular (is there any mathematical proof that shows that this is indeed this matrix ?)

Your normal measurement is a pauli-$$Z$$ measurement. If you apply a unitary $$U$$ just before measurement, this transforms the $$Z$$ measurement into $$U^\dagger ZU$$. So, any $$U$$ that transforms $$U^\dagger ZU=Y$$ will do the job. One convenient way of doing this is $$\frac{Y+Z}{\sqrt{2}},$$ but your choice will also work: $$SHZHS^\dagger=SXS^\dagger=-iS^2X=-iZX=Y$$

If you want to know why it's the transformation $$U^\dagger ZU$$, well think about a circuit with input $$|\psi\rangle$$ that has a unitary $$U$$ enacted upon it, and then it's measured in the standard basis. The probability of getting the 0 answer is $$|\langle 0|U|\psi\rangle|^2,$$ which is the same as the probability that $$|\psi\rangle$$ is in the state $$U^\dagger|0\rangle$$. This corresponds to a measurement projector $$U^\dagger |0\rangle\langle 0|U$$, so you can see that transformation starting to come out.

• Got it, thank you May 1 '20 at 8:18
• Just a question though. Why is the normal measurement a Pauli Z mesurement May 27 '20 at 13:27
• The Pauli Z matrix is diagonal in the standard measurement basis. May 27 '20 at 13:50

Measurement in $$Y$$ basis means that we want to measure is the qubit in $$|+i\rangle$$ state or $$|-i\rangle$$ state which are eigenbasis vectors for $$Y$$ gate. Because they are eigenbasis vectors we can express any $$|\psi_1 \rangle$$ state in this form:

$$| \psi_1 \rangle = \alpha_{+i} |+i\rangle + \alpha_{-i} |-i\rangle$$

where $$|\alpha_{+i}|^2$$ is the probability of measuring $$|+i\rangle$$ state and $$|\alpha_{-i}|^2$$ is the probability of measuring $$|-i\rangle$$. And

$$$$|+i\rangle = |0\rangle + i |1\rangle \qquad |-i\rangle = |0\rangle - i |1\rangle$$$$

Now when we apply $$HS^{\dagger}$$ to $$|\psi_1 \rangle$$ state, we will obtain:

$$| \psi_2 \rangle = \alpha_{+i} |0\rangle + \alpha_{-i} |1\rangle$$

Then, with $$|\alpha_{+i}|^2$$ we will measure $$|0\rangle$$ (the same probability that we had for $$|+i \rangle$$ measurment in the initial $$|\psi_1\rangle$$), and with with $$|\alpha_{-i}|^2$$ we will measure $$|1\rangle$$ (the same probability that we had for $$| -i \rangle$$ measurment in the initial $$|\psi_1\rangle$$). For any gate that will do $$U |+i\rangle = e^{i \varphi_1} |0\rangle$$ and $$U |-i\rangle = e^{i \varphi_2}|1\rangle$$ mapping (where $$\varphi_1$$ and $$\varphi_2$$ are some phases that will not have any influence on probabilities), we will have this correspondence. For example, if I understand this Riggeti's code right, they are doing $$Y$$ basis measurement by applying firstly $$U = R_x(\pi /2)$$ gate that maps $$R_x(\pi /2) |+i\rangle = |0\rangle$$ and $$R_x(\pi /2) |-i\rangle = -i|1\rangle$$.

The other thing is to measure the expectation value of $$Y$$ operator:

$$\langle \psi_1 | Y | \psi_1 \rangle = |\alpha_{+i}|^2 - |\alpha_{-i}|^2$$

that can easily be calculated after enough measurements in the $$Y$$ basis. Here we took into accout that $$Y|+i\rangle = (+1)|+i\rangle$$ and $$Y|-i\rangle = (-1)|-i\rangle$$. $$|\alpha_{+i}|^2 = \frac{N_{+i}}{N}$$ and $$|\alpha_{-i}|^2 = \frac{N_{-i}}{N}$$, where $$N$$ is the number of measurements, $$N_{+i}$$ is the number of $$| +i \rangle$$ measurements, and $$N_{-i}$$ is the number of $$| -i \rangle$$ measurements.

I guess in the paper they mean expectation value of $$Y$$ operator, not just one simple measurement in the $$Y$$ basis, because of this line "Our predicted label value is the real number between $$−1$$ and $$1$$... which is the average of the observed outcomes if $$Y_{n+1}$$ is measured in multiple copies of...".

• You're right, in the paper, they compute the expectation value of Y. Since I am implementing this on a simulator, I run the circuit multiple times and compute the probabilities just like you mentioned. However, the simulator only does measurements in the computational basis, hence my question May 27 '20 at 13:21


text:
# Is there a way to set distance between bottom of one line and up of other?

This is my minimal working code:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english,french,russian,swedish]{babel}
\begin{document}
\selectlanguage{french}

\begin{center}
\fontsize{23pt}{25pt} \textbf{TH\'{E}SE} \\[8mm]
\normalsize  PR\'{E}SENT\'{E}E A\\[7mm]
\Large\textbf{L'UNIVERSIT\'{E} BORDEAUX 1}\\[10mm]
\end{center}

\end{document}

What I need to do? I need to have exact size of font for every line and distance between bottom of upper line to up of line located below should be fixed. For fisrt two lines it should be 8 mm, then 7 and 10 at last. I've found how to set distances:

text \\[<distance>]

But it does not provide me what I need.

My second question concerns the:

\fontsize{23pt}{25pt}

Why I can not set font size bigger than 23pt, I would like to have bigger. And why second parameter does not effect behavior at all?

-
For the second question: try loading the anyfontsize pacakge, and it may also be an ise to load fontenc with the T1 option. BTW: If you are using utf8 then why the \'{E}? and not É –  daleif Jan 28 '14 at 20:27
This works. Thanks. By the way concerning the my second question, what does second parameter do? –  saldenisov Jan 28 '14 at 20:31
It fixes the interline length. Usually, it's 20-25% more than the first. And after \fontsize, you should add \selectfont to validate. For instance, \fontsize{48}{60}\selectfont. If it's only a matter of increasing the interline, you can use the setspace package, and write, say \setstretch{1.06}, which increase the interline by 6%. –  Bernard Jan 28 '14 at 20:44
\fontsize sets the fontsize and the baseline skip. Note taht it does not have to be in pt –  daleif Jan 28 '14 at 20:45

You can resort to lower level commands; I'll add some rules to show that the distance is what's expected, although it's not clear whether accents should be taken into account. For arbitrary font size, load fix-cm.

\documentclass[12pt,a4paper]{article}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english,russian,swedish,french]{babel}
\usepackage{fix-cm}

\begin{document}

{\centering
\fontsize{23pt}{0pt}\selectfont
\textbf{TH\'{E}SE}\smash{\rlap{\vrule depth 8mm}} \\
\nointerlineskip\vspace{8mm}
\normalsize  PR\'{E}SENT\'{E}E A\smash{\rlap{\vrule depth 7mm}}\\
\nointerlineskip\vspace{7mm}
\Large\textbf{L'UNIVERSIT\'{E} BORDEAUX 1}\smash{\rlap{\vrule depth 10mm}}\\
\nointerlineskip\vspace{10mm}}
Other text to see what's the distance from the last line

\end{document}

-

The default stack of the stackengine package is a "short" stack, in which the vertical gap between adjacent objects is set. So here, I just use a compound stack, specifying that gap with each nesting. By contrast, a long stack (not used here) will set the distance between adjacent baselines.

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english,french,russian,swedish]{babel}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\selectlanguage{french}
\parskip 10mm
{\centering
\stackunder[7mm]{%
\stackunder[8mm]{%
\fontsize{23pt}{25pt} \textbf{TH\'{E}SE}%
}{%
\normalsize  PR\'{E}SENT\'{E}E A%
}%
}{%
\Large\textbf{L'UNIVERSIT\'{E} BORDEAUX 1}%
}%
\par}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

\parskip 0mm
YYYYYYYYYYYYYY
\end{document}

-
Thank You a lot! This exactly what i was searching for! –  saldenisov Jan 28 '14 at 21:08

The linespacing in TeX is baseline to baseline, not from base of one to top of another (top is a bit undefined do you mean top of the letters used or the position where (say) an accented capital would be)

The linespacing is per paragraph which is why you should normally use {\small xxxx \par} rather than just {\small xxxx} so that the font change is in scope at the end of the paragraph and a suitable baseline used.

Normally \\ does not start a paragraph and

  \fontsize{23pt}{25pt} \textbf{TH\'{E}SE} \\
\normalsize  PR\'{E}SENT\'{E}E A\\
\Large\textbf{L'UNIVERSIT\'{E} BORDEAUX 1}\\

would set all the text to the baseline specified by \Large . As it happens center uses a special version of \\ that does internally use \par. so inside a center they do get specified baselines.

The default font sizes of latex for Computer Modern are restricted to the sizes commonly available when these fonts were distributed as bitmap formats. If you use a scalable font such as times then any size may be used, or to tell latex that computer modern is scalable use the fixcm package.

-


text:
Galperin’s billiard method of computing pi

For the lack of original pi-related ideas, I describe a billiard experiment invented and popularized by Gregory Galperin (Григорий Гальперин). I read about it in a short note he published in 2001 in the Russian journal “Mathematical Education” (“Математическое Просвещение”). Although the table of contents is in Russian, it’s not hard to find the article with “pi” in the title. It’s clear from the article that the observation precedes its publication by some years; the author gave talks on this subject for a while before committing it to print.

Place two billiard balls (red and blue) on the half-line $[0,\infty)$: the red ball is at rest, the blue ball is to the right of it and is moving the the left. At $x=0$ there is an elastic wall.

Assume perfectly elastic collisions: the kinetic energy is preserved. How many collisions will happen depends on the masses of the ball, or rather their ratio. Suppose they have equal mass (ratio=1). Then we’ll see the following:

1. Blue hits Red and stops; Red begins to move to the left
2. Red hits the wall and bounces back
3. Red hits Blue and stops; Blue begins to move to the right

That’s all, 3 collisions in total. Here is a Scilab-generated illustration: I placed red at $x=1$ and blue at $x=1.5$, with initial velocity $-1$. The time axis is vertical.

Number 3 is also the first digit of $\pi$. Coincidence? No.

Consider the blue/red mass ratio of 100. Now we really need scilab. Count the collisions as you scroll down:

Yes, that’s exactly 31 collisions. The mass ratio of 10000 would yield 314 collisions, and so on.

How does this work? The trick is to consider the two-dimensional configuration space in which the axes are scaled proportional to the square roots of masses. A point on the configuration plane describes the position of two balls at once, but it also behaves just like a billiard ball itself, bouncing off the lines (red=0) and (red=blue). The scaling by square roots of masses is needed to make the (red=blue) bounce work correctly: the angle of incidence is equal to the angle of reflection. (See Update 2 below.)

The opening angle is $\alpha=\tan^{-1}\sqrt{M_r/M_b}$. Now we can straighten the billiard trajectory by repeated reflection: this will help us count the number of collisions.

It remains to count how many angles of size $\alpha=\tan^{-1}\sqrt{M_r/M_b}$ fit inside of angle $\pi$. By taking $\sqrt{M_r/M_b}=10^{-n}$, we should get $10^n \pi$ collisions, rounded to an integer one way or the other. It seems that the rounding is always down, that is, we get exactly the first $n$ digits of $\pi$. I once tried to prove that this always happens, but unsuccessfully. The error of approximation $\tan^{-1} 10^{-n}\approx 10^{-n}$ needs to be compared to the fractional part of $10^n \pi$, which looks like tricky business.

Here’s the scilab source. The plots in this post were obtained with galperin(1) and galperin(100).

function galperin(m)
h=0.001; steps=4000;  x1=zeros(steps); x2=zeros(steps);
x1(1)=1.5;  v1=-1;  x2(1)=1;  v2=0; collision=0; j=1;
while j<steps,
select collision
case 0 then
newx1=x1(j)+h*v1; newx2=x2(j)+h*v2;
if (newx2<0) then collision=1;
elseif (newx1<newx2) then collision=2;
else
x1(j+1)=newx1; x2(j+1)=newx2; j=j+1;
end
case 1 then
v2=-v2; x1(j+1)=x1(j); x2(j+1)=x2(j); collision=0; j=j+1;
case 2 then
newv1=(v1*(m-1)+2*v2)/(m+1);  newv2=(v2*(1-m)+2*m*v1)/(m+1);
v1=newv1; v2=newv2; x1(j+1)=x1(j); x2(j+1)=x2(j);
collision=0; j=j+1;
end
end
t=linspace(0, h*steps, steps); plot(t, x1); plot(t, x2, 'red');
endfunction

Update: this post was referred to from Math StackExchange, with a request for a more intuitive explanation of how the scaling by $\sqrt{M}$ works. Let $V_c$ be the velocity vector of the point in the configuration space. Thanks to the scaling, we have the following:

• The magnitude of $V_c$ is equal to the total kinetic energy of the system, up to a constant factor.
• The projection of $V_c$ onto the collision line $x_r=x_b$ is equal to the total momentum of the system, up to a constant factor.

When the balls collide with each other, both the energy and the momentum are preserved. It follows that the new vector $V_c$ will have the same magnitude and the same projection onto the collision line. By trigonometry, this implies the equality of the incident and reflected angles.

6 thoughts on “Galperin’s billiard method of computing pi”

1. I tried implementing this code myself (in MATLAB, as usual, though the approach is the same), and the most I can get is the first four digits before I start running into a bunch of computation errors. In particular, with a mass ratio of 100,000,000:1, the change in velocity imparted by the collisions with the smaller billiard ball is never enough to turn the larger ball around (I think this may even be a floating point error, where the change in velocity is rounded to 0). I wonder if there is any reasonable way to implement this and get, say, 10 digits.

2. Hm. The relative change of velocity is of order at least ~1/m, due to $(m-1)/(m+1)$ factor. with m=100,000,000 this does not seem enough for floating point errors.

I guess the easiest way is “model” this process is to cheat and use the configuration point (which moves with constant speed) to obtain the positions and velocities at any moment of time.

3. Hans says:
1. His math isn’t quite right. Since he counts only the collisions up to turnaround, he needs the mass ratio 4 times a power of 100 to get the same result, not 16.
With mass ratio of 16 there will be 7 collisions before the turnaround of the larger ball, not 3 as is claimed in the video. Here’s the output of galperin(16):
http://dl.dropbox.com/u/29863189/galperin16.png

1. Correction: in the youtube video only the collisions between two balls are counted, not between a ball and the wall. So the factor of 16 is appropriate. However, my calculations still disagree with the claim that mass ratio of 16 gives 3 collisions. The graph linked above shows 4.

4. I think that this is a wonderful post! I want to confirm that I got similar results by running a simulation using Mathematica. A truly fascinating result!


text:
# Filtered probability space

1. Oct 25, 2013

### woundedtiger4

2. Oct 25, 2013

### economicsnerd

For a collection $\{\mathcal F_s\}_{s\in S}$ of sub-$\sigma$-algebras of $\mathcal F$, the set $\bigvee_{s\in S} \mathcal F_s$ is defined to be the smallest sub-$\sigma$-algebra $\mathcal G\subseteq \mathcal F$ such that $\mathcal F_s\subseteq\mathcal G$ for every $s\in S$.

3. Oct 26, 2013

### woundedtiger4

at http://en.wikipedia.org/wiki/Filtration_(mathematics)#Measure_theory

the encircle part says:

Similarly in the following picture the encircle part

does the symbole " " represent Union? I understood the notation from your reply but what is the name of the symbol? is it logical disjunction (though logical disjunction doesn't make sense here) or is it universal quantifier (though logical quantifier is turned A) or is it just a capital V (the 22nd alphabet)?

4. Oct 26, 2013

### R136a1

The symbol is called a "join". It is a symbol from lattice theory. Here, just means the smallest sigma-algebra that contains the union.

The dual symbol is $\bigwedge$ and is called a meet.

5. Oct 26, 2013

Thanks


text:
## 4. Neural Networks Learning in Theano¶

The aim of this IPython notebook is to show some features of the Python Theano library in the field of machine learning. It has been developped by the LISA group at the University of Montreal (see: http://deeplearning.net/software/theano/). The notebook also relies on other standard Python libraries such as numpy, pandas and matplotlib.

To exemplify the use of Theano, this notebook solves the assignments of the Machine Learning MOOC provided by Coursera (see: https://www.coursera.org/learn/machine-learning) and performed in Stanford University by Andrew Ng (see: http://www.andrewng.org/).

The original MOOC assignments should to be programmed with the Octave language (see: https://www.gnu.org/software/octave/).The idea with this notebook is to provide Python developpers with interesting examples programmed using Theano.

This notebook has been developped using the Anaconda Python 3.4 distribution provided by Continuum Analytics (see: https://www.continuum.io/). It requires the Jupyter Notebook (see: http://jupyter.org/).

### 4.1 Neural Networks¶

#### 4.1.1 Visualizing the data¶

In [1]:
import theano
import numpy as np
import theano.tensor as T
from theano.tensor.nnet import sigmoid
import scipy.io as sio
X, Y = data['X'], data['y'].T[0]
m = X.shape[0]

In [2]:
%matplotlib inline
import pandas as pnd
import matplotlib.pyplot as plt

def display_data(X, Y=None):
example_width = int(np.sqrt(X.shape[1]))

# Compute rows, cols
m, n = X.shape
example_height = int(n / example_width)

# Compute number of items to display
display_rows = int(np.floor(np.sqrt(m)))
display_cols = int(np.ceil(m / display_rows))

# Setup blank display

# Copy each example into a patch on the display array
# dataset contains 20 pixel by 20 pixel grayscale images of the digit
curr_ex = 0
for j in range(display_rows):
for i in range(display_cols):
if curr_ex >= m:
break
# Get the max value of the patch
max_val = max(abs(X[curr_ex]))
np.reshape(X[curr_ex], (example_height, example_width)) / max_val
curr_ex += 1
if curr_ex >= m:
break

plt.figure(figsize=(8,6))
plt.axis('off')
plt.imshow(display_array.T, cmap="Greys_r")

if Y is not None:
df = pnd.DataFrame(Y.reshape((display_rows, display_cols)).T)
df = df.replace(10,0) # 0 is mapped to 10 in Y
print(df)

In [3]:
rnd = np.random.permutation(m)[0:100]
sel = X[rnd,:] # 100 random digits
res = Y[rnd]
display_data(sel, res)

   0  1  2  3  4  5  6  7  8  9
0  7  5  5  5  9  8  5  9  0  5
1  7  6  9  8  1  4  3  1  0  0
2  1  6  0  5  1  4  7  6  2  2
3  8  1  0  4  7  3  0  7  9  0
4  1  2  6  0  5  2  9  1  1  8
5  4  7  3  7  7  6  7  8  2  5
6  9  5  6  6  2  3  3  0  5  7
7  4  5  6  3  4  9  1  2  0  6
8  5  6  7  0  2  1  7  0  5  1
9  9  3  1  6  5  0  5  6  0  8

#### 4.1.2 Feedforward and cost function¶

In [4]:
def T_add_ones(x, a, b):
var = T.concatenate([T.ones(a), x.flatten().T])
return var.reshape((b, a))

X1 = np.c_[np.ones(m), X] # Add intercept term to X
X1 = X1.T

t1 = weights['Theta1']
t2 = weights['Theta2']

print("X1:", X1.shape)
print("theta1:", t1.shape)
print("theta2:", t2.shape)

# layer sizes
input_layer_size = X.shape[1]
hidden_layer_size = t1.shape[0]
num_labels = t2.shape[0]

print('\ninput_layer_size: %i' % input_layer_size)
print('hidden_layer_size: %i' % hidden_layer_size)
print('num_labels: %i' % num_labels)

x = T.matrix('x')
y = T.vector('y')
theta1 = theano.shared(t1, 'theta1')
theta2 = theano.shared(t2, 'theta2')

# first layer
y1 = sigmoid(T.dot(theta1, x))

# second layer
y3 = sigmoid(T.dot(theta2, y2))

J = 0
for i in range(num_labels):
yy = T.eq(y,i+1)
J += -T.sum(yy * T.log(y3[i,:]) + (1 - yy) * T.log(1 - y3[i,:])) / m

cost = theano.function([x, y], J)

print('\ncost: %f' % cost(X1, Y))

X1: (401, 5000)
theta1: (25, 401)
theta2: (10, 26)

input_layer_size: 400
hidden_layer_size: 25
num_labels: 10

cost: 0.287629

#### 4.1.3 Regularized cost function¶

In [5]:
# Weight regularization parameter (we set this to 0 here).
lambda_ = 1

x = T.matrix('x')
y = T.vector('y')
theta1 = theano.shared(t1, 'theta1')
theta2 = theano.shared(t2, 'theta2')

# first layer
y1 = sigmoid(T.dot(theta1, x))

# second layer
y3 = sigmoid(T.dot(theta2, y2))

# regularization on theta1 and theta2
reg = lambda_ * (T.sum(theta1[:,1:]**2) + T.sum(theta2[:,1:]**2)) / 2 / m
J = reg
for i in range(num_labels):
yy = T.eq(y,i+1)
J += -T.sum(yy * T.log(y3[i,:]) + (1 - yy) * T.log(1 - y3[i,:])) / m

cost = theano.function([x, y], J)

print('cost: %f' % cost(X1, Y))

cost: 0.383770

## 4.2 Backpropagation¶

In [6]:
x = T.matrix('x')
h = 1.0 / (1.0 + T.exp(-x))

sigmoid2 = theano.function([x], h)
print(sigmoid2(np.array([[-1, -0.5, 0, 0.5, 1]])))

[[ 0.26894142  0.37754067  0.5         0.62245933  0.73105858]]
[[ 0.19661193  0.23500371  0.25        0.23500371  0.19661193]]

### 4.2.2 Random initialization¶

In [7]:
def rand_initialize_weights(l_in, l_out, epsilon_init):
return np.random.rand(l_out, l_in+1) * 2 * epsilon_init - epsilon_init

epsilon_init = 0.12
t1 = rand_initialize_weights(input_layer_size, hidden_layer_size, epsilon_init)
t2 = rand_initialize_weights(hidden_layer_size, num_labels, epsilon_init)

### 4.2.3 Backpropagation¶

In [8]:
def T_add_ones(x, a, b):
var = T.concatenate([T.ones(a), x.flatten().T])
return var.reshape((b, a))

theta1 = theano.shared(t1, 'theta1')
theta2 = theano.shared(t2, 'theta2')

# Choose some alpha value
alpha = 1

x = T.matrix('x')
y = T.vector('y')

# first layer
y1 = sigmoid(T.dot(theta1, x))

# second layer
y3 = sigmoid(T.dot(theta2, y2))

J = 0
for i in range(num_labels):
yy = T.eq(y,i+1)
J += -T.sum(yy * T.log(y3[i,:]) + (1 - yy) * T.log(1 - y3[i,:])) / m

for i in range(2000):
costM, y3 = train(X1,Y)
if i%500 == 0:
print('[%i] %f' % (i, costM))

print('cost: %f' % costM)

[0] 6.759750
[500] 0.481384
[1000] 0.335062
[1500] 0.257458
cost: 0.206653

In [9]:
# number of positive predictions where best prediction == Y-1
accuracy = np.sum(np.argmax(y3, axis=0) == (Y-1))/len(Y)
print('Train Accuracy: %f' % accuracy)

Train Accuracy: 0.980200

### 4.2.4 Regularized Neural Networks¶

In [10]:
theta1 = theano.shared(t1, 'theta1')
theta2 = theano.shared(t2, 'theta2')

# Weight regularization parameter (we set this to 0 here).
lambda_ = 3

# Choose some alpha value
alpha = 1

x = T.matrix('x')
y = T.vector('y')

# first layer
y1 = sigmoid(T.dot(theta1,x))

# second layer
y3 = sigmoid(T.dot(theta2, y2))

# regularization on theta1 and theta2
reg = lambda_ * (T.sum(theta1[:,1:]**2) + T.sum(theta2[:,1:]**2)) / 2 / m

J = reg
for i in range(num_labels):
yy = T.eq(y,i+1)
J += -T.sum(yy * T.log(y3[i,:]) + (1 - yy) * T.log(1 - y3[i,:])) / m

for i in range(2000):
costM, y3, theta1 = train(X1,Y)
if i%500 == 0:
print('[%i] %f' % (i, costM))

print('cost: %f' % costM)

[0] 6.774405
[500] 0.711646
[1000] 0.645442
[1500] 0.620571
cost: 0.607821

In [11]:
# number of positive predictions where best prediction == Y-1
accuracy = np.sum(np.argmax(y3, axis=0) == (Y-1))/len(Y)
print('Train Accuracy: %f' % accuracy)

Train Accuracy: 0.963000

### 4.2.5 Mean Tagged and Recognized Digit Set¶

In [12]:
# display mean tagged digit set
z1 = np.concatenate([np.mean(X[Y == i+1], axis=0) for i in range(10)])
display_data(z1.reshape((10,400)))

In [13]:
# display mean recognized digit set
z2 = np.concatenate([np.mean(X[np.argmax(y3, axis=0) == i], axis=0) for i in range(10)])
display_data(z2.reshape((10,400)))

In [14]:
# z1 and z2 are quite different
np.sum(z1!=z2)

Out[14]:
3576

## 4.3 Visualizing the hidden layer¶

In [15]:
# take theta1 without the bias term
z = theta1[:,1:]
display_data(z)

In [ ]:


text:
Results (14 matches)

Label Dim. $$A$$ Field CM Traces A-L signs $q$-expansion
$$a_2$$ $$a_3$$ $$a_5$$ $$a_7$$ 2 7
1568.2.a.a $$1$$ $$12.521$$ $$\Q$$ None $$0$$ $$-2$$ $$-2$$ $$0$$ $$+$$ $$-$$ $$q-2q^{3}-2q^{5}+q^{9}+4q^{11}-6q^{13}+\cdots$$
1568.2.a.b $$1$$ $$12.521$$ $$\Q$$ None $$0$$ $$-2$$ $$0$$ $$0$$ $$+$$ $$-$$ $$q-2q^{3}+q^{9}+4q^{11}+4q^{13}+2q^{17}+\cdots$$
1568.2.a.d $$1$$ $$12.521$$ $$\Q$$ $$\Q(\sqrt{-1})$$ $$0$$ $$0$$ $$-4$$ $$0$$ $$+$$ $$-$$ $$q-4q^{5}-3q^{9}+4q^{13}-8q^{17}+11q^{25}+\cdots$$
1568.2.a.f $$1$$ $$12.521$$ $$\Q$$ $$\Q(\sqrt{-1})$$ $$0$$ $$0$$ $$4$$ $$0$$ $$+$$ $$-$$ $$q+4q^{5}-3q^{9}-4q^{13}+8q^{17}+11q^{25}+\cdots$$
1568.2.a.h $$1$$ $$12.521$$ $$\Q$$ None $$0$$ $$2$$ $$0$$ $$0$$ $$+$$ $$-$$ $$q+2q^{3}+q^{9}-4q^{11}+4q^{13}+2q^{17}+\cdots$$
1568.2.a.i $$1$$ $$12.521$$ $$\Q$$ None $$0$$ $$2$$ $$2$$ $$0$$ $$+$$ $$-$$ $$q+2q^{3}+2q^{5}+q^{9}+4q^{11}+6q^{13}+\cdots$$
1568.2.a.p $$2$$ $$12.521$$ $$\Q(\sqrt{2})$$ $$\Q(\sqrt{-1})$$ $$0$$ $$0$$ $$0$$ $$0$$ $$-$$ $$+$$ $$q+3\beta q^{5}-3q^{9}+5\beta q^{13}-3\beta q^{17}+\cdots$$
1568.2.a.r $$2$$ $$12.521$$ $$\Q(\sqrt{2})$$ None $$0$$ $$0$$ $$0$$ $$0$$ $$-$$ $$+$$ $$q+\beta q^{3}-q^{9}+2q^{11}+2\beta q^{13}+3\beta q^{17}+\cdots$$
1568.2.a.s $$2$$ $$12.521$$ $$\Q(\sqrt{3})$$ None $$0$$ $$0$$ $$2$$ $$0$$ $$-$$ $$+$$ $$q+\beta q^{3}+q^{5}+3\beta q^{11}+\beta q^{15}+5q^{17}+\cdots$$
1568.2.a.t $$2$$ $$12.521$$ $$\Q(\sqrt{7})$$ None $$0$$ $$0$$ $$6$$ $$0$$ $$+$$ $$-$$ $$q+\beta q^{3}+3q^{5}+4q^{9}+\beta q^{11}+4q^{13}+\cdots$$
1568.2.a.u $$2$$ $$12.521$$ $$\Q(\sqrt{2})$$ None $$0$$ $$2$$ $$-2$$ $$0$$ $$+$$ $$-$$ $$q+(1+\beta )q^{3}+(-1-2\beta )q^{5}+2\beta q^{9}+\cdots$$
1568.2.a.v $$2$$ $$12.521$$ $$\Q(\sqrt{5})$$ None $$0$$ $$2$$ $$-2$$ $$0$$ $$+$$ $$-$$ $$q+(1+\beta )q^{3}+(-1+\beta )q^{5}+(3+2\beta )q^{9}+\cdots$$
1568.2.a.w $$2$$ $$12.521$$ $$\Q(\sqrt{2})$$ None $$0$$ $$2$$ $$2$$ $$0$$ $$-$$ $$+$$ $$q+(1+\beta )q^{3}+(1+2\beta )q^{5}+2\beta q^{9}+(-1+\cdots)q^{11}+\cdots$$
1568.2.a.x $$4$$ $$12.521$$ $$\Q(\sqrt{2}, \sqrt{5})$$ None $$0$$ $$0$$ $$0$$ $$0$$ $$-$$ $$+$$ $$q-\beta _{2}q^{3}-2\beta _{1}q^{5}+7q^{9}-\beta _{3}q^{11}+\cdots$$


text:
## § Hilbert polynomial and dimension

• Think of non Cohen Macaulay ring (plane with line perpendicular to it). Here the dimension varies per point.
• Let $R$ be a graded ring. Let $R^0$ be noetherian. $R$ is finitely generated as an algebra over $R^0$. This implies by hilbert basis theorem that $R$ is noetherian (finitely generated as a module over $R^0$).
• Suppose $M$ is a graded module over $R$, and $M$ is finitely generated as a module over $R$.
• How fast does $M_n$ grow? We need some notion of size.
• Define the size of $M_n$ as $\lambda(M_n)$.Suppose $R$ is a field. Then $M_n$ is a vector space. We define $\lambda(M_n)$ to be the dimension of $M_n$ as a vector space over $R$.
• What about taking dimension of tangent space? Doesn't work for cusps! (singular points). Can be used to define singular points.
• TODO: show that at $y^2 = x^3$, we have dimension two (we expect dimension one)


text:
# 7: Differential Equations

• 7.1: An Introduction to Differential Equations
Here introduce the concept of differential equations. A differential equation is an equation that provides a description of a function’s derivative, which means that it tells us the function’s rate of change. Using this information, we would like to learn as much as possible about the function itself. For instance, we would ideally like to have an algebraic description of the function.
• 7.2: Qualitative Behavior of Solutions to Differential Equations
Since the derivative at a point tells us the slope of the tangent line at this point, a differential equation gives us crucial information about the tangent lines to the graph of a solution. We will use this information about the tangent lines to create a slope field for the differential equation, which enables us to sketch solutions to initial value problems. Our aim will be to understand the solutions qualitatively.
• 7.3: Euler's Method
Euler’s method is an algorithm for approximating the solution to an initial value problem by following the tangent lines while we take horizontal steps across the t-axis. If we wish to approximate y(t) for some fixed t by taking horizontal steps of size ∆t, then the error in our approximation is proportional to ∆t.
• 7.4: Separable Differential Equations
A separable differential equation is one that may be rewritten with all occurrences of the dependent variable multiplying the derivative and all occurrences of the independent variable on the other side of the equation. We may find the solutions to certain separable differential equations by separating variables, integrating with respect to t, and ultimately solving the resulting algebraic equation for y. This technique allows us to solve many important differential equations.
• 7.5: Modeling with Differential Equations
In our work to date, we have seen several ways that differential equations arise in the natural world, from the growth of a population to the temperature of a cup of coffee. In this section, we will look more closely at how differential equations give us a natural way to describe various phenomena. As we’ll see, the key is to focus on understanding the different factors that cause a quantity to change.
• 7.6: Population Growth and the Logistic Equation
The growth of the earth’s population is one of the pressing issues of our time. Will the population continue to grow? Or will it perhaps level off at some point, and if so, when? In this section, we will look at two ways in which we may use differential equations to help us address questions such as these. Before we begin, let’s consider again two important differential equations that we have seen in earlier work this chapter.
• 7.E: Differential Equations (Exercises)
These are homework exercises to accompany Chapter 7 of Boelkins et al. "Active Calculus" Textmap.

## Contributors

Matt Boelkins (Grand Valley State University), David Austin (Grand Valley State University), Steve Schlicker (Grand Valley State University)


text:
# The sums of forces along x and y

1. May 8, 2006

### Malitic

I have a problem I'm working on where the general premise is that there is a box being pushed along the ceiling at a constant speed. The force F is at some angle with respect to the vertical. There is a coefficient of kinetic friction between the box and the ceiling and the persons hands and the box. The latter of which keeps the persons hands from slipping.
I am trying to be deliberately vague because I want help on the concept not the problem itself.

A = angle
$$F_a$$ = Force along the angle A
$$\mu_k$$ = coefficient of friction along the ceiling
$$\mu_{k2}$$ = coefficient of kinetic friction with persons hands
My thinking is that
$$\sum f_x = f_a*sinA - ff = 0 \Rightarrow f_a*cosA = \mu_k*N + \mu_{k2} *N$$
and
$$\sum f_y = f_a*cosA - mg - n = 0$$

Is there a flaw in my logic? Because when I put in all the information my result is unrealistic. I have attached the free body that goes along with my thinking.

#### Attached Files:

• ###### free.png
File size:
2.1 KB
Views:
38
Last edited: May 8, 2006
2. May 9, 2006

### Kazza_765

If the person's hands aren't slipping then ignore the coeffecient of friction between the hands and the box for now.

In the y direction:
$$F_a*cos(A) - mg - N = 0$$ N is normal reaction between box and ceiling
$$N = F_a*cos(A) - mg$$

In the x direction:
$$F_a*sin(A) - \mu*N = 0$$
$$F_a*sin(A) - \mu(F_a*cos(A) - mg) = 0$$

Now as far as the coeffecient of friction between the hands and the box, this should be a limiting condition.

$$F_a*sin(A) < F_a*cos(A)*\mu$$
$$A < Tan^-1(\mu)$$, so the above equations only hold true if this condition is met.

3. May 9, 2006

### Malitic

The force along the x direction in your problem is incorrect because the friction between the box and the hands is important to the problem overall.

However in bug fixing your problem I was able to see where I went wrong so thanks.


text:
# Count how many numbers are divisible by perfect numbers in a given range

Given two arbitrary integers a and b. Count how many numbers are divisible by perfect numbers in that given range (a and b both are inclusive).

In mathematics, a perfect number is a positive integer that is the sum of its proper positive divisors, that is, the sum of the positive divisors excluding the number itself.Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself), or σ(n) = 2n.

Input:

1 100

Output:

18

• Use stdin and stdout for Input/Output
• Your code must handle big integers, so it is not good enough to hard-code a list of perfect numbers.
• Shortest code wins
• 18 is not a perfect number! I guess you meant 28? (Since 18!=9+6+3+2+1, while 28=14+7+4+2+1). – Vereos Jan 17 '14 at 9:17
• @Vereos the question says Count how many numbers are divisible by perfect numbers  – ace_HongKongIndependence Jan 17 '14 at 9:27
• Woah, I've been misleaded by the question's name. Thank you! – Vereos Jan 17 '14 at 9:29
• @Peter Taylor Arbitrary integers – Wasi Jan 17 '14 at 9:37
• Then I suggest you edit the question to make that explicit before people start submitting answers with 32-bit ints. – Peter Taylor Jan 17 '14 at 9:41

## Perl 6, 106 103 characters

my ($a,$b)=get.words;(($a..$b).grep: *%%any ($a..$b).grep: {$^n==[+] ($^n%%$_&&$_ for 1..^$^n)})[*.say]  There's a lot of syntax here, so hopefully this explanation helps at least a little to someone who knows a bit of Perl 5 syntax, though I won't explain every detail: Finds all the perfect numbers in the range$a..$b: ($a..$b).grep: {$^n==[+] ($^n%%$_&&$_ for 1..^$^n)} (explained below). It then chooses all the numbers in the range $a..$b which are divisible (%%) by any of the perfect numbers it had found: (%a..%b).grep: * %% any ….

The final (…)[*.say] abuses the fact that any code (in this case *.say, which prints its argument and a newline) passed to the […] postfix will be given the list's length as its argument (so that one can, e.g., use the idiomatic @array[*-1] to get the last element of @array). This means that the (…)[*.say] here has the same effect as say (…).elems.

The part that finds all the perfect numbers in the range does so by returning only those numbers which are equal ($^n ==) to the sum of their divisors. [+] adds together the values following it, for 1..^$^n iterates over all numbers 1 to $^n-1 and assigns$_ to them, and $^n %%$_ && $_ returns$_ if $^n is divisible ($^n %% $_) by$_, or else False, thus creating a list that consists of the proper divisors of $^n and False objects, which numify to 0 when all the values are added together by [+]. Perl 6 uses arbitrary sized integers, so, if you have the resources and the time, it could technically compute for big integers # Mathematica - 117 Naive approach, linear for the range size With[{p=#(#+1)/2&/@Select[2^Range@@Floor@Log2@Sqrt@#-1,PrimeQ]},Length@Select[Range@@#,Or@@Divisible[#,p]&]]&@Input[]  The correct way would be constructing numbers from the perfect numbers that are in the given range of course. # Haskell - 157 c x=x==sum[i|i<-[1..x-1],mod x i==0] d x=any((0==).mod x)$takeWhile(<=x)(filter c[2..])
main=do m<-getLine;n<-getLine;print$length(filter d[read m..read n])  Can work with arbitrarily large numbers given respectively large time. Input is given on 2 lines. # C, 125120 a,b,c,p[4]={6,28,496,8128};main(i){for(scanf("%d%d",&a,&b);a<=b;a++)for(i=0;i<4;)if(a%p[i++]==0)c++,i=4;printf("%d",c);}  A little more readable: a,b,c=0,i,p[4]={6,28,496,8128}; main() { for(scanf("%d%d",&a,&b);a<=b;a++) for(i=0;i<4;) if(a%p[i++]==0) { c++; i=4; } printf("%d",c); }  This works with signed 32bit integers, up to 2^31-1=2147483647. # C, 212209 #include<stdint.h> uint64_t a,b,c,p[8]={6,28,496,8128,33550336,8589869056,137438691328,0x1fffffffc0000000};main(i){for(scanf("%lld%lld",&a,&b);a<=b;a++)for(i=0;i<8;)if(a%p[i++]==0)c++,i=8;printf("%lld",c);}  Should work up to 2^64-1=18446744073709551615. • In C global ints are initialized to 0 by default so you don't need to set c=0 :) – Josh Jan 19 '14 at 0:52 • To save 1 char you could move one of your ints into the main declaration, ex main(i) (saves a comma character). – Josh Jan 19 '14 at 0:53 • Oh, you're right! I also removed a couple of useless {}. – izabera Jan 19 '14 at 1:08 • You can remove the pair of braces around your if statement by changing the contents to be c++,i=4; – Josh Jan 19 '14 at 1:49 • Yes, I did it. Well, not in the prettified version, but that's not supposed to be short, isn't it? – izabera Jan 19 '14 at 2:24 ## Python 3 [166 bytes] a,b=map(int,input().split());print(len(set([n if n%p==0 else 0 for p in [x for x in range(a,b) if sum(y for y in range(1,x) if x%y==0)==x] for n in range(a,b+1)]))-1)  More readable: // STDIN => a, b a, b = map(int, input().split()) // list of perfect numbers perfect = [x for x in range(a, b) if sum(y for y in range(1, x) if x % y == 0) == x] // length(number % [any perfect number] == 0) => STDOUT print(len(set([n if n % p == 0 else 0 for p in perfect for n in range(a, b + 1)])) - 1)  Here the list of perfect numbers is calculated inline but may be set statically. The number range should be bound by the machine's word size. While this algorithm is deadly slow and takes ages for working with big numbers, it is at least short :) # PHP, 248 I guess there could be way shorter solutions, but here's mine. I used the STDIN constant to achieve the stdin spec, but I used echo to output. fscanf(STDIN,"%d\n",$a);fscanf(STDIN,"%d\n",$b);$l=array(6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128);$x=array();foreach($l as&$k){if($k>=$a){$c=$k;while($c<=$b){if($c%$k==0&&!in_array($c,$x)){$r++;$x[]=$c;}$c+=$k;}}}echo $r;  Readable: fscanf(STDIN,"%d\n",$a);
fscanf(STDIN,"%d\n",$b);$l=array(6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128);
$x=array(); foreach($l as&$k){ if ($k>=$a){$c=$k; while($c<=$b){ if($c%$k==0&&!in_array($c,$x)){$r++;
$x[]=$c;
}
$c+=$k;
}
}
}
echo \$r;

• The spec requires you to support big integers, so in PHP you probably want bc_math (and in any language you can't hard-code the list of perfect numbers). – Peter Taylor Jan 17 '14 at 11:15


text:
# Using GPS & IMU for robot positioning

I'm relatively new to ROS and I'm having trouble trying to integrate all the components for the real Unmanned Surface Vehicle. I have the robot description (which I've been using within Gazebo until now), a driver node for the dual-antenna GNSS, and a LiDAR driver node.

At this time, all I want to do is integrate telemetry from the real GNSS so that I can see the robot move in the map (3D-XYZ and orientation). My understanding is that I should be using the robot_localization package to fuse the GPS & IMU but I haven't had any luck getting the robot to move. For my current base for robot_localization, I am using the answer from this question. I can see new messages being produced under the topics /odometry/gps and /odometry/filtered but I get a slew of errors and am yet to get the robot to move.

Is there something obvious that I am missing to get the robot to move? I've tried searching the subject but either I'm not finding anything that helps or just not understanding the process.

Source Repo: I've made a stripped-down test version (containing the robot description and launch file that I am using) available in this repo as well as a bag file of some GNSS output under ./cust_robot_description/misc/sample.bag. (This is from a bench test so the latitude/longitude are relatively static but the roll/pitch should change to show the robot move)

This can be run using: roslaunch cust_robot_description view.launch

When running, I get the following errors. My understanding was that the odom->cust_robot/base_link tf was meant to be published by navsat_transform_node. If I add this transform myself, the error goes away but the robot still does not move in RVIZ.

[ WARN] [1611055719.572462689]: Could not obtain transform from cust_robot/base_link to odom. Error was Could not find a connection between 'odom' and 'cust_robot/base_link' because they are not part of the same tree.Tf has two or more un
connected trees.
[ WARN] [1611055721.572495570]: Could not obtain transform from cust_robot/base_link to odom. Error was Could not find a connection between 'odom' and 'cust_robot/base_link' because they are not part of the same tree.Tf has two or more un
connected trees.
[ WARN] [1611055722.572482436]: Could not obtain odom->cust_robot/base_link transform. Will not remove offset of navsat device from robot's origin.
...

The robot and RVIZ configuration:

<launch>
<arg name="namespace" default=""/>
<arg name="use_gui" default="false"/>
<param name="/use_sim_time" value="false"/>

<param name="robot_description" command="xacro --inorder '$(find cust_robot_description)/robots/cust_robot_default.urdf.xacro'" /> <!-- Publish transform for rotations to world frame --> <node pkg="tf" type="static_transform_publisher" name="base_link_tf" args="0 0 0 0 0 0 1 map cust_robot/base_link 30"/> <param name="use_gui" value="$(arg use_gui)"/>

<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />
<node name="rviz" pkg="rviz" type="rviz" args="-d \$(find ...
edit retag close merge delete

Why would robot_localization help your robot move? What do you mean by that? To get the robot to move you should be using something like move_base. Localization will just be used to track its motion right?

( 2021-01-19 09:31:49 -0500 )edit

Apologies, when I mean "move" I mean to track its real-world motion. The platform will more or less currently just be a suite of sensors that need monitoring/visualised (GPS, IMU, Camer, LiDAR, etc,). Actual control will come much further down the line which I guess what move_base is intended for.

( 2021-01-19 09:42:39 -0500 )edit

Sort by » oldest newest most voted

These things are quite difficult to debug but here are some tips how to get started on that.

1. Have a good read of https://www.ros.org/reps/rep-0105.html, especially focus on building an intuition on map and odom frames (it took me quite a while to figure out how they are supposed to work)
2. Afterwards read this: http://docs.ros.org/en/melodic/api/ro... that should give you an idea how to use robot localization with GPS (spoiler alert: you will need to run 2 instances of ekf, one will provide odom->base_link transform and will contain continuous measurements (IMU and odom) and the second one will provide map->odom frame and it will fuse gps odometry (this change will be non-continuous, you can expect odom to jump in map frame a lot)
3. Move your config to .yaml file so that it's more convenient to debug. In your yaml file set the parameter print_diagnostics to true - sometimes it will provide you insights into what's wrong in your setup
4. Start tuning with the continuous frame just with the odometry and imu fused. Then in rviz make sure that you set the fixed frame to odom and double check that the localization works. Once you complete this step move over to implementing the second ekf that will additionally fuse the GPS.
5. For fusing gps you will most likely need to run navsat_transform node. Ideally you should have a heading from your GPS unit.
more


text:
# zbMATH — the first resource for mathematics

On some Turán-type inequalities. (English) Zbl 1095.33002
In this paper the inequalities of the type $$f_n(x)f_{n+2}(x)\geq f_{n+1}^2(x),\quad n=0,1,2,\ldots,$$ ( called by the authors Turán-type inequalities ) are obtained for some special functions. They are proved by using the following generalization of the Schwarz inequality $\int_{a}^{b}g(t)[f(t)]^m \,dt \cdot \int_{a}^{b}g(t)[f(t)]^n \,dt\geq \biggl(\int_{a}^{b}g(t)[f(t)]^{(m+n)/2} \,dt\biggr)^2,$ where $$f, g$$ are nonnegative functions of a real variable and $$m, n$$ are real numbers, such that the integrals exist.

##### MSC:
 33B15 Gamma, beta and polygamma functions 26D15 Inequalities for sums, series and integrals 26D07 Inequalities involving other types of functions
##### Keywords:
Schwarz inequality; Turán-type inequalities
Full Text:
##### References:
 [1] Csordas, G; Norfolk, TS; Varga, RS, The Riemann hypothesis and the Turán inequalities, Transactions of the American Mathematical Society, 296, 521-541, (1986) · Zbl 0602.30030 [2] Elbert, Á; Laforgia, A, Some monotonicity properties of the zeros of ultraspherical polynomials, Acta Mathematica Hungarica, 48, 155-159, (1986) · Zbl 0611.33011 [3] Elbert, Á; Laforgia, A, Monotonicity results on the zeros of generalized Laguerre polynomials, Journal of Approximation Theory, 51, 168-174, (1987) · Zbl 0645.33013 [4] Gradshteyn IS, Ryzhik IM: Table of Integrals, Series, and Products. 6th edition. Academic Press, California; 2000:xlvii+1163. · Zbl 0981.65001 [5] Katkova OM: Multiple positivity and the Riemann zeta-function.http://arxiv.org/abs/math.CV/0505174 · Zbl 0512.34018 [6] Laforgia, A, Sturm theory for certain classes of Sturm-Liouville equations and turánians and Wronskians for the zeros of derivative of Bessel functions, Indagationes Mathematicae, 44, 295-301, (1982) · Zbl 0512.34018 [7] Laforgia A, Natalini P: Turán-type inequalities for some special functions. submitted submitted · Zbl 1126.26017 [8] Lorch, L, Turánians and Wronskians for the zeros of Bessel functions, SIAM Journal on Mathematical Analysis, 11, 223-227, (1980) · Zbl 0446.33011 [9] Pólya G: Collected Papers. Vol. II: Location of Zeros, edited by R. P. Boas, Mathematicians of Our Time. Volume 8. The MIT Press, Massachusetts; 1974. [10] Szegö G: Orthogonal Polynomials, Colloquium Publications. Volume 23. 4th edition. American Mathematical Society, Rhode Island; 1975:xiii+432. [11] Titchmarsh EC: The Theory of the Riemann Zeta-Function. The Clarendon Press, Oxford; 1951:vi+346. · Zbl 0042.07901 [12] Turán, P, On the zeros of the polynomials of Legendre, Časopis Pro Pěstování Matematiky, 75, 113-122, (1950) · Zbl 0040.32303
This reference list is based on information provided by the publisher or from digital mathematics libraries. Its items are heuristically matched to zbMATH identifiers and may contain data conversion errors. It attempts to reflect the references listed in the original paper as accurately as possible without claiming the completeness or perfect precision of the matching.


text:
## Geometry: Common Core (15th Edition)

From $23.5\text{ ft}$ to $24.5\text{ ft}$
The measurement is given to the nearest foot, so the error is $\pm\text{ 0.5 ft}$. Therefore, to find the range of values that the measurement represents, we must both subtract and add $0.5$ to the given value. $$24+0.5=24.5$$$$24-0.5=23.5$$ Therefore the range of values is from $23.5\text{ ft}$ to $24.5\text{ ft}$


text:
# Tricks to Use Python f-strings More Efficiently

F-strings are string literals that begin with a f and curly braces which contain expression which later converted into their values. The expression...
Hey .py devs!

Have you ever used the cool f-strings in your python project?

If no, then you must start using it. But before that let me clear you the following things,

• What are f-strings in python?
• How to use them?
• Why use them?

After all this we will see the cool tricks we are going to talk about in this post.

So let's start learning...

## Introduction

First what is a f-string in python?

### What are f-strings?

F-strings or "formatted string literals" joined the party in the python 3.6 version before that we were using the old school str.format() method.

F-strings are string literals that begin with a f and curly braces which contain expression which later converted into their values. The expressions are evaluated at runtime and then formatted using the __format__ protocol.

### How to use f-strings?

Consider the following code,

>>> name = "Genius"
>>> age = 22
>>> f"Hello, {name}. You are {age}."
'Hello, Genius. You are 22.'

In the above code we used the f and then enclosed the string in quotes(""). The expressions are writtern in curly which will be replaced with their values when the program is executed.

You can also use a capital F,

>>> F"Hello, {name}. You are {age}."
'Hello, Genius. You are 22.'

Now you can start using f-strings in your code.

### Why use f-strings?

As from Python 3.6, f-strings are a great way to format strings. Not only are they more readable, more concise, and less prone to error than other ways of formatting, but they are also faster!

Now you know what are these f-strings, let's see the tricks you can do with them.

## F-strings tricks

Here we have 4 tricks that can be achieved with f-strings and if you find more let me know in the comments!

### 1. Formatting large Numbers

Have you noticed? Generally, while writing large numbers people use the thousands saperators.

The commas separating the numbers in group of three integers. like the number 1234567890 is written as 1,234,567,890.

Similarly in python, f-strings can be used to separate large numbers with thousand separators.

>>> # Without thousand separators
>>> number = 1234567890
>>> print(f"{number} is a large number")
1234567890 is a large number.
>>> # With thousand separators
>>> print(f"{number:,d} is a large number.")
1,234,567,890 is a large number.

In the above code we used the :,d with the variable in curly braces to separate the number with commas.

### 2. Format dates

We can use the f-strings to format dates. or we can specify the format the same way we did in the first trick.
We can use the dates without formatting like other variables in f-strings or represent them in a better way. Like this,

>>> # Without formatting dates
>>> from datetime import datetime
>>> today = datetime.today().date()
>>> print(f"Today is {today}")
Today is 2021-08-01

>>> # With formatting (a better representation)
>>> print(f"Today is {today:%B %d, %Y}")
Today is August 1, 2021

In this way you can represent your dates in a better format with f-strings

### 3. Pad Numbers

Sometimes we see seriel numbers in the form 001, 002, 003... so on. I don't know it makes sense or not to write like this but if you want such format in your code then f-strings are here to help.
In f-strings we can place any number of leading zeroes for a variable. Refer to the code below.

>>> a = 4
>>> b = 2466
>>> print(f"The numbers are \n{a:04} \n{b:04}")
The numbers are
0004
2466

Here a:04 indicates that there will be total of 4 digits and the leading blank spaces will be replaced by zeroes.

### 4. Writing Expressions

Not just variables but f-strings can also be used to write expressions with the literals. To save the time we can write small pieces of code etc. Which means we can perform these operations without going to a new line.
In this code we subtracted the 3 days from the date today, to get the date before 3 days.

>>> # Date manipulation
>>> from datetime import datetime
>>> today = datetime.today().date()
>>> print(f"The results were announced 3 days ago on {today - timedelta(days=3)}.")
The results were announced 3 days ago on 2021-07-29.

The above code involves use of mathematical operations with f-strings. Similarly, we can also use some methods like len() etc. in the f-strings to save time.

>>> list = [1, 3, 5 ,67, 82, 67]
>>> print(f"The list contains {len(list)} items.")
The list contains 6 items.

These are some of the advanced tricks with f-strings which help us to save time and effort in data-science or any python projects we are working on, which involve the use of f-strings. f-strings are the better syntax to format a string literal in a more consie and faster way.

If you find more tricks like this let me know in the comments.

Thank You!