text:
Suggested languages for you:
|
|

## All-in-one learning app

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

# Divergence Test

Sometimes proving that a series diverges can be quite a challenge! Using the Divergence Test, also called the $$n^{th}$$ Term Test for Divergence, is a simple test you can do to see right away if a series diverges. This can save you considerable time in the long run.

## Divergence Tests in Calculus

Many of the tests used for series will have a part that also talks about divergence.

For example, the Direct Comparison Test and the Limit Comparison Test both have a part that talks about convergence and another that talks about divergence. The Integral Test, Ratio Test, and Root Test do as well. Some series, such as the P-series, Geometric series, and Arithmetic series, have known conditions for when they diverge and converge. So when you are looking for divergence tests, be sure to look at Convergence tests as well.

## Series Divergence Tests

Here you will see a test that is only good to tell if a series diverges. Consider the series

$\sum_{n=1}^{\infty} a_n,$

and call the partial sums for this series $$s_n$$. Sometimes you can look at the limit of the sequence $${a_n}$$ to tell if the series diverges. This is called the $$n^{th}$$ term test for divergence.

$$n^{th}$$ term test for divergence.

If

$\lim\limits_{n\to \infty}a_n$

does not exist, or if it does exist but is not equal to zero, then the series

$\sum_{n=1}^{\infty}a_n$

diverges.

What is the wrong way to use the test?

The most common mistake people make is to say that if the limit of the sequence is zero, then the series converges. Let's take a look at an example to show why that isn't true.

Can you use the $$n^{th}$$ term test for divergence to say that if

$\lim\limits_{n\to \infty}a_n=0$

the series converges?

Solution

Let's take a look at two examples.

First look at the Harmonic series

$\sum_{n=1}^{\infty}\frac{1}{n}.$

For this series, we have

$\lim\limits_{n\to\infty}a_n=\lim\limits_{n\to\infty}\frac{1}{n}=0,$

but you know that the series diverges.

Next look at the P-series with $$p=2$$,

$\sum_{n=1}^{\infty}\frac{1}{n^2}.$

If you look at the limit of the sequence of terms for this series, you get,

\begin{align}\lim\limits_{n\to\infty}a_n&=\lim\limits_{n\to \infty}\frac{1}{n^2}\\ &=0\end{align}

as well, but this series converges.

So in fact, if the limit is zero, the series might converge and it might diverge, you just can't tell.

## Proof of the $$n^{th}$$ Term Test for Divergence

Let's take a look at the $$n^{th}$$ term test for divergence is true. Sometimes in math, you prove a statement like "if A is true then B is true", and sometimes it is easier to prove the contrapositive, which is "if B is false then A is false".

For the $$n^{th}$$ term test for divergence, it is easier to show the contrapositive.

So what is the contrapositive for the $$n^{th}$$ term test for divergence?

The statement B is "the series diverges", and saying that "B is false" is the same as saying "the series converges".

The statement A is "the limit of the sequence either doesn't exist or does exist and isn't zero", and "A is false" is the same as saying "the limit of the sequence is zero". That means we will look at the proof of:

If $$\sum\limits_{n=1}^{\infty}a_n$$ converges then

$\lim\limits_{n\to \infty}a_n=0.$

To do this, you will need to look at the partial sums for the series. The sequence of partial sums is defined by $s_n=\sum_{k=1}^{n}a_k.$

The previous term in the sequence of partial sum would be $s_{n-1}=\sum_{k=1}^{n-1}a_k$

Subtracting them gives,

\begin{align} s_{n}-s_{n-1}&=\sum_{k=1}^{n} a_{k}-\sum_{k=1}^{n-1}a_{k}\\&=(a_{1}+a_{2}+\cdots+a_{n-1}+a_{n})-(a_{1}+a_{2}+\cdots+a_{n-1})\\&=a_{n}.\end{align}

You already know that the series converges, which implies that the sequence of partial sums converges as well, or in other words

$\lim\limits_{n\to\infty}s_n=L$

for some real number $$L$$. Now taking the limit of the subtraction of partial sums,

\begin{align}\lim\limits_{n\to\infty}[s_n-s_{n-1}]&=\lim\limits_{n\to \infty}s_n-\lim\limits_{n\to\infty}s_{n-1}\\&=L-L\\&=0.\end{align}

But you also know that

$\lim\limits_{n\to\infty}[s_{n}-s_{n-1}]=\lim\limits_{n\to\infty} a_n,$

which means that

$\lim\limits_{n\to\infty}a_n=0.$

## Examples Using the $$n^{th}$$Term Test for Divergence

Let's look at some examples of how to properly use the $$n^{th}$$ term test for divergence.

What can you say about the convergence or divergence of the series

$\sum_{n=1}^{\infty}\frac{2n+3}{7n-1}$

using the $$n^{th}$$term test for divergence?

Solution

For this series, $a_{n}=\frac{2n+3}{7n-1},$

and

\begin{align}\lim\limits_{n\to\infty}a_n &=\lim\limits_{n\to\infty}\frac{2n+3}{7n-1} \\ &=\frac{2}{7}.\end{align}

So the sequence converges, but the limit isn't zero. Then by the $$n^{th}$$ term test for divergence, the series diverges.

Let's take a look at another example.

What can you say about the convergence or divergence of the series $\sum_{n=1}^{\infty}(-1)^n,$

using the $$n^{th}$$ term test for divergence?

Solution

For this series, $$a_{n}=(-1)^n$$, and the limit of this sequence doesn't exist. So by $$n^{th}$$ term test for divergence, the series diverges.

## Integral Divergence Test

As mentioned already, the Integral Test has a part that talks about divergence. So for more information on divergence when using the Integral Test, see Integral Test.

## Divergence Test - Key takeaways

• Many tests can be used to tell if a series converges or diverges, such as the Integral Test or the Limit Comparison Test.
• The $$n^{th}$$ term test for divergence is a good first test to use on a series because it is a relatively simple check to do, and if the series turns out to be divergent you are done testing.
• If $\sum\limits_{n=1}^{\infty}a_{n}$ converges then $\lim\limits_{n\to\infty}a_n=0.$

• $$n^{th}$$ term test for divergence: If $\lim\limits_{n\to\infty}a_{n}$

does not exist, or if it does exist but is not equal to zero, then the series $\sum_{n=1}^{\infty} a_n$ diverges.

It is a way to look at the limit of the terms of a series to tell if it diverges.

Look at the limit of the terms of the series.  If that limit is not zero then the series diverges.

The divergence test is a good one to use on any series as a basic check.  If the divergence test shows the series doesn't converge, then you are done testing.

By looking at the difference of the partial sums.

We say that a series is convergent if its partial sum converges to a finite limit. If the partial sum does not have a finite limit, or the limit does not exist, the series is divergent.

## Final Divergence Test Quiz

Question

What is a good first test to do to see if a series diverges or converges?

The nth term test for divergence.  It is relatively simple to apply it to see if the series diverges.  If it diverges, you are done testing.

Show question

Question

Is the nth term test for divergence the only divergence test?

No, there are lots of tests that also look at divergence in addition to convergence, e.g. the Integral Test, the Ratio Test, and the Root Test.  Not to mention the Direct Comparison Test and the Limit Comparison Test.

Show question

Question

What is the wrong way to use the $$n^{th}$$ term divergence test?

The most common mistake people make is to say that if the limit of the sequence is zero, then the series converges.

Show question

Question

If

$\lim\limits_{n\to \infty}a_n$

does not exist what can you say about convergence of

$\sum_{n=1}^{\infty}a_n?$

By the $$n^{th}$$ term test for divergence, you can say the series diverges.

Show question

Question

If

$\lim\limits_{n\to \infty}a_n \ne 0$ what can you say about convergence of the series

$\sum_{n=1}^{\infty}a_n?$

By the $$n^{th}$$ term test for divergence, you can say the series diverges.

Show question

Question

If

$\lim\limits_{n\to \infty}a_n = 0$ what do you know about convergence of the series

$\sum_{n=1}^{\infty}a_n ?$

Nothing.  That isn't enough information to tell if the series converges or diverges.

Show question

Question

Is it true that if  $$\sum\limits_{n=1}^{\infty}a_n$$ converges then

$\lim\limits_{n\to \infty}a_n=0?$

Yes.  This is the contrapositive of the $$n^{th}$$ term test for divergence.

Show question

Question

Is it true that if $$\sum\limits_{n=1}^{\infty}a_n$$ diverges then

$\lim\limits_{n\to \infty}a_n=0?$

No, just knowing the series diverges doesn't tell you anything about the limit of the sequence.

Show question

Question

Why do you use the $$n^{th}$$ term test on a new series as a first test?

Because it is relatively simple to use and can save you a lot of work checking the various convergence tests.

Show question

Question

Other than the $$n^{th}$$ term test, what is another test used to check for divergence?

The Integral Test.

Show question

Question

What is the contrapositive of the statement "if A is true then B is true"?

The contrapositive is "if B is false then A is false"

Show question

Question

Give an example of a series where

$\lim\limits_{n\to \infty}a_n=0$

but the corresponding series converges.

The P-series with $$p=2$$

Show question

Question

Give an example of a series where

$\lim\limits_{n\to \infty}a_n=0$

but the corresponding series diverges.

The Harmonic Series.

Show question

60%

of the users don't pass the Divergence Test quiz! Will you pass the quiz?

Start Quiz

## Study Plan

Be perfectly prepared on time with an individual plan.

## Quizzes

Test your knowledge with gamified quizzes.

## Flashcards

Create and find flashcards in record time.

## Notes

Create beautiful notes faster than ever before.

## Study Sets

Have all your study materials in one place.

## Documents

Upload unlimited documents and save them online.

## Study Analytics

Identify your study strength and weaknesses.

## Weekly Goals

Set individual study goals and earn points reaching them.

## Smart Reminders

Stop procrastinating with our study reminders.

## Rewards

Earn points, unlock badges and level up while studying.

## Magic Marker

Create flashcards in notes completely automatically.

## Smart Formatting

Create the most beautiful study materials using our templates.


text:
SEARCH CONTENT

You are looking at 1 - 10 of 19,388 items :

• Chemistry
• Organic Chemistry
• Nuclear Chemistry
Clear All

Abstract

Three new coordination complexes [Zn(btec)0.5(L1)0.5(H2O)]n (1), [Ni(H2btec)(L1)(H2O)2]n (2), and {[Ni(btec)0.5(L2)(H2O)3]·2H2O}n (3) [H4btec = 1,2,4,5-benzenetetracarboxylic acid), L1 = N,N′-bis(3-pyridyl)adipamide, L2 = N,N′-bis(3-pyridyl)octanediamide] have been obtained under hydrothermal conditions. Single-crystal X-ray diffraction analysis has revealed that complex 1 has a layer structure based on [Zn(btec)0.5]n ribbons and the μ 2-bridging ligands L1. Complex 2 possesses a layered framework constructed by [Ni(H2btec)]n linear chains and [Ni(L1)]n wave-like chains. Complex 3 forms layers based on [Ni(L2)]n helical chains and μ 2-bridging L2 ligands, representing an interesting 4-fold interpenetrating 2D braided framework. The three different 2D frameworks exhibit 3,4-connected {4.62}2{42.62.82} topology for 1, 4-connected {44.62} topology for 2 and 3-connected {63} topology for 3. Their adjacent layers are further linked by hydrogen bonding interactions to generate 3D supramolecular structures. The differences in the nature of both the metal ions and the organic ligands lead to various coordination modes in the final structures. The photocatalytic activities and the fluorescence properties of complexes 13 were investigated.

Abstract

A detailed structural analysis has been carried out on the monohydrate of (E)-3-(2-hydroxy-5-methoxyphenyl)-1-(2-hydroxy-4-methoxyphenyl)prop-2-en-1-one, 1·H 2 O. The molecule, 1, shows a small deviation from planarity with an interplanar angle between the phenyl groups of 13.32(6)°. Classical O–H⋯O hydrogen bonds involving the water molecule play significant roles in determining the overall structure. The chalcone molecules in the structure are linked directly by C–H⋯O and off-set face-to-face π⋯π intermolecular interactions, as well as indirectly via interactions involving the water molecule in an elaborate spiralling hydrogen bonding scheme. The relative contributions of various intermolecular contacts were investigated using Hirshfeld surface analysis and the associated two dimensional fingerprint plots. Pairs of molecules were identified in the crystal structure using the Pixel method. The Pixel lattice energy calculations revealed that the dispersion and the Coulombic components were the major contributors to the packing stabilization. Comparisons were made between the structures of 1·H 2 O and hydroxylated (E)-3-(2-hydroxyphenyl)-1-phenyl-prop-2-en-1-one derivatives, in particular in regards to the participation of π interactions.

FREE ACCESS

Abstract

The rare earth oxoborates REB5O8(OH)2 (RE = Ho, Er, Tm) were synthesized in a Walker-type multianvil apparatus at a pressure of 2.5 GPa and a temperature of 673 K. Single-crystal X-ray diffraction data provided the basis for the structure solution and refinement. The compounds crystallize in the monoclinic space group C2 (no. 5) and are composed of a layer-like structure containing dreier and sechser rings of corner sharing [BO4]5− tetrahedra. The rare earth metal cations are coordinated between two adjacent sechser rings. Further characterization was performed utilizing IR spectroscopy.

FREE ACCESS

Abstract

Layer diffusion of 3,5-bis(4-pyridyl)-1H-1,2,4-triazole (BptH) in ethanol on an aqueous solution of cadmium sulfate leads to a novel three-dimensional cadmium sulfate-based inorganic-organic hybrid polymer (IOHP), CdSO4(H2O)(BptH)·1.5H2O (1). Its structure was determined by single-crystal X-ray diffraction (SCXRD), and further characterized by elemental analysis, powder X-ray diffraction (PXRD), infrared spectra (IR), and thermogravimetric (TG) analysis. IOHP 1 exhibits a novel 2-nodal 3,5-connected nanoporous structure formed by BptH ligands connecting 2D neutral inorganic cadmium sulfate layers. Water molecules reside in its nanoporous channels. The thermal stability and solid-state photoluminescence properties of the compound have also been investigated.

Abstract

A variety of 4-methoxysalicylates and related polyketide-type phenols are regioselectively prepared by formal [3+3] cyclocondensations of 1,3-bis(trimethylsilyloxy)-1,3-butadienes with 3-oxo-orthoesters. Cycloalkyl-substituted salicylates were prepared for the first time.

Abstract

The crystal and molecular structures of vardenafil (free, unprotonated base), vardenafil dihydrate and the hydrochloride salts, vardenafil monohydrochloride trihydrate and vardenafil dihydrochloride hexahydrate, were determined by single-crystal X-ray diffraction. The crystal structure of vardenafil monohydrochloride trihydrate is in good agreement with the published crystal structure obtained by powder diffraction using synchrotron radiation. This work shows that the crystal structure of anhydrous vardenafil free base is very similar to the crystal structure of sildenafil free base.

Abstract

Based on 2-(4-pyridyl)-terephthalate (H2pta) and oxalate ligands, two new lanthanide-containing coordination polymers (CPs), [Tb(pta)(C2O4)0.5(H2O)2)]·2H2O (1) and [Sm(pta)(C2O4)0.5(H2O)2)]·2H2O (2), have been synthesized under solvothermal conditions. The structures of both 1 and 2 have been determined by single-crystal X-ray diffraction. Infrared, elemental analysis, powder X-ray diffraction and thermogravimetric analysis data are also presented. The crystals of 1 and 2 exhibit isostructural layer-like networks, crystallizing in the triclinic space group P $1‾$. The layers are further stabilized and associated into 3D architectures through hydrogen bonding. Remarkably, the CPs 1 and 2 exhibit excellent water stability and remarkable thermostability with thermal decomposition temperatures of more than 420 °C.

Abstract

Two new coordination polymers (CPs), [Zn(npba)2] (1) and [Cd(npba)2] (2), have been hydrothermally synthesized from Zn(NO3)2·6H2O/Cd(NO3)2·6H2O and 3-nitro-5-(pyridin-3-yl) benzoic acid (Hnpba). The products have been characterized by IR spectroscopy, elemental analysis, thermogravimetric analysis, and single-crystal X-ray diffraction. In CP 1, the four-coordinated Zn(II) centers are bridged by npba ligands to generate chains, which are connected through arene π–π stacking interactions to generate a layer structure. In CP 2, the six-coordinated Cd(II) centers are also bridged by npba ligands to form chains with similar connectivity. The photoluminescence properties of CPs 1 and 2 were studied.

format: plain


text:
# Numerical method for finding the square-root.

I found a picture of Evan O'Dorney's winning project that gained him the first place in the Intel Science talent search. He proposed a numerical methods to find the square root, that gained him $100,000$ USD.

Below are some links of pictures of the poster displaying the method.

How does this numerical method to find square-root work and what is the proof?

His method makes use of Moebius Transformation.

-
Since both answers missed it (and my shoulder hurts too much to answer myself), I'd like to point out that the picture suggests that rather than applying $f$ iteratively to an initial value, you instead compute the sequence of compositions $f^{(2^n)}$. – Hurkyl Oct 28 '12 at 2:37

Essentially if you are interesting in evaluating $\sqrt{a}$, the idea is to first find the highest square below $a$. Say this is $b$ i.e. $b = \lfloor \sqrt{a} \rfloor \implies b^2 \leq a < (b+1)^2$. Then consider the function $$f(x) = b + \dfrac{a-b^2}{x+b}$$ $$f(b) = b + \underbrace{\dfrac{a-b^2}{2b}}_{\in [0,1]} \in [b,b+1]$$ $$f(f(b)) = b + \underbrace{\dfrac{a-b^2}{f(b) + b}}_{\in [0,1]} \in [b,b+1]$$ In general $$f^{(n)}(b) = \underbrace{f \circ f \circ f \circ \cdots f}_{n \text{times}}(b) = b + \dfrac{a-b^2}{f^{(n-1)}(b)+b}$$ Hence, $f^{(n)}(b) \in [b,b+1]$ always.

If $\lim_{n \to \infty}f^{(n)}(b) = \tilde{f}$ exists, then $$\tilde{f} = b + \dfrac{a-b^2}{\tilde{f}+b}$$ Hence, $$\tilde{f}^2 + b \tilde{f} = b \tilde{f} + b^2 + a - b^2 \implies \tilde{f}^2 = a$$

To prove the existence of the limit look at $$(f^{(n)}(b))^2 - a = \left(b + \dfrac{a-b^2}{f^{(n-1)}(b)+b} \right)^2 - a = \dfrac{(a-b^2)(a-(f^{(n-1)}(b))^2)}{(b+f^{(n-1)}(b))^2} = k_{n-1}(a,b)((f^{(n-1)}(b))^2-a)$$ where $\vert k_{n-1}(a,b) \vert <1$. Hence, convergence is also guaranteed.

EDIT

Note that $k_{n-1}(a,b) = \dfrac{(a-b^2)}{(b+f^{(n-1)}(b))^2} \leq \dfrac{(b+1)^2 - 1 - b^2}{(b+b)^2} = \dfrac{2b}{(2b)^2} = \dfrac1{2b}$. This can be interpreted as larger the number, faster the convergence.

Comment: This method works only when you want to find the square of a number $\geq 1$.

EDIT

To complete the answer, I am adding @Hurkyl's comment. Functions of the form $$g(z) = \dfrac{c_1z+c_2}{c_3z+c_4}$$are termed Mobious transformations. With each of these Mobius transformations, we can associate a matrix $$M = \begin{bmatrix} c_1 & c_2\\ c_3 & c_4\end{bmatrix}$$ Note that the function, $$f(x) = b + \dfrac{a-b^2}{x+b} = \dfrac{bx + a}{x+b}$$ is a Mobius transformation.

Of the many advantages of the associated matrix, one major advantage is that the associate matrix for the Mobius transformation $$g^{(n)}(z) = \underbrace{g \circ g \circ \cdots \circ g}_{n \text{ times}} = \dfrac{c_1^{(n)} z + c_2^{(n)}}{c_3^{(n)} z + c_4^{(n)}}$$ is nothing but the matrix $$M^n = \begin{bmatrix}c_1 & c_2\\ c_3 & c_4 \end{bmatrix}^n = \begin{bmatrix}c_1^{(n)} & c_2^{(n)}\\ c_3^{(n)} & c_4^{(n)} \end{bmatrix}$$ (Note that $c_k^{(n)}$ is to denote the coefficient $c_k$ at the $n^{th}$ level and is not the $n^{th}$ power of $c_k$.)

Hence, the function composition is nothing but raising the matrix $M$ to the appropriate power. This can be done in a fast way since $M^n$ can be computed in $\mathcal{O}(\log_2(n))$ operations. Thereby we can compute $g^{(2^n)}(b)$ in $\mathcal{O}(n)$ operations.

-
To Marvis -Does this method garuantee that it at least gain one extra correct decimal place when it iterate once? – Victor Oct 28 '12 at 1:37
This converges linearly, which can be interpreted as saying that roughly each iteration gives one more digit accuracy. – user17762 Oct 28 '12 at 1:45
Marvis - Apreciate for your answer! – Victor Oct 28 '12 at 1:48
@Victor Consecutive approximations say $f^{(n)}$ and $f^{(n+1)}$ decreases the error by a factor if $\dfrac1{2b}$ at each step. So if $b \geq 5$, we can recover one digit with every recursion. If $b \geq 50$, we can recover two digits with every recursion and so on. – user17762 Oct 28 '12 at 1:54
Marvis - Appreciate for your edit, it will take me a extra few hour without your edit! – Victor Oct 28 '12 at 1:59

The iteration to find $\sqrt k$ is $f(x) = \frac{d x+k}{x+d}$ where $d = \lfloor \sqrt k \rfloor$. The iterations start with $x = d$.

If $x$ is a fixed point of this, $x = \frac{d x+k}{x+d}$, or $x(x+d) = dx + k$ or $x^2 = k$, so any fixed point must be the square root.

Now wee see if the iteration increases or decreases. If $y = \frac{d x+k}{x+d}$, $$y - x = \frac{d x+k}{x+d} - x = \frac{d x+k - x(x+d)}{x+d} = \frac{k - x^2}{x+d}$$ so if $x^2 < k$, $y > x$ and if $x^2 > k$, $y < x$.

Also, proceeding like analyses of Newton's method, $y^2-k = \frac{(d x+k)^2}{(x+d)^2} - k = \frac{d^2 x^2 +2 d x k + k^2 - k(x+d)^2}{(x+d)^2} = \frac{d^2 x^2 +2 d x k + k^2 - k(x^2 + 2dx +d^2)}{(x+d)^2} = \frac{d^2 x^2 +2 d x k + k^2 - kx^2 - 2dkx -kd^2)}{(x+d)^2} = \frac{d^2 x^2 + k^2 - kx^2 -kd^2)}{(x+d)^2} = \frac{d^2 (x^2-k) + k^2 - kx^2)}{(x+d)^2} = \frac{d^2 (x^2-k) - k(x^2-k))}{(x+d)^2} = \frac{(d^2-k) (x^2-k)}{(x+d)^2} = (x^2-k)\frac{d^2-k}{(x+d)^2}$.

Since $d = \lfloor \sqrt k \rfloor$, $d < \sqrt k < d+1$ or $d^2 < k < d^2 + 2d +1$ or $-2d - 1 < d^2 - k < 0$, so $|d^2-k| < 2d+1$. Using this, $|y^2-k| < |x^2-k|\frac{2d+1}{(x+d)^2}| = |x^2-k|\frac{2d+1}{x^2+2dx+d^2}$, so $|y^2-k|< |x^2-k|$, and each iteration gets closer to the square root.

Since the starting iterate is $d$, all following iterates exceed $d$ so $|y^2-k| < |x^2-k|\frac{2d+1}{(d+d)^2}| < |x^2-k|\frac{2d+1}{4d^2}| < |x^2-k|\frac{1+1/(2d)}{2d}| \le 3|x^2-k|/4$ since $d \ge 1$.

This show that the iteration converges. However, this does not show that it converges quadratically like Newton's, only that it converges linearly.

-


text:
# Measure ALL the things

My multimeter has been all nicely soldered together for a while now, but it didn’t actually do anything. Doing something is obviously an important criterion for actually being a multimeter, so this was an issue that I needed to address.

I need to measure voltage, current, capacitance and resistance, over large ranges and with reasonable precision. I’m doing all of this with the AVR’s 10 bit successive-approximation analogue-to-digital converter (ADC), although I’m getting 12 bits of precision out of it by oversampling.

I’ll post the schematic here – you might want to keep it open in another tab, because I’ll refer back to it. A lot.

### Voltage

Voltage was the first on the chopping block. To get a decent range, I used the battery supply voltage as the reference for the ADC; this means that the converter measures the scaled voltage as a fraction of the battery voltage, between 0 and 100%.

The problem with this is that the battery voltage is by nature not constant! I needed to measure the battery voltage. To do this, I delved deep into the ancient and terrible tome that is the AVR datasheet.

Pictured: the first copy of the AVR datasheet. Printed on human skin, blood for ink

The ATmega32PA (the microcontroller on my meter) has a rarely-used but very useful feature: an internal bandgap voltage reference. In principal it’s similar to an LED and a current source of a few microamps. What this does is give me a known voltage of 1.1V: if I use the ADC to measure this reference, as a fraction of the battery voltage, I can then calculate the battery voltage. This gives me a transfer standard with which to measure everything else.

Reading the datasheet (page 255) I eventually came up with the magical incantation which makes this measurement work:

#define VIN_BANDGAP 0x1e
{
ADMUX = 0x40 | pin; // AREF = VCC
ADCSRA = 0x87;      // Enabled, clk/64 = 125kHz
return result | (((uint16_t)ADCH) << 8);
}

uint16_t get_battery_voltage()
{
ADMUX = 0x5e;   // AREF = VCC, input = 1.1v bandgap reference
ADCSRA = 0x86;  // ADC enabled, don't start conversion yet, auto trigger off, no interrupt, ck/128 = 62.5 kHz
_delay_us(500);
uint32_t result = 0;
for (int i = 16; i; --i)
{
}
return 4538487 / result;   // = 1024 (number of ADC steps) * 1.1 (bandgap voltage) * 16 (number of readings) * 256 (fxp88 fixed point)
}

Taking 16 readings and averaging them increases the effective number of bits by two, because it increases the signal-to-noise ratio by four. (See: Wikipedia)

We then divide a big integer constant by this sum, and the result is the battery voltage in an 8.8 fixed point format. The exact value of this constant is not quite the one described in the comments: it varies slightly with each chip, and was derived by cross-referencing the value from this function with an actual measurement of the battery voltage. Sorted.

The 0.5ms delay is to allow the bandgap reference (which has a very high output impedance) to charge the AVR’s internal capacitance to the correct value – not giving it time to settle led to a very peculiar problem. More on this later!

We can now actually measure the voltage.

#define PORT_VATTEN PORTA
#define DDR_VATTEN DDRA
#define VATTEN_1M 0x20
#define VATTEN_100k 0x10
#define VATTEN_5k 0x04
#define VATTEN_ALL (VATTEN_1M | VATTEN_100k | VATTEN_5k)

#define VIN_V 6

{
uint16_t result = 0;
for (uint8_t i = 16; i; --i)
{
}
return result >> 2;
}

uint8_t voltage_range = 0;
void set_voltage_range(uint8_t range)
{
uint8_t range_attens[] = {VATTEN_1M, VATTEN_100k, VATTEN_5k};
DDR_VATTEN |= VATTEN_ALL;
PORT_VATTEN &= ~VATTEN_ALL;
PORT_VATTEN |= range_attens[range];
}

float get_voltage()
{
set_voltage_range(voltage_range);
uint16_t lower_limits[] = {0, 151, 49};
uint16_t upper_limits[] = {941, 805, 1024};
uint16_t multipliers[] = {2, 11, 201};

if (result < lower_limits[voltage_range])
voltage_range--;
else if (result > upper_limits[voltage_range])
voltage_range++;

_delay_us(10);

uint32_t battery = get_battery_voltage();
}

get_adc_12bit() is a quick-and-easy function which gets a 12-bit reading from the AVR’s 10-bit ADC by averaging 16 readings – see Atmel’s app note on oversampling and decimation.

set_voltage_range() is for controlling the attenuation circuitry at the front end of the multimeter – see the upper left of the schematic. All voltage measurements go through a fixed-gain op amp circuit, but switching the MOSFETs allows the voltage to be attenuated first by different voltage dividers, so large voltages can be scaled down in order to measure  them.

get_voltage() needs only to select the appropriate range and then scale the 12-bit reading to get the final voltage. This was originally all fixed-point maths, which worked perfectly, but I gave in and used floats because it’s just easier.

I stuck a 1602 display and a shift register onto the logic analyser header (which should be input but I’m using it as an output for now) so that I can have some form of readout until the proper screens arrive. Here I’m measuring the 32-ish volt output from my power supply:

Looks good! There is a problem though:

Voltage seems to drop off significantly towards the upper end of each range (the meter clicks up a range at about 3.8 volts). Due to the very high impedance of the attenuator circuitry, I initially assumed this was due to leakage currents in the MOSFETs, and was dreaming up all sorts of compensation schemes. As it turned out, it was due to this line I mentioned earlier in the battery voltage measurement:

_delay_us(500);

Without this line (or when the delay is smaller, on the order of 10us) we have the problem above; with it, we do not. When the ADC input is switched from the voltage input (at a higher voltage) to the reference, if it is not given time to settle then the reference will read as being a higher voltage than it is, and so the calculated battery voltage will be smaller. The measured voltage will be scaled down accordingly. This effect becomes more pronounced at higher voltages, which explains the downward nosedive seen above.

### Current

Current measurement was much more straightforward:

void switch_current(bool onoff)
{
DDR_IGATE |= IGATE;
if (onoff)
PORT_IGATE |= IGATE;
else
PORT_IGATE &= ~IGATE;
}

float get_current()
{
switch_current(CURRENT_ON);
_delay_us(50);
}

Again, this was originally all fixed point maths, but I converted to a float at the end. I’m after peace of mind, not efficiency!

The meter can measure up to about 1.7A, and will happily take 1 amp continuously with little or no heating effects.

The Megameter agrees with my Extech EX330 to within 1% across its range, and measures with a resolution (and pretty much an accuracy) of 1mA, which is “good enough”.

In between these two photos I had an accident which involved having to reflow, remove and replace soldered SMD parts with a frying pan – hence the missing buttons!

The measurement circuitry consists of nothing more than a 0.22ohm shunt resistor, the beefiest MOSFET I have ever seen in a SOT23 package (put in as many vias as I could so that I could use the planes as a heatsink), and a fixed 11x gain op amp circuit. Does the job!

### Capacitance

The final measurement which I have tackled so far is capacitance. The meter has a useful range of 1nF -> >600uF, which is far better than my EX330, as well as being about as accurate. It’s based on the well-known principle of RC discharge curves – by discharging the capacitor, charging it through one of a range of resistors (for various ranges of capacitance value), and then timing how long it takes to reach a certain threshold voltage, it’s possible to calculate the capacitance. I derived this formula:

$C = \frac{-t}{R \ln(1 - \frac{V_{trig}}{V_{cc}})}$

Vtrig is the threshold voltage at which the capacitor stops charging. To give this a known value, I used the internal bandgap reference, and the AVR’s analogue comparator to detect when the capacitor reaches this voltage. This involved yet more datasheet black magic:

inline void set_rc_range(uint8_t range)
{
uint8_t ranges[] = {RC_LOW, RC_MID, RC_HI};
DDR_RC &= ~(RC_LOW | RC_MID | RC_HI);
PORT_RC &= ~(RC_LOW | RC_MID | RC_HI);
DDR_RC |= ranges[range];
PORT_RC |= ranges[range];
}

uint8_t cap_range = 2;

// Timer 1 overflow vector: stop the timer, set its result back to a large value,
// jump up a range, and force the wait loop to exit.
ISR(TIMER1_OVF_vect) {
TCCR1B = 0x00;
cap_range--;
TCNT1 = 0xfff0;
}

void choose_cap_range(float result)
{
// all values are in microfarads
switch(cap_range)
{
case 0:
cap_range++;
break;
case 1:
if (result < 5.f)
cap_range++;
break;
case 2:
if (result > 6.f)
cap_range--;
else if (result < 0.5f)
cap_range++;
break;
case 3:
if (result > 0.6f)
cap_range--;
break;
}
}

float get_capacitance()
{
uint16_t resistances[] = {47, 470, 20000, 20000};
uint8_t divisors[] = {1, 1, 1, 8};          // compensates for timer clock frequency differences
uint8_t tccrs[] = {0x02, 0x02, 0x02, 0x01}; // selects the clock frequency input to the timer
uint8_t subtractors[] = {1, 1, 1, 10};      // compensates for code execution time

// let the RC_SENSE net float by switching off the current pass MOSFET
switch_current(CURRENT_OFF);

// Get values ready to plug into registers (timing is critical later)
uint8_t rc_range = cap_range;
if (rc_range > 2)
rc_range = 2;
uint8_t tccr_start = tccrs[cap_range];

// Switch off the ADC so we can use its multiplexer, and set up the comparator:
ADCSRB = 0x40;  // ACME = 1 (connect ADC multiplexer to the comparator)
ADMUX = VIN_RC; // RC pin connected to comparator negative input
ACSR = 0x40;    // 1.1v bandgap reference connected to comparator positive input

// connect RC -> 47 ohms -> ground, float other pins, then wait 50ms for discharge
set_rc_range(0);
PORT_RC &= ~RC_LOW;
DDR_RCSENSE &= ~RC_SENSE;
PORT_RCSENSE &= ~RC_SENSE;
_delay_ms(50);

// set up timer1
TCCR1A = 0x00;
TCCR1B = 0x00;
TCNT1 = 0;
TIMSK1 = 0x01; // overflow interrupt enabled
sei();

// connect rc -> resistance -> vcc and start timer.
set_rc_range(rc_range);
TCCR1B = tccr_start;

// exits when comparator outputs 0 (voltage has reached 1.1v) or the timer overflow interrupt has fired
// stop timer and float pins
TCCR1B = 0x00;
DDR_RC |= RC_LOW;
PORT_RC &= ~RC_LOW;
// C = -t / (R * ln(1 - Vtrig / Vcc)
float result = -((float)(TCNT1 - subtractors[cap_range]) / divisors[cap_range]) / (log(1 - 1.03f / (get_battery_voltage() * (1/256.f))) * (float)resistances[cap_range]);
choose_cap_range(result);
return result;
}

I initially had trouble making the comparator code work. I was doing this in the wait loop, to wait until the analogue comparator output (ACO) went low: (capacitor is connected to the inverting input)

while (ACSR & ACO);

The “gotcha” here is that the constant ACO, defined by avr/io.h, is the bit position (5), not the bit value (0x20). The idiomatic way of doing this is to write

while (ACSR & (1 << ACO));

But this looks stupid, so I just used the hex constant (in a named variable, whose purpose will be explained shortly).

The only other complicating factor is that of timer overflows. The timer is a 16 bit counter, clocked at either 1 or 8MHz depending on range, so it will overflow after either 65ms or 8ms. You could detect this overflow by doing a comparison against a value suitably lower than 0xffff in the wait loop, but every single instruction in this loop reduces the precision of the measurement.

The comparison can be made faster by comparing only the high byte, but this still reduces the precision. If only a processor had a way of handling asynchronous events separate to the main flow of execution… wait.

The timer is set up to trigger an interrupt when it overflows. The interrupt itself is handled by separate silicon, and does not slow down execution until it is actually triggered, at which point execution jumps to the service routine.

The interrupt stops the timer, changes the ACO mask to zero (which forces the while loop to exit), sets the count back to a very large value, and bumps the capacitance range up by one.

I stuck all of this together into a main function that lets me choose measurement by clicking on the buttons.

Up next: resistance measurement, SPI flash and TV remote!


text:
# Revision history [back]

### Finding complex roots

So, what is the best way to find complex roots of polynomials?

I only found that one:

sage: from sage.rings.polynomial.complex_roots import complex_roots
sage: x=polygen(ZZ)
sage: complex_roots(1.3*x^3-x^2-5*x-1)
[(-1.479272103982880?, 1), (-0.2113935621844148?, 1),
(2.459896435398064?, 1)]

Should I use that? Isn't there an inbuilt function? Even PARI/GP has one, namely polroots...

And why is the x casted as an element of $\mathbb{Z}$, why not $\mathbb{C}$? Can somebody explain that to me?

Thank you!

### Finding complex roots

So, what is the best way to find complex roots of polynomials?

I only found that one:

sage: from sage.rings.polynomial.complex_roots import complex_roots
sage: x=polygen(ZZ)
sage: complex_roots(1.3*x^3-x^2-5*x-1)
[(-1.479272103982880?, 1), (-0.2113935621844148?, 1),
(2.459896435398064?, 1)]

Should I use that? Isn't there an inbuilt function? Even PARI/GP has one, namely polroots...

And why is the x casted as an element of $\mathbb{Z}$, $\mathbb{Z}[X]$, why not $\mathbb{C}$? $\mathbb{C}[X]$? Can somebody explain that to me?

Thank you!

 3 retagged rws 1059 ●1 ●16 ●37 http://google.com/+Ral...

### Finding complex roots

So, what is the best way to find complex roots of polynomials?

I only found that one:

sage: from sage.rings.polynomial.complex_roots import complex_roots
sage: x=polygen(ZZ)
sage: complex_roots(1.3*x^3-x^2-5*x-1)
[(-1.479272103982880?, 1), (-0.2113935621844148?, 1),
(2.459896435398064?, 1)]

Should I use that? Isn't there an inbuilt function? Even PARI/GP has one, namely polroots...

And why is the x casted as an element of $\mathbb{Z}[X]$, why not $\mathbb{C}[X]$? Can somebody explain that to me?

Thank you!


text:
# Are all quartic graphs represented as flat knots?

I am thinking about flat knots and how they can represent graph. Most flat knots have a cord following an over-under pattern connecting back to itself. Here's a tripled up knot:

These sorts of knots must be quartic since all graphs with Eulerian circuits exist in even node connected graphs. Well, that and the fact any two cords crossing give four and only four edges.

Let $G$ be a connected, planar, quartic graph consisting of edges $E$ and nodes $V$.

Let $e_1, \dots, e_m$ be an Eulerian circuit of edges and $n_1,\dots, n_{m-1}$ be the corresponding nodes connecting consecutive edges. That is, $n_i$ connects edges $e_i$ and $e_{i+1}$. Additionally, let there be an $m$th node $n_m$ that connect $e_m$ and $e_1$.

My question is: Does there exist a map $f:V \to \{0, 1\}$ and an Eulerian circuit as specified above, such that $f(n_i)$ alternatives between $0$ and $1$? What are the necessary and sufficient conditions for a connected quartic graph for the above to hold?

• Can you define what a flat knot and a quartic graph are? Also, in your Eulerian circuit, are you labeling some nodes twice? Aug 29, 2016 at 15:49
• A quartic graph is a graph where all nodes are order 4. The sequence of nodes may include duplicates. These are sequences, not enumerations. By flat knot, I mean what is written in the last paragraph. Aug 29, 2016 at 15:52
• All prime knots with at most 7 crossings are alternating knots, so to get a counterexample to your question (which I suspect exists), you want a good number of crossings.
– user98602
Aug 29, 2016 at 15:58
• Also, "most" knots are absolutely not alternating. Just the small ones.
– user98602
Aug 29, 2016 at 16:48
• I'm not talking about mathematical knots. I'm talking about decorative ones. Most of the decorative flat knots I see in books are alternating. Aug 29, 2016 at 19:36

Let $G$ be a connected, planar, quartic graph and suppose we found a map $f$ and eulerian circuit as described in the question.
Since the degree of each vertex is four, then in the Eulerian circuit, each vertex $v$ must be included exactly twice in the sequence of nodes corresponding to the Eulerian circuit, say at index $i$ and $j$. Notice if the parity of $i$ and $j$ differ, then our map no longer has its alternating property (since $f(n_i) = f(n_j)$ and the difference between $i$ and $j$ is odd). Thus, it must be the case that the parity of $i$ and $j$ is the same and we can assign this parity to vertex $v$. If the parity is even, we'll say that $v$ is even-indexed, if it is odd, we'll say $v$ is odd-indexed.
This partitions the vertices of $G$ into even-indexed and odd-indexed vertices. Notice that due to the construction of Eulerian circuit, if we have an even number of vertices, then even-indexed vertices are only adjacent to odd-indexed vertices and odd-indexed vertices are only adjacent to even-indexed vertices and thus $G$ is in fact bipartite where each partition contains equal amounts of vertices (i.e. $G$ is a balanced bipartite graph).
If the number of vertices is odd, then we have something close to a bipartite graph with an added edge within one of the partitions. I would assume that you want you would want the alternating property of $f$ to also "loop back" in a sense though, i.e., $f(n_m) \neq f(n_1)$. This can only happen if the number of vertices is even, so we can throw out the case of an odd number of vertices if we want the alternating to loop back.
It's not too computationally taxing to determine if a graph is bipartite and to find the two partitions. If we are trying to find a Eulerian circuit and a mapping $f$ for $G$, we can simply test for bipartiteness and find the partitions. If the graph is not bipartite, we know that no circuit and mapping exist. If $G$ is bipartite, it suffices to pick any Eulerian circuit and map the vertices in one partition to $0$ and map the vertices in the other partition to $1$.


text:
Mixed Cauchy and Dirichlet and unspecified boundary conditions for Laplace equation on $I^2$

I am looking for a reference where the following problem is discussed:

$$u \in C^{\infty}(I^2)$$ so that

• $$\Delta u = 0$$
• $$u(0,y) = f(y)$$, $$u(1,y) = g(y)$$, $$u(x,0) = h(x)$$
• $$\nabla u(x,0) \cdot \hat{n} (x,0) = a(x)$$

Assume $$f'(0) = a(0)$$ and $$g'(0) = a(1)$$.

That is, $$u$$ is harmonic in $$I^2 = [0,1]^2$$, and subject to certain mixed and overlapping boundary conditions -- Dirichlet conditions on the three sides, and Neumann conditions on one of those sides, and the fourth side is left unspecified. (In other words, on one side there is are no conditions, and on two opposite sides there is a Dirichlet boundary condition, and on one side there is a Cauchy boundary condition.)

Specifically, I am interested in the conditions on $$f,g,a,b$$ necessary for a solution to exist, and to be unique, and for a (reasonably) explicit solution.

Some appropriate terms to search would also be very welcome.

P.S. I'm not especially committed to the Laplace equation -- it's the boundary conditions along with existence and uniqueness that are more important for my purpose right now. I'd be interested in replacing $$\Delta u = 0$$ by another PDE in order to get a problem that has existence and uniqueness for these boundary conditions - though the problem as I formulated it above has certain advantages from my point of view.


text:
💬 👋 We’re always here. Join our Discord to connect with other students 24/7, any time, night or day.Join Here!

Educators

Section 1 - Problem 1

If $g(x)=\frac{1}{32} x^{4}-5 x^{2},$ find $g^{\prime}(4)$
(A) $\quad-72$
(B) $\quad-32$
(C) $\quad 24$
(D) $\quad 32$

Amrita B.

Section 1 - Problem 2

$\lim _{x \rightarrow 0} \frac{8 x^{2}}{\cos x-1}=$
(A) $\quad-16$
(B) $\quad-1$
(C) $\quad 8$
(D) $\quad 6$

Amrita B.

Section 1 - Problem 3

$\lim _{x \rightarrow 5} \frac{x^{2}-25}{x-5}$
(A) 0
(B) 10
(C) 5
(D) The limit does not exist.

Amrita B.

Section 1 - Problem 4

If $f(x)=\frac{x^{5}-x+2}{x^{3}+7},$ find $f^{\prime}(x)$
(A) $\frac{\left(5 x^{4}-1\right)}{\left(3 x^{2}\right)}$
(B) $\frac{\left(x^{3}+7\right)\left(5 x^{4}-1\right)-\left(x^{5}-x+2\right)\left(3 x^{2}\right)}{\left(x^{3}+7\right)}$
(C) $\frac{\left(x^{5}-x+2\right)\left(3 x^{2}\right)-\left(x^{3}+7\right)\left(5 x^{4}-1\right)}{\left(x^{3}+7\right)^{2}}$
(D) $\frac{\left(x^{3}+7\right)\left(5 x^{4}-1\right)-\left(x^{5}-x+2\right)\left(3 x^{2}\right)}{\left(x^{3}+7\right)^{2}}$

Amrita B.

Section 1 - Problem 5

Evaluate $\lim _{h \rightarrow 0} \frac{5\left(\frac{1}{2}+h\right)^{4}-5\left(\frac{1}{2}\right)^{4}}{h}$
(A) $\frac{5}{2}$
(B) $\frac{5}{16}$
(C) 160
(D) The limit does not exist.

Amrita B.

Section 1 - Problem 6

$\int x \sqrt{3 x} d x=$
(A) $\frac{2 \sqrt{3}}{5} x^{\frac{3}{2}}+C$
(B) $\frac{5 \sqrt{3}}{2} x^{\frac{5}{2}}+C$
(C) $\frac{\sqrt{3}}{2} x^{\frac{1}{2}}+C$
((D) $\frac{5 \sqrt{3}}{2} x^{\frac{3}{2}}+C$

Amrita B.

Section 1 - Problem 7

Find $k$ so that $f(x)=\left\{\begin{array}{l}{\frac{x^{2}-16}{x-4} ; x \neq 4} \\ {k \quad ; x=4}\end{array} \text { is continuous for all } x\right.$
(A) 0
(B) 16
(C) 8
(D) There is no real value of $k$ that makes $f(x)$ continuous for all $x$ .

Amrita B.

Section 1 - Problem 8

Which of the following integrals correctly gives the area of the region consisting of all points above the $x$ -axis and below the curve $y=8+2 x-x^{2} ?$
(A) $\int_{-2}^{4}\left(x^{2}-2 x-8\right) d x$
(B) $\int_{-1}^{2}\left(8+2 x-x^{2}\right) d x$
(C) $\int_{-2}^{4}\left(8+2 x-x^{2}\right) d x$
(D) $\int_{-1}^{2}\left(x^{2}-2 x-8\right) d x$

Amrita B.

Section 1 - Problem 9

If $f(x)=x^{2} \cos 2 x,$ find $f^{\prime}(x)$
(A) $-2 x \cos 2 x+2 x^{2} \sin 2 x$
(B) $-4 x \sin 2 x$
(C) $2 x \cos 2 x-2 x^{2} \sin 2 x$
(D) $2 x-2 \sin 2 x$

Amrita B.

Section 1 - Problem 10

An equation of the line tangent to $y=4 x^{3}-7 x^{2}$ at $x=3$ is
(A) $y+45=66(x+3)$
(B) $y-45=66(x-3)$
(C) $y=66 x$
(D) $y+45=\frac{-1}{66}(x-3)$

Amrita B.

Section 1 - Problem 11

$\int_{0}^{\frac{1}{2}} \frac{2}{\sqrt{1-x^{2}}} d x=$
(A) $\frac{\pi}{3}$
(B) $\frac{\pi}{3}$
(C) $\frac{2 \pi}{3}$
(D) $\quad-\frac{2 \pi}{3}$

Amrita B.

Section 1 - Problem 12

Find a positive value $c,$ for $x,$ that satisfies the conclusion of the Mean Value Theorem for Derivatives for $f(x)=3 x^{2}-5 x+1$ on the interval $[2,5]$ .
(A) 1
(B) $\frac{11}{6}$
(C) $\frac{23}{6}$
(D) $\frac{7}{2}$

Amrita B.

Section 1 - Problem 13

Given $f(x)=2 x^{2}-7 x-10,$ find the absolute maximum of $f(x)$ on $[-1,3]$
(A) $-1$
(B) $\frac{7}{4}$
(C) $-\frac{129}{8}$
(D) 0

Amrita B.

Section 1 - Problem 14

Find $\frac{d y}{d x}$ if $x^{3} y+x y^{3}=-10$
(A) $\quad\left(3 x^{2}+3 x y^{2}\right)$
(B) $\quad \frac{\left(3 x^{2} y+y^{3}\right)}{\left(3 x y^{2}+x^{3}\right)}$
(C) $-\frac{\left(3 x^{2} y+y^{3}\right)}{\left(3 x y^{2}+x^{3}\right)}$
(D) $-\frac{\left(x^{2} y+y^{3}\right)}{\left(x y^{2}+x^{3}\right)}$

Amrita B.

Section 1 - Problem 15

$\lim _{x \rightarrow 0} \frac{x \cdot 2^{x}}{2^{x}-1}=$
(A) $\ln 2$
(B) 1
(C) 2
(D) $\frac{1}{\ln 2}$

Amrita B.

Section 1 - Problem 16

$\int 7 x e^{3 x^{2}} d x=$
(A) $\frac{6}{7} e^{5 x^{2}+C}$
(B) $\frac{7}{6} e^{3 x^{2}+C}$
(C) $7 e^{3} x^{2}+C$
(D) 42$e^{3 x^{2}+C}$

Amrita B.

Section 1 - Problem 17

Find the equation of the tangent line to $9 x^{2}+16 y^{2}=52$ through $(2,-1)$
(A) $-9 x+8 y-26=0$
(B) $9 x-8 y-26=0$
(C) $9 x-8 y-106=0$
(D) $8 x+9 y-17=0$

Amrita B.

Section 1 - Problem 18

A particle's position is given by $s=t^{3}-6 t^{2}+9 t .$ What is its acceleration at time $t=4 ?$
(A) 0
(B) $-9$
(C) $-12$
(D) 12

Amrita B.

Section 1 - Problem 19

If $f(x)=3^{\pi x},$ then $f^{\prime}(x)=$
(A) $\frac{3^{\pi x}}{\ln 3}$
(B) $\frac{3^{\pi x}}{\pi}$
(C) $\pi\left(3^{\pi x-1}\right)$
(D) $\pi \ln 3\left(3^{\pi x}\right)$

Amrita B.

Section 1 - Problem 20

The average value of $f(x)=\frac{1}{x}$ from $x=1$ to $x=e$ is
(A) $\quad \frac{1}{e+1}$
(B) $\frac{1}{1-e}$
(C) $e-1$
(D) $\frac{1}{e-1}$

Amrita B.

Section 1 - Problem 21

If $f(x)=\sin ^{2} x,$ find $f^{\prime \prime \prime}(x)$
(A) $\quad-\sin ^{2} x$
(B) $\cos 2 x$
(C) $\quad-4 \sin 2 x$
(D) $\quad-\sin 2 x$

Amrita B.

Section 1 - Problem 22

Find the slope of the normal line to $y=x+\cos x y$ at $(0,1)$
(A) 1
(B) $\quad-1$
(C) 0
(D) $\quad$ Undefined

Amrita B.

Section 1 - Problem 23

$\int e^{x}\left(e^{3 x}\right) d x=$
(A) $\frac{1}{3} e^{3 x}+C$
(B) $\frac{1}{4} e^{4 x}+C$
(C) $\frac{1}{4} e^{5 x}+C$
(D) $4 e^{4 x}+C$

Amrita B.

Section 1 - Problem 24

$\lim _{x \rightarrow 0} \frac{\tan ^{3}(2 x)}{x^{3}}=$
(A) $-8$
(B) 2
(C) 8
(D) The limit does not exist.

Amrita B.
A solid is generated when the region in the first quadrant bounded by the graph of $y=1+\sin ^{2} x,$ the line $x=\frac{\pi}{2},$ the $x$ -axis, and the $y$ -axis is revolved about the $x$ -axis. Its volume is found by evaluating
(A) $\pi \int_{0}^{1}\left(1+\sin ^{4} x\right) d x$
(B) $\pi \int_{0}^{1}\left(1+\sin ^{2} x\right)^{2} d x$
(C) $\pi \int_{0}^{\frac{\pi}{2}}\left(1+\sin ^{4} x\right) d x$
(D) $\pi \int_{0}^{\frac{\pi}{2}}\left(1+\sin ^{2} x\right)^{2} d x$


text:
# Maximum Clique¶

Technical details are available in the API documentation: sf.apps.clique

Here we’ll explore how to combine GBS samples with local search algorithms to find large cliques in graphs. Let’s get started!

A clique is a special type of subgraph where all possible connections between nodes are present; they are densest possible subgraphs of their size. The maximum clique problem, or max clique for short, asks the question: given a graph $$G$$, what is the largest clique in the graph? Max clique is NP-Hard, so finding the biggest clique becomes challenging for graphs with many nodes. This is why we need clever algorithms to identify large cliques!

To get started, we’ll analyze the 24-node TACE-AS graph used in [40]. This is the binding interaction graph representing the spatial compatibility of atom pairs in a protein-molecule complex. Cliques in this graph correspond to stable docking configurations, which are of interest in determining how the molecule interacts with the protein.

The first step is to import the Strawberry Fields apps module and external dependencies:

from strawberryfields.apps import data, plot, sample, clique
import numpy as np
import networkx as nx
import plotly

The adjacency matrix of the TACE-AS graph can be loaded from the data module and the graph can be visualized using the plot module:

TA = data.TaceAs()


text:
# What is a flying qubit?

DiVincenzo criteria for quantum communication mentions flying qubits:

a. The ability to interconvert stationary and flying qubits b. The ability to faithfully transmit flying qubits between specified locations

So, what exactly is a flying qubit, and how is it related to and different from a normal qubit? Please help understand more. I am undertaking Delft University's course in EdX on Quantum Internet and Quantum Computers.

## Preliminary - The DiVincenzo criteria for a 'normal' quantum computer

The DiVincenzo criteria, as originally proposed by DiVincenzo, are $$5$$ criteria that he originally proposed in his 2000 paper. In this paper, he proposed five criteria, which are widely considered to be the five (sufficient and necessary) criteria that any physical quantum computer should meet.

As you are doing the TUD quantum crypto course, you are familiar with the concept of a quantum internet. The five DiVincenzo criteria are not sufficient for a quantum computer including a quantum internet; they come up short in the communication part. For this, two more criteria (nr. $$6$$ & $$7$$) have been 'added'. They were not originally proposed by DiVincenzo.

## The two new criteria

These two new criteria have to do with communication between different quantum computers or nodes. To exchange (quantum) information between two nodes, one needs to have a carrier of this quantum information. This is exactly what a flying qubit should be: a qubit that can be freely send from one node to the other.

The first extra criterium prescribes that the information encoded in a qubit within the quantum computer (often referred to as the stationary qubit in this context) should be reliably transfered to a flying qubit. Additionally, an obtained flying qubit's information needs to be reliably tranferred back to a stationary qubit as well.

The second extra criterium prescribes that such a flying qubit should be reliably send from one node to another. This is a daunting task if you consider that the nodes might be (geographically) very far apart ($$> 50$$km). The coherence of the flying qubit needs to be preserved over this scale, possibly (likely) with the use of error correction.

## Properties of a flying qubit when compared to a stationary qubit

A flying qubit should, just as a stationary qubit, be able to reliably store quantum information. However, there are some important distinctions. First and foremost, flying qubits have a more restricted use case than stationary ones - they are only used to propagate the information between macroscopic distances, whereas stationary qubits are used to not only store information, but also to perform calculations with.

So to compare:

Stationary qubits need to:

• Be able to store quantum information reliably on a timescale of $$\sim ms$$.

• Perform calculations: various gates/operations need to be reliably performed on them. This includes an operation that moves/converts the information to a flying qubit.

• Be able to be measured/read out reliably.

• Be able to be highly entangled.

Flying qubits, however, need to:

• Be send over macroscopic distances while keeping their encoded (quantum) information intact.
• Be operational on a macroscopic temperature scale (i.e. about room temperature).
• Perform only one single operation reliably: converting into stationary qubits.

• Be able to be entangled.

Therefore, there are some important distinctions between the two. To summarize in what I believe is their defining distinctions:

• Stationary qubits need to be reliably calculated with.
• Flying qubits need to be reliably transmitted over macroscopic distances.

## Physical implementation of a flying qubit

There exist myriad different implementations of stationary qubits that all have their advantages and disadvantages; it is still an open question what the final 'go to' stationary qubit design (if any) will be. For flying qubits, there is one clear design which is the most promosing: the photon. The photon travels very fast, and has a straightforward two-level system (namely, its polarization). Also, this polarization can be conserved at higher temperatures.

Note that it is highly unlikely that stationary and flying qubits will be based on the same physical principle or design. That is to say, stationary qubits will most likely be based on an entire different physical phenomenon than stationary qubits (e.g. Ion traps, superconducting qubits/transmons, quantum dots, other confined electron systems etc. for stationary qubits.) There are, however, design for a quantum computer (with stationary qubits) based on the use of photons; only time will tell what actual implementation of stationary and flying qubits will prevail.

## Current implementations of flying qubits

As an interesting sidenote, in the context of quantum key distribution, flying qubits are used in the key distillation. However, for this protocol to work, only a subset of all possible qubit states need to be transferred (often this are the eigenstates of the $$Z$$ and $$X$$ operators). This reduces the complexity of the flying qubits. Note that for a general quantum internet this reduction needs to be omitted.

• Thank you for the answer, JSdJ. But, the question remains - how is it related to and different from a normal qubit ? I mean, we know that two qubits can be entangled to have identical information. If we can move one of them far apart, then we can say the information is transferred across two locations. So, is this the flying qubit (entangled and moved away)? Or, the flying qubit is entirely another entity altogether? – Amitabh Srivastava Nov 25 '19 at 3:22
• You're welcome and thanks for the feedback. I have added some discussion on the different design goals and properties of flying and stationary qubits. – JSdJ Nov 25 '19 at 7:50
• Also, as an unrelated remark, note that two qubits can not be entangled to possess identical information. By the no cloning theorem, information can not be copied from one qubit to the other. Therefore, when we say that we transfer information from a stationary qubit to a flying one, we really mean transfer; the information is destroyed on the stationary qubit. – JSdJ Nov 25 '19 at 7:59


text:
# Does moment of inertia only work for special cases?

I was looking into the moment of inertia expression for angular momentum. The angular momentum of a group of particles can be expressed as a linear transformation of the angular velocity vector. This produces a simple form for the whole body when the angular velocity is constant. Moreover, assuming we would like a simpler diagonal form for moment of inertia, the matrix must be diagonalisable so also must have real eigenvalues. The rotation vector must also be parallel to an eigenvector if we further want a constant moment of inertia

My question is, are these conditions necessary for moment of inertia to make sense? Moreover what shortcuts do we know a priori of calculating the linear transformation, to tell us that these conditions do in fact hold?

Constant angular velocity, for I to exist Diagonalisable Matrix with angular velocity parallel to one eigenvector

If so, what are some shortcuts we can take to observe when these conditions hold?

Sorry if my question was unclear


text:
184_notes:b_summary

It is an experimental fact that moving electric charges generate magnetic fields in all of space. When we observe a magnetic field, we know that is often due to some charge or collection of charges that are moving relative to our location in space (unless it’s due to a changing electric field as we will see soon).

The model of the magnetic field generate by a moving point charge is a bit more complicated than that for the electric field of a point charge because we observe that the magnetic field points perpendicular to the velocity vector and relation position vector,

$$\vec{B} = \dfrac{\mu_0}{4\pi} \dfrac{q \vec{v} \times \hat{r}}{r^2}$$

From this model, we can generate the magnetic field for a number of distributions of moving charges: line currents, rings of current, solenoids, and permanent magnets — for which the story is a bit more complicated than the others. The magnetic field, much like the electric field, superposes, so we can just add up the contributions to little chunks of moving charge (chunks of current) to find the field:

$$\vec{B} = \dfrac{\mu_0}{4 \pi} \int \dfrac{I d\vec{l} \times \hat{r}}{r^2}$$

This is called the Biot-Savart Law, but is really just an expression for superposition of the magnetic field. Later we will find that the pattern of the magnetic field in some cases suggests a short cut to finding the magnetic field that doesn’t involve superposition integrals.

Magnetic fields can exert forces on moving charges, but these forces are always perpendicular to the motion of said charges. The model for a single point charge in the presence of a magnetic field is:

$$\vec{F} = q \vec{v} \times \vec{B}$$

Which shows that the force is both perpendicular to the motion of the charge ($\vec{v}$) and the local magnetic field in which the charge is moving ($\vec{B}$). By superposing the forces on little chunks of moving charge in a wire, we can determine how a magnetic field will generate a force on a wire. We derived this model:

$$\vec{dF} = I d\vec{l} \times \vec{B} \longrightarrow \vec{F} = \int I d\vec{l} \times \vec{B}$$

Typically, the most common experience people have with magnetic force comes from permanent magnets, where the story is more complicated. We haven’t dived into the mathematical model for how forces in that situation work because while superposition continues to work, it means computing every magnetic field generated by every domain in one magnet and determining the force exerted on each domain of the other magnet and adding that all up!

The definition of magnetic force shows us that magnetic forces cannot change the kinetic energy of particles - the force is always perpendicular to the motion, so magnetic fields can not do work! Magnetic forces are used to change the trajectory of moving charges without adding energy to them. This is very useful in applications like mass spectroscopy.

However, this leads to a little bit of a difference between electric and magnetic fields, which is that there’s no such thing as a scalar magnetic potential (unlike electric potential). This doesn’t mean there’s no such thing as magnetic energy - there most definitely is, but it is a more complex and abstract idea than we had for electric fields. In fact, because there are no magnetic monopoles, we can define a vector potential for magnetic field, which carries with it some information related to energy, but that is beyond the scope of this course.

• 184_notes/b_summary.txt


text:
×

# Are ratings back?

This morning when I opened one of those "Someone liked your problem" emails and I viewed the problem, I saw something that said "Your rating: 1754 near the title of the problem (see attached image). It was a combinatorics problem and my combinatorics level was hanging on the border of Level 3/4 so I think it was pretty accurate. Are ratings back?

Edit: Confirmed. Ratings are back. To view your rating, go to any of your problems, view solution and your rating will appear below the problem's level.

Note by ZhiJie Goh
2 years, 3 months ago

## Comments

Sort by:

Top Newest

@Suyeon Khim Grrrreattt!!!!! Now I'd have to pay even to see my ratings. One by one, you will take away all the features from the non-Brilliant squared members and then you can enjoy snatching away the money from the few brilliant squared members when no one else will be here. Why do you introduce new features when you wanna take away the old ones away with them???????????????? · 2 years, 3 months ago

Log in to reply

I am not able to see my rating! · 2 years, 3 months ago

Log in to reply

Alright, just follow these 3 simple steps:

1. Go to a problem that you have already solved, or one of your own problems
2. Open up the solutions page
3. Your rating should be beside the level rating of the problem.

I run full view on my phone, not so sure if it works for mobile view. To enable full view, click on the gear thinggy on the top right corner and you should see the option "enable full view". · 2 years, 3 months ago

Log in to reply

Note: You must open up the solutions page if you want to see your rating · 2 years, 3 months ago

Log in to reply

hey it is gone! · 2 years, 3 months ago

Log in to reply

yesterday it was there today they are gone · 2 years, 3 months ago

Log in to reply

YUP.... · 2 years, 3 months ago

Log in to reply

OH GOD WHY · 2 years, 3 months ago

Log in to reply

now it is for brilliant square only what the he**!! · 2 years, 3 months ago

Log in to reply

I am on Brilliant squared, why am I still not able to see it? · 2 years, 3 months ago

Log in to reply

I'm not a Brilliant squared user but I think you have to click on the "Me" thing between "Post" and "Home" to view your ratings. · 2 years, 3 months ago

Log in to reply

×

Problem Loading...

Note Loading...

Set Loading...


text:
# Financial Smart Contract on Ethereum: can an Ether Futures contract be priced in Ether?

## BACKGROUND

This is more in the wheel-house of economics than programming, but after a few different titles, I thought it best not to skirt around the root of my question OR create a oddly phrased USD based question; when I'm actually asking about Ether. Just briefly, Ethereum is a blockchain network and Ether is the main crypto-currency on it that is used to pay the miners / validators, yada, yada.

Other tokens exist and it's possible to program an arbitrary contract like a financial derivative, but it doesn't have (and cannot have) a tokenized version of a US dollar without someone being able to cheat you if you ask for delivery or lie to you if you just ask for a price-feed. Basically, just like the real world, there's counter-party risk when you have to ask a human to help you or give you information. So the hard part here is getting an accurate picture of the current purchasing power of 1 Ether without simply asking a human to provide you with the current USD:ETH price feed.

## QUESTION

I'm a programmer, not an economist, but crypto-currencies are just ridiculously volatile. I would like to create asset market on Ethereum to help stabilize the value of Ether over the long term. I was thinking that perhaps I could create a contract in the form of "Pay X Ether now to have the option to buy Y Ether in 90 days". Except when I start to walk myself through an example, it doesn't make sense. I think I've structured it wrong and it seems like one side is guaranteed to lose and the other guaranteed to win regardless of whether the objective purchasing power of Ether goes up or down.

Phrased differently, using USD as a more familiar asset, I want to glean information about the current value (purchasing power) of \$1 USD today by creating a derivative of \$1 USD deliverable at some point in the future... without access to anyone's opinion of what the price is other than the current and historical order-book / trades between people of the real asset and the derivative.

The other caveat here is to avoid delivery 'now' for a 'promise' in the future, as that is wide open to theft and 99.99% of participants on Ethereum are anonymous, so no person can be trusted (only the code is trusted to execute as-written).

If I'm way off base with how I've thought the Asset:Derivative pair should work, please provide further guidance or alternatives. Especially real-world examples I can research.

## FOLLOWUP

Later, the intent is that a Market Maker contract will trade both sides of the asset (Ether Vs Ether's long term sentiment) to guarantee high-liquidity and easy price-discovery. The MM assumes only that the further the price is away from the long term mean, the more it should offer to trade at the current spot price, to buy back later when sentiment change back to the other side again. This, I believe will reduce volatility (as measured in purchasing power) given enough liquidity (some double digit % of total market cap locked in it I think would be quite influential).

The MM would:

• Skim profits from traders during high volatility.
• Neither win nor lose during stable periods as volume it offered would be negligible compared to the total assets it held.
• Be susceptible to losses as long term trend could cause the MM to be over committed to one side of the market than the other, expecting a return to mean that never comes.
• Over-sell Ether in a long term bull market and lose out on gains.
• Over-buy Ether in a long term bear market and lose objective purchasing power.
• OK, I'm having some trouble understanding what it is you want to do, exactly. For example, you say "Pay X Ether now to have the option to buy Y Ether in 90 days." When you buy Ether in 90 days, what will you buy it with? Dollars? Gold? Don't say Ethers because that really doesn't make any sense. You could pay X Ethers now for a promise that I will pay you Y Ethers in 90 days. We call that a loan. That makes perfect sense. But you say that isn't what you want. – Bill Dec 14 '16 at 15:14

Futures and Options are all about exchanging something for something else. These kind of derivatives all involve exchanging different 'kinds' of goods so it doesn't make sense to have both sides denominated in the same currency: When you have X Ethereum which you are willing to give up for Y Ethereum later, what you have is a loan. Loans aren't going to do much in terms of managing volatility, which is essentially, how much is Ethereum worth in terms of other stuff.

So the futures contracts needs to be exchanging Ethereum for that other stuff that happens to be volatile relative to Ethereum or vice versa. (could be dollars, could be Bitcoins). Of course since we can't predict the future there will be a winner and a loser. It's the nature of this sort of thing, however supposedly both parties are gaining a loss of volatility.

If you want to manage the downside, you can structure it as an option. An example of this would be, You pay \$1 now to have the right to exchange \$300 for 1 Ethereum in 90 days. (or vice versa). If the Ethereum ends up being worth more than \$301 then you end up winning on that deal, and if Ethereum ends up being worth less than \$301, you don't buy it. This benefits both parties: The person selling the option gets \$1 either way, and if Ethereum drops the purchaser of the option doesnt't lose more than \$1. This type of option is called a 'call option'. If structured the opposite way (you pay \$1 for the right to exchange 1 Ethereum for \$300 in 90 days) then the opposite happens: you 'win' if Ethereum drops below \$299, and you don't exercise the option if Ethereum rises in value, in which case you're simply out \$1. This is called a 'put option'.

No matter what, there will be a winner and a loser come the time to exercise the option. This is inevitable. However, the big idea is that the buyer of the option has a certain expectation on the market trend but wants to protect themselves against the opposite trend (in the case of call, fixed loss and unlimited upside, in the case of a put, guaranteed gain if there is downward movement vs. fixed loss if there is upward movement). The opposite side, the side selling the option, makes money off of the fee to purchase the option and is hoping that the volatility works out to less than the cost of the fee.

You are right about fixed futures (where the price and quantity are fixed and there is no option to back out): they will definitely have a winner and a loser. However, both parties get a guaranteed price, and that may be more valuable than any potential gains or losses. For example, say I am a multinational corporation where most of my profits come in USD but have just built a factory in Kenya and have taken out a loan to do so from a local bank. To pay off the loan, I need to guarantee I can get a fixed amount of Kenyan shilling every month, and it may be worth it to set price in USD so I don't have to worry about exchange fluctuations causing the loan to cost more USD than I expect one month, leaving me short; in that case I won't care too much if I lose out on the potential for the USD/Kenyan Shilling rate to move in my favour. Maybe the same thing could apply for someone who has contracts denominated in Ethereum, who knows.

On the other hand, any kind of investment based on expected future trends is just a smarter form of gambling, when you find someone to take the other side of the bet of course someone will win and someone will lose.

Enforceability of such contracts is a separate measure, it would be the same problem for any futures market and ideally that is what contracts, reputation and the rule of law is for.


text:
# Print all the ways to aquire specific number using only specific numbers

Let's say we have some arbitrary number:

For example 25. We also have some "tokens" (poker chips, money, something similar) with different values.

Values of tokens are 2; 3; 4; 5.

"Tokens" are limitless

You need to achieve number 25 using exactly n tokens (for example, 8) and to output all possible ways of doing so.

Fragment of example expected output (25 with 8 tokens):

3 '5' tokens, 5 '2' tokens
2 '5' tokens, 1 '4' token, 1 '3' token, 4 '2' tokens
....
1 '4' token, 7 '3' tokens

You may output in any reasonable, non-ambiguous format. For instance, 3 '5' tokens, 5 '2' tokens can be represented as a single list [5,0,0,3] or as a list of tuples [[3,5],[5,2]]. And if there's no solution, you can provide empty output (or state no solution found or something among the lines)

Standard code golf rules apply, so winner is decided by shortest byte count (though you have to also provide "commented" version of your code, especially for languages such as Brainfuck, Jelly, Piet and so on)

Edit: I intended this challenge as challenge with fixed tokens, but I like universal answers more then "niche" ones even if it's not specified in challenge itself initially. As long as making tokens "third input parameter" still provides correct answer for tokens provided it's accepted for this challenge. If you are willing to rewrite your code - go on, save those precious bytes/chars.

• @Arnauld, Oh, sorry. I'm very new to this community. How should I add standard LoC winning criteria and probably rewrite this challenge so that input and ouput is still readable and not to limit participants to much? – Sheyko Dmitriy Nov 8 at 14:16
• By the way: welcome to Code Golf! I hope you'll enjoy your stay here. – Arnauld Nov 8 at 14:33
• Are 2,3,4,5 always the tokens, or is that part of the input too and that's just the example? – Joseph Sible Nov 10 at 6:13
• @JosephSible I intended this challenge as challenge with fixed tokens, but I like universal answers more then "niche" ones even if it's not specified in challenge itself. If taking tokens to "third input parameter" makes your solution shorter but still provides correct answer for tokens [2,3,4,5] - I would accept it – Sheyko Dmitriy Nov 11 at 12:29
• @stephanmg let's limit it by MAX_INT, I don't think going for some BigInteger values will make this challenge any more intersting – Sheyko Dmitriy Nov 11 at 12:34

# Jelly, 10 bytes

ŒṗfƑƇL=¥Ƈ⁵

Try it online!

A full program that takes the total, token values and number of arguments as its arguments. Returns a list of lists of token values.

## Explanation

Œṗ          | Integer partition (of first argument)
Ƈ       | Keep only those which:
Ƒ        | - are invariant when:
f         |   - filtered to only include the (implicit) second argument.
¥Ƈ   | Keep only those for which:
L      | - the length
=  ⁵  |   - is equal to the third argument

• Wow. I'll probably never understand Jelly but it always seem to provide shortest solution. Congrats. And bonus points for providing a way to input tokens. – Sheyko Dmitriy Nov 11 at 7:54
• @SheykoDmitriy The Jelly answer is the only one that takes the [2,3,4,5] as third input instead of hard-coding it, though. Which of the two is correct? Could you answer @JosephSible's comment on your challenge? – Kevin Cruijssen Nov 11 at 8:22
• @KevinCruijssen I’d interpreted it as being part of the input, rightly or wrongly. – Nick Kennedy Nov 11 at 8:23
• @NickKennedy I can understand. I also read it like that as first. But I noticed all other answers are hard-coding it instead, and I also noticed Joseph's question regarding it. If it's a third input, the 05AB1E answer for example could be 7 bytes, and I'm sure some of the other answers would be able to save some bytes as well. If it's indeed intended to be a third input as we both thought when reading the challenge. – Kevin Cruijssen Nov 11 at 8:25

# J, 35 32 bytes

~.@((=1&#.)#])2+#&4/:~@#:[:i.4^]

Try it online!

• Count in base 4 from 0 up to 4 ^ num_tokens to generate all the raw possibilities: #&4/:~@#:[:i.4^]
• Add 2 to all numbers so the tokens will have 2 3 4 5 labels instead of 0 1 2 3 labels: 2+
• Sort each possibility in preparation for removing dups: /:~@
• Filter the raw possibilities to include only those with the correct sum: ((=1&#.)#])
• Take the uniqs: ~.@

# Perl 6, 64 bytes

{grep(*.sum==$_,|($/=2..5),|(+<<[\X] $/xx$_)[*;*])>>.Bag.unique}

Try it online!

Fails for inputs above 7 due to Too many arguments in flattening array.This is because we are generating a list of every possible combination with repetition of numbers up to length n (where n is the same as the input), and not just that, but every possible ordering as well. Ah well, the price of being golfy...

This takes a number and returns a Bag, which is an unordered list of numbers and the amount in the bag.

# JavaScript (V8),  94  82 bytes

Takes input as (sum)(n). Prints the solutions, as lists of token values.

s=>(g=(n,t=0,u=[])=>n?[2,3,4,5].map(v=>v>u[0]||g(n-1,t+v,[v,...u])):t-s||print(u))

Try it online!

### Commented

s => (              // s = expected sum
g = (             // g is a recursive function taking:
n,              //   n   = expected number of tokens
t = 0,          //   t   = current sum, initialized to 0
u = []          //   u[] = list of tokens
) =>              //
n ?             // if n is not equal to 0:
[2, 3, 4, 5]  //   for each allowed token value v:
.map(v =>     //
v > u[0] || //     abort if u[] is non-empty and v is greater than the last
//     token value (which is actually stored at the beginning)
g(          //     otherwise, do a recursive call:
n - 1,    //       decrement n
t + v,    //       add v to t
[v, ...u] //       prepend v to u[]
)           //     end of recursive call
)             //   end of map()
:               // else:
t - s ||      //   if t = s:
print(u)    //     this is a solution: print it
)                   //

• I like the way you format your code for explanations. Do you do it by hand or use a program you've written? – Jonah Nov 9 at 1:53
• @Jonah Every once in a while, the idea of writing a program crosses my mind. And then I say to myself: "oh well, let's do this one manually for now..." – Arnauld Nov 9 at 8:29
• Wow. Taking off my hat. Nice formatting and thorough comments. That's the way I like to see code! – Sheyko Dmitriy Nov 11 at 7:56

# 05AB1E, 11 bytes

ÅœIùʒ5L¦ÃyQ

Try it online!

Outputs list of token values.

Explanation

Åœ            | Take all integer partitions of the target number
Iù          | Only keep those of length n
ʒ         | Filter by:
5L¦      | Push [2,3,4,5]
ÃyQ   | Check if partition is equal to its intersection with [2,3,4,5]
| Filter it out if not

# Pyth, 21 20 bytes

{mSdfqhQsT.c*hQr2 6e

Try it online!

Saved a byte because the last Q is implicit

Returns a list of token combinations (e.g. [3, 3, 4] for 2 '3' tokens and 1 '4' token) which seems like a reasonable, non-ambiguous format, so I'll leave it unless the rules are changed. Takes input as value, n. Return an empty list if there are no valid combinations (I think)

Also hopelessly slow, so dont pick a value thats too high.

## How it works

{mSdfqhQsT.c*hQr2 6e (Q)
*hQ        - Multiply the first input by...
r2 6    - The range 2,6 (2..5)
.c       e(Q)- All combinations of the above that are the length of the
second input (Q is implicit)
fqhQsT             - Filter to elements where the sum is equal to the first input
mS                    - Sort all elements
{                      - Remove duplicates

New contributor
frank is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

# Wolfram Language (Mathematica), 36 bytes

Not really golfed. There is a built-in for this in Mathematica.

IntegerPartitions[#,{#2},{2,3,4,5}]&

Try it online!

# Charcoal, 30 bytes

ＮθＮηΦＥＸ⊕θ⁴⭆⮌↨ι⊕θ⭆λ⁺²μ∧⁼Ｌιθ⁼Σιη

Try it online! Link is to verbose version of code. Outputs a list of strings each of n tokens sorted in ascending order (if they had been sorted in descending order then the list itself would be in ascending order). Explanation:

ＮθＮη

Input n and the target.

ΦＥＸ⊕θ⁴

Loop over the range 0..(n+1)⁴.

⭆⮌↨ι⊕θ

Convert each value to base (n+1) as an array with least significant digit first.

⭆λ⁺²μ

Convert each array to a string of tokens 2..5 and concatenate the results.

∧⁼Ｌιθ⁼Σιη

Only output those strings with a length of n and the correct digital sum.

n%k=[l|l<-mapM(\_->[0..n])"xnor",sum l==k,sum(scanr(+)0l)==n-k]

Try it online!

A cute trick is used to check the list sum. We're looking for for elements l=[a,b,c,d] with a+b+c+d=k (right number of tokens) and 2*a+3*b+4*c+5*d==n (right total value). Subtracting the first equation from the second gives a+2*b+3*c+4*d==n-k. To get a+2*b+3*c+4*d, we do scanr(+)0 l to get the reversed cumulative sum [a+b+c+d,b+c+d,c+d,d,0] and take the sum of its elements.

The solution brute-forces using mapM to generate all possible quadruples of token counts.

71 bytes

n%k=filter(all(>=0))[[a,4*k-n-2*a+d,n-3*k+a-2*d,d]|a<-[0..n],d<-[0..n]]

Try it online!

A longer direct solution. We try all a and d, and for each possibility we solve for b and c and check if they are non-negative positive.

68 bytes

(%)2
6%t=[[]|t==(0,0)]
x%(v,c)=do y<-[0..c];(y:)<$>(x+1)%(v-x*y,c-y)  Try it online! Golfing Joseph Sible's solution. Takes input uncurried like (25,8). # Haskell, 75 67 bytes f(x:l)v c=do y<-[0..c];(y:)<$>f l(v-x*y)(c-y)
f[]0 0=[[]]
f[]_ _=[]

Try it online!

-8 bytes by taking the tokens as input

The last two lines could be replaced with either f[]v c=[[]|v==0,c==0] or f n v c=[n|v==0,c==0], both keeping the same byte count. Perhaps there's a way to golf one of those variants further that I'm not seeing though.

# Julia 1.0, 67 bytes

f(s,n,q=0:n)=[[a b c d] for a=q,b=q,c=q,d=q if[a b c d]*(2:5)==[s]]

Generates values representing how many tokens there are, then uses matrix multiplication to calculate the total. It seems like there should be a way to avoid typing [a b c d] twice, but I'm not aware of it.

Try it online!

# Japt, 22 bytes

V*4 o î6o2)àV â f_x ¥U

Try it

Returns arrays of tokens.
Not really efficent though.

(V * 4).o() // create an array of 4 times every token
.î(6 .o(2)) // repeat 2 to 5 inside it
.à(V).â() // all unique combinations
.f(function(Z) { return Z.x() == U }) // remove the wrong combinatons

Flag -Q to pretty print the result

# Python 3, 97 bytes

lambda s,n:{(*sorted(i),)for i in product([2,3,4,5],repeat=n)if sum(i)==s}
from itertools import*

Try it online!

# Python 3, 106 bytes

lambda s,n,r=range:{(i,j,k,n-i-j-k)for i in r(n+1)for j in r(n-i+1)for k in r(n-i-j+1)if 5*n==s+3*i+2*j+k}

Try it online!

This function iterates over 3 variables i, j and k. The fourth variable follows from the difference between the number of tokens n and ijk. A combination is valid if 2*i+3*j+4*k+5*(n-i-j-k)==s. This condition rearranges to 5*n==s+3*i+2*j+k.


text:
# Integrating over level sets of a function

+ 4 like - 0 dislike
10 views

I have a background in math, but I think the following construction appears often in physics.

Is there a term for a functional which maps one smooth function $f: R^n \rightarrow R$ to another $L(f):R \rightarrow R$ which represents the integral along each level set? That is, $L(f)(a) = \int_{f^{-1}(a)} d\mu$ where the measure $d\mu$ might be the induced measure from the metric on $R^n$, or it might also depend on the original $f$ in some intelligent way.

For instance, if the initial function is $f:R^2 \rightarrow R$ is defined $f(x)=x^2+y^2$ then $L(f)(a) = 2 \pi \sqrt{a}$.

If the original function is $f:R \rightarrow R$ is defined $f(x)=x^2$, then we'd have $L(f)(a)=0$ for $a<0$, $1$ for $a=0$, and $2$ for $a>0$. In both cases it might be more natural to integrate with a term derived from the value of $f'$ normal to the level set.

I suppose one could generalize to any smooth map $f:M \rightarrow M'$ from a Riemannian manifold to a another smooth manifold and get a new function that represents a computed volume of the preimage for each point: $L(f):M' \rightarrow R$.

My question: Is there a good way to compute $L(f)$ for some class of function $f$?

Any thoughts would be appreciated. It is reminiscent of (but I hope simpler than) stationary phase approximations and path integral calculations.

http://en.wikipedia.org/wiki/Stationary_phase_approximation

This post imported from StackExchange Mathematics at 2014-06-02 20:26 (UCT), posted by SE-user Obidiah

+ 2 like - 0 dislike

If I remember correctly, what you are describing is close to the concept of a distribution function (it is the name that I am slightly unsure about).

Given a measure space $(X,\mathcal{E},\mu)$, and a measurable function $f:X\to \mathbb{R}$, a concept often used in classical and harmonic analysis is the notion of the distribution function $\lambda_f:\mathbb{R}_+\to\mathbb{R}$ defined as

$$\lambda_f(a) = \mu\left( \{|f| < a\} \right)$$

that is, $\lambda_f$ is returns the measure of the set on which $|f|$ is bounded by $a$. One can reformulate the $L^p$ norms of $f$ in terms of the distribution function

$$\|f\|_{L^p(X,\mu)} = p \int_0^\infty t^{p-1}\lambda_f(t) dt$$

a device that is very useful for analytical estimates. Now, formally speaking the functional $L(f)$ you wrote down is very similar to the derivative $\lambda_f'$.

Another possibility that you may want to look into is the notion of pull-back distributions. If $f:M\to\mathbb{R}$ is a smooth map with non-vanishing gradient, then given any distribution (generalized function) $k$ on $\mathbb{R}$ you can define the pull-back distribution $f_*k$ on $M$. The definition of $f_*k$ depends closely on the notion of $L(f)$ you wrote down (see e.g. the introduction to distributions by Friedlander and Joshi), and is a generalization of the co-area formula.

I am not exactly sure how to answer your second question of "is there a good way to compute". If you are asking whether given an analytic expression for the function $f$ whether you can have a "closed form" expression for $L(f)$, the answer is surely no, since the expression also depends on the chosen Riemannian metric/volume form/measure on $M$. If you are asking whether there are any convenient expressions to capture $L(f)$, I think you need to say a bit more about why you care about $L(f)$. You can certainly just write $L(f) = f_*\delta_a$ as the pull-back of the Dirac delta distribution on $\mathbb{R}$; whether that expression is a useful one for your purpose, I don't know.

This post imported from StackExchange Mathematics at 2014-06-02 20:26 (UCT), posted by SE-user Willie Wong
answered Dec 30, 2010 by (570 points)
other way: $\lambda_{f}(a)=\mu(x:|f|>a)$ (Folland)

This post imported from StackExchange Mathematics at 2014-06-02 20:26 (UCT), posted by SE-user TKM
+ 1 like - 0 dislike

Using the Fourier transform representation of the Dirac measure on the level set, the volume of the level set (which is the required integral according to the examples given in the question) is given by (using the same notation as in the question):

$L(f)(a) = \frac{1}{2\pi} \int_{-\infty}^\infty \mathrm{d}k \,exp(-ika)\, \int\,|\nabla f|\,exp(ikf)\,\mathrm{d}\mu$

On a Riemannian manifold, the gradient is given by:

$\nabla f = \sum_{ij}g^{ij}\frac{\partial f}{\partial x^i}\frac{\partial}{\partial x^j}$

The two examples given in the question can be worked out according to this formula (the second example very easily, the first one involves integrals of trigonometric functions of a squared angle, but it can also be solved analytically).

This post imported from StackExchange Mathematics at 2014-06-02 20:26 (UCT), posted by SE-user David Bar Moshe
answered Dec 28, 2010 by (3,845 points)

 Please use answers only to (at least partly) answer questions. To comment, discuss, or ask for clarification, leave a comment instead. To mask links under text, please type your text, highlight it, and click the "link" button. You can then enter your link URL. Please consult the FAQ for as to how to format your post. This is the answer box; if you want to write a comment instead, please use the 'add comment' button. Live preview (may slow down editor)   Preview Your name to display (optional): Email me at this address if my answer is selected or commented on: Privacy: Your email address will only be used for sending these notifications. Anti-spam verification: If you are a human please identify the position of the character covered by the symbol $\varnothing$ in the following word:p$\hbar$ysicsOverfl$\varnothing$wThen drag the red bullet below over the corresponding character of our banner. When you drop it there, the bullet changes to green (on slow internet connections after a few seconds). To avoid this verification in future, please log in or register.


text:
Forum archive 2000-2006

Zbigniew Fiedorowicz - Quiz mode for WeBWorK

by Arnold Pizer -
Number of replies: 0
 Quiz mode for WeBWorK topic started 3/11/2003; 4:00:57 PMlast post 9/27/2005; 7:58:00 AM
 Zbigniew Fiedorowicz - Quiz mode for WeBWorK  3/11/2003; 4:00:57 PM (reads: 1880, responses: 9) I've now implemented quiz mode for WeBWorK along the lines of my previous post, using Moodle as the front end. Quiz mode means a couple of things: first of all the assignment must be done within a short time frame of xx minutes (xx specified by the instructor). Secondly there is no feedback about correctness or incorrectness until the whole assignment is submitted. [However at the instructor's option, the whole quiz/assignment can be redone and resubmitted.] The main use of quiz mode, as I see it, is to furnish practice for students in test taking under time pressure. To see quiz mode in action, go to https://webwork.math.ohio-state.edu/moodle/ and click on WeBWorK Quiz. The interface scripts for quiz mode are still in rough shape, so I am not yet making them available. There still may very well be bugs in the code. Please let me know if you come accross a bug and send me the details on how it happens. Zig Fiedorowicz <| Post or View Comments |>

 Gavin LaRose - Re: Quiz mode for WeBWorK  3/12/2003; 10:56:35 AM (reads: 2152, responses: 0) Hi Zig, Very impressive! I tried it a couple of times and have the following comments. The first time I tried it (with Netscape 4.7x on Solaris 8), I was unable to display the problem page, which made it difficult to take the quiz. I've most often seen this problem with Netscape when a closing tag is omitted somewhere, but it might just be a bug in the browser too. It displayed fine in Mozilla. The navigation, which makes pretty good sense for homework, confused me at first in the quiz context--my tendency was to click "Next problem" to get the next problem (after working on the first), which of course would result in me losing my work. This may be a result of my experience with other testing software, rather than an actual user interface issue. This could probably be resolved by renaming some of the buttons. While working on the problems, it would be nice to have feedback on the front page as to which had been completed. It would be nice to get some feedback other than the grade when the quiz is submitted for grading. In the homework you immediately see what you did wrong and any comments that might be set up for the problem when you grade it--it would be nice to have similar feedback when the quiz is submitted. When trying to look at "test gateway 1 score", I get the response "weird assignment error." :) Cheers, Gavin <| Post or View Comments |>

 Zbigniew Fiedorowicz - Re: Quiz mode for WeBWorK  3/12/2003; 2:10:32 PM (reads: 2147, responses: 0) Hi Gavin,Thanks for your comments.>The first time I tried it (with Netscape 4.7x on Solaris 8), I was unable>to display the problem page, which made it difficult to take the quiz. I've most>often seen this problem with Netscape when a closing table tag is omitted>somewhere, but it might just be a bug in the browser too. It displayed fine in>Mozilla.I don't have Netscape 4.x available on my office machine, but I'll look into it.>The navigation, which makes pretty good sense for homework, confused me at>first in the quiz context--my tendency was to click "Next problem" to get the>next problem (after working on the first), which of course would result in me>losing my work. This may be a result of my experience with other testing>software, rather than an actual user interface issue. This could probably be>resolved by renaming some of the buttons.This is doable but takes some work. My postprocessing wrapper script will needto rewrite the page emitted by processProcessProblem8.pl so as to have a singleinput form instead of 3 or 4 as it does now.>While working on the problems, it would be nice to have feedback on the>front page as to which had been completed.I'm not sure what you want here. I thought that the quiz format is not supposedto provide feedback on individual problems until the entire quiz is submittedfor grading. Or do you just want feedback on which problems have been attempted?>It would be nice to get some feedback other than the grade when the quiz>is submitted for grading. In the homework you immediately see what you did wrong>and any comments that might be set up for the problem when you grade it--it>would be nice to have similar feedback when the quiz is submitted.But it does provide such feedback! Namely when you click on the "Submit Quiz forGrading" button, you get the problem page back again. If you click on Get Problem,you will get the problem page with the answers you submitted showing. Instead ofa Submit Answers button, there is a Show Correct Answers button. Now I grant youthis is a little round-about, but the limitation of the method I'm using is thatI am constrained to use the basic web page format provided in WeBWorK. Besides thatI think there may be some pedagogical benefits to this format,instead of immediatelyshowing the correct answer. I think it is helpful to allow the student a chanceto spot their own mistakes first.>When trying to look at "test gateway 1 score", I get the response "weird>assignment error." :)I think what happened is that the database table for that assignment gotcorrupted while I was still debugging earlier versions of the script, butI'm still looking into it.Zig <| Post or View Comments |>

 Zbigniew Fiedorowicz - Re: Quiz mode for WeBWorK  3/13/2003; 12:54:08 PM (reads: 2141, responses: 0) Hi Gavin,>The first time I tried it (with Netscape 4.7x on Solaris 8), I was unable >to display the problem page, which made it difficult to take the quiz. I've most >often seen this problem with Netscape when a closing table tag is omitted >somewhere, but it might just be a bug in the browser too. It displayed fine in >Mozilla.This should now be fixed.>The navigation, which makes pretty good sense for homework, confused me at >first in the quiz context--my tendency was to click "Next problem" to get the >next problem (after working on the first), which of course would result in me >losing my work. This may be a result of my experience with other testing >software, rather than an actual user interface issue. This could probably be >resolved by renaming some of the buttons.Also this.>When trying to look at "test gateway 1 score", I get the response "weird >assignment error :)And this too.I'd like you and anybody else who is interested have a go at this againand let me know whether anything else needs fixing.Thanks,Zig <| Post or View Comments |>

 Zbigniew Fiedorowicz - Re: Quiz mode for WeBWorK  3/13/2003; 7:15:07 PM (reads: 2135, responses: 0) Hi Gavin,Thanks again for your comments.>The "Next Problem" adjustment is very nice. Having that retain >answers from problem to problem, it's tempting to say that the >next thing would be simply to get rid of the "submit problem" >button entirely. Then the student would have a nice sense that he/>she was working through each problem on the test, possibly >stopping back at the top page to check on the list of problems, >without wondering what it means to "submit" a problem in the >middle of the test. Instead, he/she does all of the work and then >clicks the intuitively labelled "submit the quiz for grading" >button.I agree that this is a good idea. It's trivial to implement.>With regards to the "feedback on the front page" I mentioned >before, I was thinking, as you intuited, of something indicating >which problems had been attempted.Now that you've clarified this point, I'll put this into the nextversion of the scripts.>A couple of other thoughts. From the perspective of the gateway >testing that we do here it's nice for the students to be able to >get a single page that summarizes what they did right and which >problems they missed. I'm not sure to what extent that's logical >in the system that is running here.Perhaps this could go into the screenHeader.pg for the assignment?>Also, we restrict the number of times a student can take the >quiz in a day. I didn't notice if this was possible with this >system, but it's a highly desirable feature. (We don't want to, >and realistically probably can't, require proctors to enforce >that type of limit.)This should be easy to implement via inspection of the WeBWorKlogin.log for the course.Zig <| Post or View Comments |>


text:
Solve this
Question:

It $\tan ^{-1} \frac{x+1}{x-1}+\tan ^{-1} \frac{x-1}{x}=\tan ^{-1}(-7)$, then the value of $x$ is

(a) 0

(b) $-2$

(c) 1

(d) 2

Solution:

(d) 2

We know that $\tan ^{-1} x+\tan ^{-1} y=\tan ^{-1}\left(\frac{x+y}{1-x y}\right)$.

$\therefore \tan ^{-1}\left(\frac{x+1}{x-1}\right)+\tan ^{-1}\left(\frac{x-1}{x}\right)=\tan ^{-1}(-7)$

$\Rightarrow \tan ^{-1}\left(\frac{\frac{x+1}{x-1}+\frac{x-1}{z}}{1-\frac{x+1}{x-1} \times \frac{x-1}{x}}\right)=\tan ^{-1}(-7)$

$\Rightarrow \tan ^{-1}\left(\frac{\frac{x^{2}+x+x^{2}-2 x+1}{x x-1}}{\frac{x^{2}-x-x^{2}+1}{x(x-1)}}\right)=\tan ^{-1}(-7)$

$\Rightarrow \tan ^{-1}\left(\frac{2 x^{2}-x+1}{-x+1}\right)=\tan ^{-1}(-7)$

So, we get

$\frac{2 x^{2}-x+1}{-x+1}=-7$

$\Rightarrow 2 x^{2}-x+1=7 x-7$

$\Rightarrow 2 x^{2}-8 x+8=0$

$\Rightarrow x^{2}-4 x+4=0$

$\Rightarrow(x-2)^{2}=0$

$\Rightarrow x=2$


text:
# Air gap in toroid

#### sarahgarden

1. Homework Statement
(I have done parts i) through v) correctly. It is the remaining two I'm stuck on.

A toroid of rectangular cross-section has a height of 10mm, an inner diameter of 68mm and an outer diameter of 82mm. It is made of iron and is wound with 118 closely-spaced turns. When a current of 2A flows, calculate;

i)the mmf around the toroid
ii)the magnetic field-strength within the toroid
iii)Using B-H curve determine the flux density and flux in the ring,
iv)the relative permeability at this point on the curve

A 1mm air gap is then cut in the toroid. The current is still 2A. Calculate;
v)the new flux density in the ring,
vi)the mmf around the ring, and across the air gap.
vii) It is then required to establish a flux density of 0.75T in the air gap. Calculate the current needed to do this.

Answers to parts vi) and vii)
vi) 53, 183 A-t
vii) 8.0 A

2. Homework Equations

$$m.m.f.=NI=BS(R_{m}iron+R_{m}air)$$

$$R_{m}=\frac{l}{\mu_{0}\mu_{r}S}$$

where

$$\mu_{r}=557$$,

I have $$B=0.21T$$ (although the answer gives it as 0.23)

$$R_{m}(iron)=4.787*10^6$$ and $$R_{m}(air)=11.365*10^6$$

$$S$$= cross-sectional area = $$7*10^{-5}$$

3. The Attempt at a Solution

I get the m.m.f. across the air gap correct if I use the value of B = 0.23T in answers. My answer was 0.21T and I found this was significant:

$$R_{m}(air)=\frac{l}{\mu_{0}S}$$

$$m.m.f.=BS(R_{m}(air))$$

$$=0.23*7*10^-5*11.365*10^6=183.5At$$

I did as before with the iron, subtracting the 1mm from \piD for l (in metres)

$$m.m.f.=BS(R_{m}(iron)$$ where

$$R_{m}(iron)=\frac{l}{\mu_{0}\mu_{r}S}$$

but I get 70, which is far from the answer of 53.

For the last part (vii) I don't know why it isn't simply

$$I=\frac{BS}{N}R_{m}(air)$$

with this I get 5A rather than 8

Last edited:
Related Introductory Physics Homework Help News on Phys.org

"Air gap in toroid"

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving