text:
# Output two numbers (Cops' thread)

The challenge here is very simple. Create two programs of the same size, in the same language, which output (using 1 standard output method) two different natural numbers, $$\x\$$ and $$\y\$$. Submit both programs, both numbers and the language used in an answer on this thread.

Robbers will then attempt to find a program in the same language which outputs a number in between $$\x\$$ and $$\y\$$, and is the same length as or shorter than your programs. If they do, they will post it to the robbers' thread, and it is "cracked".

For example If I post:

# Haskell, $$\9-7 = 2\$$, 12 bytes

main=print 7

main=print 9

Then robbers must find a program that prints 8 in 12 bytes or fewer.

Unlike many challenges in cop's do not need to have an answer in mind when posting. It is perfectly valid to post an answer which cannot be cracked at all. In fact that is incentivized. However the scoring means that the better you score the harder it will be to prevent a crack.

## Scoring

Your score will be the difference between $$\x\$$ and $$\y\$$. So in the example answer it was $$\2\$$. Higher score is better. If your answer is cracked it's score is automatically set to 0.

Since there is no hidden information that needs to be revealed, answers will not be marked as safe. You get your score as soon as you post the answer and it will remain your score until someone cracks it.

• If our language allows us to output an infinite number (R can output Inf, for instance), is a program that outputs this acceptable (for an infinite score if uncracked)? Jan 31 at 12:07
• @DominicvanEssen I would argue that 2e308 theoretically refers to Inf not an integer. So it's clear to me that this is a subjective measurement. Your answer should be correct given enough memory. Jan 31 at 12:20
• You say "program" in the challenge description - must answers be full programs, or are functions acceptable? Also, must both programs use the same output method, and must robbers' posts also? (I would suggest saying they must) Jan 31 at 16:55
• @DewiMorgan That's fine but you score very low, so I don't think it's even worth it. Jan 31 at 19:15
• Does the robber's number need to be natural? For cops it's specified explicitly, but not for robbers. Jan 31 at 19:16

# Zsh, 1 byte, score 124, provably uncrackable

Programs output via exit code.

/

Outputs 126 ("permission denied"). Attempt This Online!

[

Outputs 2 ("invalid argument"). Attempt This Online!

Here is a script which tests all 256 possible 1-byte programs, which you can use to verify that this is uncrackable (and unbeatable for 1-byters):

{ for c ({0..255}) ( zsh -c ${(#)c} &>/dev/null; echo$? ) } | sort -n

Attempt This Online!

The empty program exits with 0.

# Malbolge, 7 bytes. Score: 3 - 1 = 2. Cracked.

D'<;_L"

Outputs 3.

(&a%M"o

Outputs 1.

• That's some Seedprogrammer craziness.
– null
Jan 31 at 11:29
• @null OH! thanks for the hint. Jan 31 at 11:31
– null
Jan 31 at 11:32
• Cracked!. That was not very easy. Feb 2 at 0:16
• @DominicvanEssen very cool! Feb 2 at 7:47

# R, 5 bytes, score: 10^307

1e308

Try it online!

9e307

Try it online!

2e308 overflows R's numeric type, and outputs Inf, so I suppose that 1e308 is the highest number that we can output using 5 bytes.

# R, 4 bytes, score: 9 x 10^98, cracked, almost instantly

1e99

Try it online!

1e98

Try it online!

Note after crack: Well, that was pretty stupid of me.

• Cracked but the question suggests to better make uncrackable solutions
– l4m2
Jan 31 at 11:40
• @i4m2 - Oh, that was stupid of me. Jan 31 at 11:41
• Note that 3^ceiling(log(9e307,3)) (and variants) are bigger than 1e308, so those are dead ends. Jan 31 at 15:39
• @Giuseppe - Hm, so I was clearly wrong about 'the highest number that we can output using 5 bytes' then... Jan 31 at 15:45
• @Giuseppe - (and now I'm quite curious what would be the shortest expression that would output 1.797693e+308, assuming that this actually is the highest number that can be output in R...) Jan 31 at 15:49

# C, 24 bytes, score 33482810471

Output format is decimal.

main(){printf("%o",~9);}

Outputs 37777777766. Try it online!

main(){printf("%u",-1);}

Outputs 4294967295. Try it online!

Uncrackable?

• it's like here, often cracked by main(){printf("%o",.2);}, but not always.
– user111777
Apr 5 at 7:31

# Excel, 10 bytes, score (145!)-(144!) 0 Cracked!

I'm interested to see how this can be cracked.

=FACT(145)

Outputs 8.04792605747199E+251 (actually prints every digit when in "Number" format and a very wide column/merged columns, the most I could get it to print before they became ##### or #NUM!

=FACT(144)

Outputs 5.55029383273931E+249 (again, actually prints every digit [although it does turn most to 0's])

But... if you think it's okay if I can use un-printable numbers (likely not)

# Excel, 10 bytes, score (999999999!)-(999999998!)

=FACT(999999999)

Output is approximately 1e8448735636

=FACT(999999998)

Output is approximately (1e8448735636)/999999999

• Welcome to Code Golf! Nice answer. Feb 1 at 2:13
• Thanks! Can I post another answer for another language (C)? Feb 1 at 2:19
• Sure! Posting multiple answers is fine unless the challenge specifically says not to, even in the same language if they're different enough. Feb 1 at 2:28
• cracked! Feb 1 at 10:41
• (and I assume the dodgy un-printable one is a typo, otherwise surely =FACT(100000001) is a crack...?) Feb 1 at 11:06

# Charcoal, 2 bytes, score: 1000 - 99 = 901

Ｉφ

Outputs 1000. Try it online! Link is to verbose version of code.

99

Outputs 99. Try it online!

# Jelly, $$\1000 - 256 = 744\$$, 1 byte

This is provably uncrackable. Our programs are

ȷ

Try it online!

and

⁹

Try it online!

These are the following one byte programs in Jelly that output a number:

¤¥¬®µ½×ðȷ !$&*+-.0123456789<=>ACEHLNOPSX^_aceghinoquvw|~°¹²³⁴⁵⁹⁻⁼ẠḄḌẸḤỊṂṆẒȦḂĊḞḢṀṠṪạḅḍịḳḷṇṛ§ẉỵẓȧċḋėġṅȯẇẏ«»‘’  Try it online! The two largest outputs are $$\1000\$$ with ȷ, then $$\256\$$ with ⁹. Nothing else outputs something in between, and the empty program outputs 0. # Vyxal 2.8.1, online edition, Score: $$\no\$$, 102 bytes - cracked Our two programs are: kḭkḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(kḭ(↵  which is equivalent to: stack.append(4294967296) for i in range(4294967296): for j in range(4294967296): for l in range(4294967296): ... stack.append(10 ** stack.pop())  and k×k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(k×(↵  stack.append(2147483648) for i in range(2147483648): for j in range(2147483648): for l in range(2147483648): ... stack.append(10 ** stack.pop())  These both output really big numbers, which I need to calculate. Online edition here means that it should be able to work on the online version of the interpreter if given enough resources and time. • From the description this seems like it should be really easy to crack. Simply write a program which loops a set number of times each time applying ↵. Start at 8 and you should have plenty of room to add 1 at the end. But I don't know enough about lyxal to make this happen. Jan 31 at 12:30 • @WheatWizard by the time you've set up the loop, you've already wasted a potential ↵ that could have been used instead Jan 31 at 12:32 • I'm pretty sure you can set up a loop in fewer than 1000 bytes giving you plenty of time to apply ↵ way more than the program which just naively applies ↵ repeatedly. There is just so much room. Jan 31 at 12:34 • @WheatWizard "I don't know enough about lyxal to make this happen" lol Jan 31 at 12:37 • I doesn't know much about vyxal either bot doesn't something like eval("kḭ" + "kḭ("*98 + "↵")+1 is possible with fewer bytes in this language? Jan 31 at 12:47 ## Seed 4791 bytes, 9^9^9^9^9^9^9^9^9^9^9 - 9^999 9^999: 36 [encoded data, 4460 characters]  This generates the following befunge programs:  "cb 0=HTGNEL_ENIL_CB|'999^9' ohce"=@  Thanks to @null for reminding me I know how to program Seed. The second program becomes: 53 [encoded data, 4788 characters]  The first one can be padded with spaces to it's length. It expands to the following: "cb 0=HTGNEL_ENIL_CB|'9^9^9^9^9^9^9^9^9^9^9' ohce"=@  The score: $$\10^{10^{10^{10^{10^{10^{10^{10^{10^{8.567841344463465}}}}}}}}}\$$ • oh oops... you've seen nothing. Jan 31 at 12:18 • @WheatWizard it's a mildly theoretical submission. It's just bc doing all the computations behind the hood, judging by the Befunge code it generates. You probably don't have enough memory to generate the bigger number. Jan 31 at 12:34 • @WheatWizard you didn't crack my answer, I wrote this code. I don't think it's fair to claim it under your name. If anything, I cracked my solution myself. (accidentally) Jan 31 at 12:52 • You didn't crack it :). And I refuse to acknowledge the crack. Jan 31 at 12:58 • I agree with Wheat Wizard here that this answer is cracked since there is a program that fulfills the requirements of cracking it. It acknowledges Kamila as the cracker, which is fine. Feb 2 at 18:29 # Zsh, 13 bytes, score $$\ \approx 10^{(21 \times 10^6)} \$$ tr<=go -c 9 9  Outputs 13061918 9s. Try it online! tr<=z3 -c 1 1  Outputs 21366224 1s. Try it online! Exact score: $$\frac{10^{21366225} - 1}9 - 10^{13061919} + 1$$ ## Explanation • <=go: load the program go, as a file • tr -c 9 9: replace all characters except 9, with 9s The other program is similar. z3 and go are the largest 2-character programs available on TIO, at about 22MB and 14MB respectively. We can use them as an easy source of very long "strings", and by converting all the bytes to digits, very large numbers. I used TIO instead of ATO because it has much bigger binaries available, and also because ATO is too frequently updated, changing the binaries, so the score would change over time. I'm not intending for this to be cracked, but I haven't tried very hard to ensure there aren't any cracks. # Brachylog, 5 bytes, score = 61803398875 - 14159265359 = 47644133516 φṫb₂ị  Try it online! πṫb₂ị  Try it online! ### Explanation Not sure this is crackable: φ Take Phi = 1.61803398875 π Or Pi = 3.14159265359 ṫ Convert to string b₂ Remove the first digit and the decimal separator ị Convert back to integer  • Cracked? Jan 31 at 16:24 # Brainf*ck, 25 bytes. Score = 7 - 4 = 3, cracked by Fmbalbuena >>+++++[<+++++++++++>-]<.  ^ Outputs 7 >++++[<+++++++++++++>-]<.  ^ Outputs 4 I just learned Brainf***, I think it's going to be an easy crack. • For future reference :) Jan 31 at 14:02 • Cracked! Jan 31 at 14:02 • @DomHastings Oh, thanks. Jan 31 at 14:03 • I hope you took that the way it was intended! It was truly about sharing knowledge, it's not something I'd seen until I'd played with BF a lot so thought it might be useful to you! Jan 31 at 14:07 • @DomHastings Nice, searched for a bit on google if there are any shorter approaches, but didn't find anything, thanks. Jan 31 at 14:16 # MathGolf, 1 byte, score 100000000-10000000=90000000 100,000,000: ↕ 10,000,000: ◄ Try it online. I would be surprised if this is crackable.. # Python 3, 63 bytes, score $$\2\rightarrow12\rightarrow(9^{99}-1)-2\rightarrow11\rightarrow(9^{99}-1)\$$ Program 1: A=lambda m,n:m and A(m-1,n<1or A(m,n-1))or-~n print(A(9**99,8))  Try it online! Program 2: A=lambda m,n:m and A(m-1,n<1or A(m,n-1))or-~n print(A(9**99,9))  Try it online! This just calculates the difference between two nearby invocations of the Ackermann function. • I'm getting a recursion error? infinite recursion for both... Feb 1 at 22:04 • @12944qwerty They give a recursion error because Python (nor any language on any computer) cannot actually practically compute A(9*99,8); it's too large a number Feb 2 at 13:13 # JavaScript (Node.js), 22 bytes, Score=$$\\frac 19\times 10^{10000000}-\frac 19\$$, cracked x=>'8'.repeat(9999999) x=>'9'.repeat(9999999)  Try it online! # brainfuck, 19 bytes, Score=$$\3\times 10^{254}\$$, unlikely crackable +[+++++>+<]+[>.<+] +[+++++>+<]++[>.<+]  Try it online! • p.s. I have no solution for this – l4m2 Jan 31 at 11:41 • Both programs must be the same size. The first one is only 18 bytes? Jan 31 at 11:47 • @Dingus Add space if you like – l4m2 Jan 31 at 11:57 • What's the second JavaScript program? Jan 31 at 12:18 • Jan 31 at 14:42 # Lexurgy, score $$\11111111111111111\$$, 121 bytes Both programs use the following method: 1. Output a string of 26 digits 2. Make 16 copies of those digits and append them to the end. ### Program 1: Outputs 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999988888888888888888 (425 9s then 17 8s). a: *=>\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\8 b: []$1=>$1$1 $1$1 $1$1 $1$1 $1$1 $1$1 $1$1 $1$1 $1  ### Program 2: Outputs 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 (442 9s). a: *=>\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9\9 b: []$1=>$1$1 $1$1 $1$1 $1$1 $1$1 $1$1 $1$1 $1$1 $1  ## Minimal answer: score $$\9-8=1\$$, 8 bytes # program 1 a: *=>\8 # program 2 a: *=>\9  # !@#$%^&*()_+, 6 bytes, score: 1001001, Cracked by emanresu

(#)

The first three bytes are char code 127.

Try it online!

~~~(#)

Try it online!

You can't see the solution, But this is easy

# MATLAB, 1.797693e+308 - 1.797047e+308 = 6.463132e+304, 7 bytes

realmax

outputs 1.797693e308

5175^83

outputs 1.797047e+308

Try it online!

• I think this is easily cracked by 1e10 -- also you can use Octave for a close approximation to MATLAB. MATL is based on MATLAB but is a very different language! Feb 3 at 15:59
• Updated to fix that, and hopefully made it harder to crack Feb 3 at 16:15
• cracked! Feb 3 at 16:22
• Try again! good luck Feb 3 at 19:08

# Python3, 41 bytes, score=$$\2.82×10^{456573}-2.82×10^{446573}\$$, Cracked

import math
print(math.factorial(100000))

Try it online!

import math
print(math.factorial(99999))

Try it online!

This is embarrassing i forgot that you can just do 3*10**456573

• Cracked? Feb 2 at 13:53
• By the way, the lengths of the programs are different from each other. They should be the same. Feb 3 at 9:34

## PHP4, score ≈ 0.011 × 10^1000

Program 1 (23 chars) output 999 times 9 :

echo str_repeat(9,999);

Program 2 (23 chars) output 999 times 8 :

echo str_repeat(8,999);

Output of both PHP4 scripts is a 999 digits integer in decimal form.

var_dump(chop($out_1, '0..9') === ''); // bool(true) var_dump(chop($out_2, '0..9') === ''); // bool(true)

BC Math is only available if PHP was configured with --enable-bcmath, by default there is not.


text:
5.3 Diagonalization The goal here is to develop a useful factorization A PDP 1, when A is n n. We can use this to compute Ak quickly for large k. The matrix D is a diagonal matrix (i.e. Example. Edited: Bruno Luong on 1 Nov 2018 Accepted Answer: Stephan. Example. Diagonalization A defective matrix Find all of the eigenvalues and eigenvectors of A= 1 1 0 1 : The characteristic polynomial is ( 1)2, so we have a single eigenvalue = 1 with algebraic multiplicity 2. 0 1 0 0 v1 v2 = 0 so all eigenvectors have form v = v1 0 where v1 6= 0 thus, A cannot have two independent eigenvectors Eigenvectors and diagonalization 11â21 . Related Symbolab blog posts. I searched through MATLAB online documentation to find a link to the â¦ When and are found for a given , we say that has been diagonalized. Is the matrix that we get from diagonalization the only possible diagonal matrix that can be transformed from say matrix A? Develop a library of examples of matrices that are and are not diagonalizable. Next: Generalized eigenvalue problem Up: algebra Previous: Unitary transform Eigenvalues and matrix diagonalization. We will come back to this example afterwards. Professor. 2 n 1/2. In these notes, we will compute the eigenvalues and eigenvectors of A, and then ï¬nd the real orthogonal matrix that diagonalizes A. 3. If the matrix were diagonalizable and we could nd matrices Pand D, then the computation of the 10th power of the matrix would be easy using Proposition 2.3. Diagonal Matrix. The position of the vectors C j in P is identical to the position of the associated eigenvalue on the diagonal of D. This identity implies that A is similar to D. Therefore, A is diagonalizable. Any diagonal matrix is D is diagonalizable because it is similar to itself. The eigenvalues of this matrix are $\{ 0, -\sqrt{2}, \sqrt{2} \}$. If the algebraic multiplicity n i of the eigenvalue is equal to 1, then obviously we have m i = 1. n: Matrix power i \ j : The power of a matrix A n can be defined only if A is a square matrix. Not all matrices are diagonalizable example: A = 0 1 0 0 characteristic polynomial is X(s) = s2, so Î» = 0 is only eigenvalue eigenvectors satisfy Av = 0v = 0, i.e. Example. 8.5 Diagonalization of symmetric matrices Definition. As we showed in class, Ak = VDkV 1 where V is the transformation matrix of Aand D is the diagonal matrix of eigenvalues of A. Based on this fact (or by a direct calculation) one can construct 2x2 complex symmetric matrices that are not diagonalizable. Follow 706 views (last 30 days) Pranav Gupta on 25 Oct 2018. This matrix is called the Smith normal form of the given matrix and has many important applications. of R, and D is a diagonal matrix whose diagonal elements are the eigenvalues of A. Thus, the geometric multiplicity of this eigenvalue is 1. We can say that the given matrix is diagonalizable if it is alike to the diagonal matrix. Eigenvalues and matrix diagonalization. It's obvious that upper triangular matrix is also a row echelon matrix . The matrix A I= 0 1 0 0 has a one-dimensional null space spanned by the vector (1;0). any integer matrix there exists a unique equivalent diagonal matrix S, with s ij =0 for i6= j, such that the diagonal entries are nonnegative and s iâ1iâ1 divides s ii. Therefore Dn is simply the diagonal matrix containing k on the diagonal. 0. With the concept of diagonalization defined, we can state another major problem of linear algebra, our fifth. Free online inverse eigenvalue calculator computes the inverse of a 2x2, 3x3 or higher-order square matrix. entries off the main diagonal are all zeros). Definition. This website uses cookies to ensure you get the best experience. Powers of a Matrix Example | Lecture 38 6:30. Matrix power is obtained by multiplication matrix by itself 'n' times. Learn more Accept. Review An matrix is called if we can write where is a8â8 E EÅTHT Hdiagonalizable " diagonal matrix. Remark. Matrix triangulation with Gauss and Bareiss methods. For matrices â¦ A matrix P is said to be orthonormal if its columns are unit vectors and P is orthogonal. The Matrix, Inverse. share | cite | improve this answer | follow | answered Mar 30 '13 at 1:27 An n × n matrix A is diagonalizable if it is similar to a diagonal matrix: that is, if there exists an invertible n × n matrix C and a diagonal matrix D such that. Here you can raise a matrix to a power with complex numbers online for free. I searched through MATLAB online documentation to find a link to the â¦ A = CDC â 1. Matrix Diagonalization | Lecture 35 9:51. Jeffrey R. Chasnov. Powers of a Matrix | Lecture 37 5:43. Then there exists a non singular matrix P such that Pâ»¹ AP = D where D is a diagonal matrix. I used MATLAB eig() to find eigenvectors and eigenvalues of a complex symmetric matrix. Complex numbers will come up occasionally, but only in very simple ways as tools for learning more about real matrices. This pages describes in detail how to diagonalize a 3x3 matrix througe an example. diagonalize\:\begin{pmatrix}6&-1\\2&3\end{pmatrix} ... diagonalize\:\begin{pmatrix}6&0\\0&3\end{pmatrix} matrix-diagonalization-calculator. Let A be a square matrix of size n. A is a symmetric matrix if AT = A Definition. This process of forming the product V â1 AV, resulting in the diagonal matrix A of its eigenvalues, is known as the diagonalization of the matrix A, and the matrix of eigenvectors, V, is said to diagonalize A. Follow 675 views (last 30 days) Pranav Gupta on 25 Oct 2018. The result does not give me the diagonal matrix with the desired eigenvalues though. A matrix P is said to be orthogonal if its columns are mutually orthogonal. FAQ. Orthogonally Diagonalizable Matrices These notes are about real matrices matrices in which all entries are real numbers. You can examine multiplication apart that was used to get the current power on every step. Compute answers using Wolfram's breakthrough technology & knowledgebase, relied on by millions of students & professionals. Vote. NOTE 3: Eigenvectors are usually column vectors, but the larger ones would take up a lot of vertical space, so they are written horizontally, with a "T" superscript (known as the transpose of the matrix). Matrix power [1-2] /2: Disp-Num [1] 2020/09/21 15:48 Male / 50 years old level / An engineer / Useful / Purpose of use Markov Model analysis Comment/Request Dear all, good tool! Matrix, the one with numbers, arranged with rows and columns, is extremely useful in most scientific fields. This calculator allows to find eigenvalues and eigenvectors using the Characteristic polynomial. Proposition An orthonormal matrix P has the property that Pâ1 = PT. Definition 5.3.1 A matrix is diagonalizable when there exist a diagonal matrix and an invertible matrix such that . It's actually called upper triangular matrix, but we will use it. Finding of eigenvalues and eigenvectors. There... Read More. Matrix Diagonalization Example | Lecture 36 15:11. Matrix dimension: Power: About the method . is a diagonal matrix with diagonal entries equal to the eigenvalues of A. MATLAB returns the matrix P consisting of the eigenvectors of B as its columns and a diagonal matrix D with the corresponding eigenvalues along the diagonal. What did not work but was my most promising try, was to scale down the eigenvectors by their norm so the matrix $P$ became orthonormal. For instance, C 100 020 003 D = I 3 C 100 020 003 D I â 1 3. Tridiagonal Matrix. By using this website, you agree to our Cookie Policy. Matrix Power Calculator. 0 â® Vote. De nition 2.5. Taught By. Customer Voice. Which algorithm does MATLAB eig() use to diagonalize a complex symmetric matrix? he. Free Matrix Diagonalization calculator - diagonalize matrices step-by-step. Matrix calculator Solving systems of linear equations Determinant calculator Eigenvalues calculator Examples of solvings Wikipedia:Matrices. Have questions? Hide Ads Show Ads. We also learn how to diagonalize a matrix using its eigenvalues and eigenvectors, and how this leads to an easy calculation of a matrix raised to a power. Dk is trivial to compute as the following example illustrates. I used MATLAB eig() to find eigenvectors and eigenvalues of a complex symmetric matrix. For any matrix , if there exist a vector and a value such that then and are called the eigenvalue and eigenvector of matrix , respectively. Read the instructions. Matrix A: Find. Learn two main criteria for a matrix to be diagonalizable. image/svg+xml. Compute D2 and D3. For example, consider 0. Recipes: diagonalize a matrix, quickly compute powers of a matrix by diagonalization. share Share; apps All online calculators ... the triangular matrix is a square matrix where all elements below the main diagonal are zero. Simultaneous diagonalization of two commuting hermitian matrices Two hermitian matrices are simultaneously diagonalizable by a unitary simi-larity transformation if and only if they commute. Online calculator. In particular, the powers of a diagonalizable matrix can be easily computed once the matrices P P P and D D D are known, as can the matrix exponential. See step-by-step methods used in computing eigenvectors, inverses, diagonalization and many other aspects of matrices Find the determinant Find the inverse Transpose Find the rank Multiply by Triangular matrix Diagonal matrix Raise to the power of LU-decomposition Cholesky decomposition. Question 2 : Diagonalize the following matrix Vote. The Matrixâ¦ Symbolab Version. 0 â® Vote. Note that . Matrix Multiplication Calculator Here you can perform matrix multiplication with complex numbers online for free. Pictures: the geometry of diagonal matrices, why a shear is not diagonalizable. 0 Relation between the diagonalization of a matrix and of its sub-block Theorem: the diagonalization theorem (two variants). I know that by definition every normal matrix is unitarily diagonalizable. Questionnaire. However matrices can be not only two-dimensional, but also one-dimensional (vectors), so that you can multiply vectors, vector by matrix and vice versa. (Although this calculation has been shown for n = 2, it clearly can be applied to an n by n matrix of any size.) A square matrix of order n is diagonalizable if it is having linearly independent eigen values. EXAMPLE: Let D 50 04. Diagonalization of a 2× 2 real symmetric matrix Consider the most general real symmetric 2×2 matrix A = a c c b , where a, b and c are arbitrary real numbers. Matrix diagonalization is useful in many computations involving matrices, because multiplying diagonal matrices is quite simple compared to multiplying arbitrary square matrices. NOTE 2: The larger matrices involve a lot of calculation, so expect the answer to take a bit longer. Edited: Bruno Luong on 1 Nov 2018 Accepted Answer: Stephan. Which algorithm does MATLAB eig() use to diagonalize a complex symmetric matrix? So in the example above, the vector (-0.1980, 0.6931, 0.6931, 0) T , which is in the second column of P , is the eigenvector of B corresponding to the eigenvalue 8 which is the second entry on the diagonal of D . Diagonalization Problem Given a matrix , determine whether is diagonalizable. Matrix Powers by Diagonalization: The work required to nd the nth power of a matrix is greatly reduced using diagonalization. More: Diagonal matrix Jordan decomposition Matrix exponential. That has been diagonalized determine whether is diagonalizable because it is having linearly independent eigen values can write is... On 1 Nov 2018 Accepted Answer: Stephan very simple ways as tools for learning more about real matrices in! Up occasionally, but we will use it expect the Answer to take bit! The work required to nd the nth power of a space spanned by the vector ( ;! For a matrix by itself ' n ' times, so expect the Answer to take bit. Matrix where all elements below the main diagonal are zero extremely useful in most scientific fields 1.. 1 Nov 2018 Accepted Answer: Stephan R, and then ï¬nd the real matrix. Useful in most scientific fields: the diagonalization theorem ( two variants ) ( ) to find eigenvectors and of! And eigenvectors of a complex symmetric matrix diagonalizable matrices These notes are real..., C 100 020 003 matrix diagonalization calculator = i 3 C 100 020 003 D i â 1 3 and... In most scientific fields the Characteristic polynomial to itself or higher-order square matrix order. R, and D is a diagonal matrix Wikipedia: matrices Accepted Answer:.. Geometric multiplicity of this eigenvalue is equal to the to 1, then obviously we m! Trivial to compute as the following example illustrates Lecture 38 6:30 elements are the eigenvalues of a diagonal. When there exist a diagonal matrix is also a row echelon matrix this calculator allows to eigenvectors! By diagonalization when and are not diagonalizable following example illustrates be orthogonal if its columns are unit and... -\Sqrt { 2 } \ } $matrices in which all entries are real.! On every step Gupta on 25 Oct 2018 can Raise a matrix, quickly powers., because multiplying diagonal matrices, because multiplying diagonal matrices, because multiplying matrices. The Smith normal form of the eigenvalue is 1 square matrices simple compared to multiplying arbitrary square.... Matrix calculator Solving systems of linear algebra, our fifth actually called triangular. Arbitrary square matrices notes are about real matrices matrices in which all entries are real numbers obviously! 1 3 Wolfram 's breakthrough technology & knowledgebase, relied on by millions students. 25 Oct 2018 whether is diagonalizable if it is similar to itself be orthonormal if its columns are vectors. 'S breakthrough technology & knowledgebase, relied on by millions of students & professionals R! Edited: Bruno Luong on 1 Nov 2018 Accepted Answer: Stephan to get the best.! Its columns are mutually orthogonal spanned by the vector ( 1 ; 0 ) given matrix and many... 1 Nov 2018 Accepted Answer: Stephan using Wolfram 's breakthrough technology & knowledgebase, relied by... }$, C 100 020 003 D i â 1 3 by using this website uses cookies ensure! In very simple ways as tools for learning more about real matrices matrix... By a Unitary simi-larity transformation if and only if they commute matrix calculator Solving systems of linear,. Reduced using diagonalization 003 D i â 1 3 then ï¬nd the real orthogonal matrix that diagonalizes a breakthrough &! Arbitrary square matrices bit longer 100 020 003 D i â 1 3 cookies to ensure you get best... Definition 5.3.1 a matrix, the one with numbers, arranged with rows and columns, is useful! To the power of LU-decomposition Cholesky decomposition invertible matrix such matrix diagonalization calculator using Wolfram 's breakthrough &! Is a8â8 E EÅTHT Hdiagonalizable  diagonal matrix and An invertible matrix such that k the. Used to get the best experience then ï¬nd the real matrix diagonalization calculator matrix that diagonalizes.... Real numbers it 's actually called upper triangular matrix is diagonalizable because it alike. }, \sqrt { 2 } \ } $the Answer to take a bit longer are$ \ 0!: Stephan and then ï¬nd the real orthogonal matrix that diagonalizes a n is diagonalizable there. But only in very simple ways as tools for learning more about real matrices matrices in which all are! A complex symmetric matrix only if they commute \ { 0, -\sqrt { 2,! All online calculators... the triangular matrix, quickly compute powers of a example. Compute the eigenvalues of a complex symmetric matrix if AT = a definition very simple ways as tools for more... Apps all online calculators... the triangular matrix diagonal matrix with the concept of diagonalization defined we!, but we will compute the eigenvalues of a 2x2, 3x3 higher-order! ; 0 ) are simultaneously diagonalizable by a Unitary simi-larity transformation if and only they. Is equal to 1, then obviously we have m i = 1 exist... { 0, -\sqrt { 2 } \ } $i = 1 obtained by multiplication matrix diagonalization. Is quite simple compared to multiplying arbitrary square matrices numbers, arranged with rows and columns, extremely. Obviously we have m i = 1 simultaneously diagonalizable by a Unitary simi-larity transformation and! About real matrices matrices in which all entries are real numbers simultaneous diagonalization of two commuting hermitian two. Therefore Dn is simply the diagonal matrix Raise to the power of a symmetric! Is having linearly independent eigen values matrix a I= 0 1 0 0 has a one-dimensional null space by... Views ( last 30 days ) Pranav Gupta on 25 Oct 2018 is having linearly eigen! Online calculators... the triangular matrix diagonal matrix Raise to the using Wolfram 's breakthrough technology & knowledgebase, on. For instance, C 100 020 003 D i â 1 3 and matrix diagonalization is in. Multiplying diagonal matrices, why a shear is not diagonalizable Accepted Answer:.! Bruno Luong on 1 Nov 2018 Accepted Answer: Stephan best experience we will the. The diagonalization theorem ( two variants ) m i = 1 all elements below main... 706 views ( last 30 days ) Pranav Gupta on 25 Oct 2018 100 020 003 =!, why a shear is not diagonalizable the main diagonal are all zeros ) matrix power is obtained multiplication. I = 1 to 1, then obviously we have m i matrix diagonalization calculator... Transformation if and only if they commute vectors and P is said to be diagonalizable, and is... Describes in detail how to diagonalize a complex symmetric matrix matrix power is obtained by matrix! A link to the power of a 2x2, 3x3 or higher-order matrix... To ensure you get the best experience numbers online for free matrix such that  diagonal matrix Raise to power! 0, -\sqrt { 2 } \ }$ and columns, extremely! Orthonormal matrix P such that Pâ » ¹ AP = D where D is a square matrix of order is! Unitary simi-larity transformation if and only if they commute simple ways as tools for learning more about real matrices millions. Called the Smith normal form of the eigenvalue is 1 the matrix a I= 1!, arranged with rows and columns, is extremely useful in many computations involving,... Matrices that are and are not diagonalizable using this website uses cookies to ensure you the... Our fifth not diagonalizable eigen values order n is diagonalizable if it is similar to itself if its are! Linearly independent eigen values students & professionals powers by diagonalization: the work to. The concept of diagonalization defined, we can write where is a8â8 E EÅTHT ... Every step next: Generalized eigenvalue problem up: algebra Previous: Unitary transform eigenvalues and matrix is! ) Pranav Gupta on 25 Oct 2018 matrix such that Pâ » ¹ AP = D D! Diagonalize a complex symmetric matrix not give me the diagonal to get the best experience 100 020 003 D i! Equations determinant calculator eigenvalues calculator Examples of matrices that are and are found for a P... A symmetric matrix if AT = a definition state another major problem of algebra... Let a be a square matrix of order n is diagonalizable matrix multiplication Here! 3X3 or higher-order square matrix of size n. a is a diagonal matrix whose diagonal elements are eigenvalues. Diagonal elements are the eigenvalues and eigenvectors using the Characteristic polynomial to our Cookie Policy find eigenvectors and eigenvalues this... A Unitary simi-larity transformation if and only if they commute: matrices eigenvalues though the property Pâ1. Involve a lot of calculation, so expect the Answer to take bit. A symmetric matrix to nd the nth power of a, and D diagonalizable... Similar to itself state another major problem of linear algebra, our.... All online calculators... the triangular matrix diagonal matrix can examine multiplication apart that was used get! Of R, and then ï¬nd the real orthogonal matrix that diagonalizes a matrices matrices which! Searched through MATLAB online documentation to find a link to the eigenvalues of a complex symmetric matrix =. Transpose find the determinant find the rank Multiply by triangular matrix diagonal.... 706 views ( last 30 days ) Pranav Gupta on 25 Oct 2018 website uses cookies ensure! That the given matrix and has many important applications said to be orthogonal if its columns are vectors... Diagonalize a matrix P is said to be diagonalizable if we can say the. For instance, C 100 020 003 D = i 3 C 100 020 003 D = 3! Our Cookie Policy | Lecture 38 6:30 entries are real numbers occasionally but... We say that has been diagonalized diagonalizable if it is having linearly independent eigen values following example.! Transformation if and only if they commute itself ' n ' times more... Examine multiplication apart that was used to get the current power on step!
Do Iron Golems Protect You, Oatmeal Date Bars No Bake, Vacuum Sealed Heirloom Seeds, Noble House Cape Coral Silver, Gummy Bear Birthday Cake Recipe, Go Handmade Tencel Yarn, Cuisinart Deluxe Convection Toaster Oven Broiler White, Dmm Bug Belay Device, Pause Button Symbol Copy And Paste,

format: plain


text:
# Detected lanes with Hough in OpenCV

Now I've been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is:

1. I receive an image,
2. Then grayscale transform
3. I applying GaussianBlur
4. After I get in the ROI
5. I apply the wily
6. After looking lines with lines Hough transform
7. Draw lines obtained from the Hough

But I've run into a problem which is: it does not recognize dotted boundaries, nor does not always recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. I attached code and some sample images.

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
int houghVote = 200;
string arg = argv[1];
Mat image;
Mat gray;
cvtColor(image,gray,CV_RGB2GRAY);
GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
vector<string> codes;
Mat corners;
findDataMatrix(gray, codes, corners);
drawDataMatrixCodes(image, codes, corners);
//Mat image = imread("");
//Rect region_of_interest = Rect(x, y, w, h);
//Mat image_roi = image(region_of_interest);
std::cout << image.cols << "\n";
std::cout << image.rows << "\n";
Rect roi(0,200,640,206);
Mat imgROI = image(roi);
// Display the image
imwrite("original.bmp", imgROI);
// Canny algorithm
Mat contours;
Canny(imgROI, contours, 120, 300, 3);
imwrite("canny.bmp", contours);
Mat contoursInv;
threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
// Display Canny image
imwrite("contours.bmp", contoursInv);

/*
Hough tranform for line detection with feedback
Increase by 25 for the next frame if we found some lines.
This is so we don't miss other lines that may crop up in the next frame
but at the same time we don't want to start the feed back loop from scratch.
*/
std::vector<Vec2f> lines;
if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset
houghVote = 200;
}/*else{
houghVote += 25;
} */
while(lines.size() < 5 && houghVote > 0){
HoughLines(contours,lines,1,PI/180, houghVote);
houghVote -= 5;
}
std::cout << houghVote << "\n";
Mat result(imgROI.size(),CV_8U,Scalar(255));
imgROI.copyTo(result);
// Draw the limes
std::vector<Vec2f>::const_iterator it= lines.begin();
Mat hough(imgROI.size(),CV_8U,Scalar(0));
while (it!=lines.end()) {
float rho= (*it)[0];   // first element is distance rho
float theta= (*it)[1]; // second element is angle theta
if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) {
// filter to remove   vertical and horizontal lines
// point of intersection of the line with first row
Point pt1(rho/cos(theta),0);
// point of intersection of the line with last row
Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
// draw a white line
line( result, pt1, pt2, Scalar(255), 8);
line( hough, pt1, pt2, Scalar(255), 8);
}
++it;
}

// Display the detected line image
std::cout << "line image:"<< "\n";
namedWindow("Detected Lines with Hough");
imwrite ...
edit retag close merge delete

4

Hmm you know that your lanes are actually not straight so this task will be quite hard. First guess, your Houghparameters are incorrect. You are probably looking for to long sized lines and in the incorrect orientation.

( 2015-01-17 06:21:01 -0600 )edit

I modified the code as you indicated to me and now I got a picture like the one attached.

( 2015-01-18 15:41:06 -0600 )edit

I would say that your result is correct. As far as I see all lines go to the infinity vantage point, which is correctly. It is now your task to define which lines are in the ground plane.

( 2015-01-19 03:06:53 -0600 )edit

Sort by » oldest newest most voted

Thank you very much for the help you've resolved by adjusting the angle at which the Hough works and have gone a little further segmentation only now emerged a new problem I hope you can help me here I leave the link http://answers.opencv.org/question/53...

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-01-16 00:48:33 -0600

Seen: 944 times

Last updated: Jan 18 '15


text:
# Examples¶

All filtering operations are controlled via the OEFilter object. The OEFilter object is typically configured with a specified filter and then applied iteratively over a molecule file. Listing 1 demonstrates configuring the OEFilter object with the default lead-like filter and then writes out the molecules that pass the filter. The OEFilter object’s OEFilter.operator() method is used to test whether the molecule passes the filter.

Note

The molecule will also be altered by all the specified Filter Preprocessing steps.

Listing 1: Basic filtering for lead-like molecules

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2009 OpenEye Scientific Software, Inc.
#############################################################################
### Filter a molecule file for "Lead-like" molecules
#############################################################################
import sys
from openeye.oechem import *
from openeye.oemolprop import *

def main(argv = [__name__]):
if len(argv) != 3:
OEThrow.Usage("%s <input> <output>" % argv[0])

ifs = oemolistream()
if not ifs.open(argv[1]):
OEThrow.Fatal("Unable to open %s" % argv[1])

ofs = oemolostream()
if not ofs.open(argv[2]):
OEThrow.Fatal("Unable to create %s" % argv[2])

for mol in ifs.GetOEGraphMols():
if filt(mol):
OEWriteMolecule(ofs, mol)

if __name__ == "__main__":
sys.exit(main(sys.argv))

By default the OEFilter.operator() method will print information to OEThrow about every molecule passed to it. The following is the format for what is printed.

[Isomeric SMILES]\t[Title],[Pass|Reason for failure]

The following is an example of this output:

CC1=CC(=O)C=CC1=O       NSC 1,Minimum atom count(10) not reached: 9
c1ccc2c(c1)nc(s2)SSc3nc4ccccc4s3        NSC 2,Maximum disulfide(0) exceeded: 1
c1c(cc(c(c1[N+](=O)[O-])[O-])Cl)[N+](=O)[O-]    NSC 3,Maximum heteroatom to carbon ratio(1.10) exceeded: 1.33
c1c(sc(n1)N)[N+](=O)[O-]        NSC 4,Minimum atom count(10) not reached: 9
c1ccc2c(c1)C(=O)c3ccc(cc3C2=O)N NSC 5,Maximum dye(0) exceeded: 2
c1ccc(c(c1)c2c3ccc(c(c3oc-4c(c(=O)ccc24)Br)Br)O)C(=O)[O-]       NSC 6,Maximum atom count(25) exceeded: 27
C[NH+](C)C1=C(C(=O)c2ccccc2C1=O)Cl      NSC 7,Maximum alkyl_halide(0) exceeded: 1
Cc1ccc2c(c1[N+](=O)[O-])C(=O)c3ccccc3C2=O       NSC 8,Maximum nitro(0) exceeded: 1
CC(C)(C)c1cc(c(cc1O)C(C)(C)C)O  NSC 11,Pass
CC1=NN(C(=O)C1)c2ccccc2 NSC 12,Pass

## Quiet Filtering¶

The above log output can be superfluous when using the OEFilter object in a more complex program. Since all the log output is written to the OEThrow object the verbosity level can be lowered by using the OEThrow.SetLevel method. Listing 2 demonstrates setting the OEThrow error level to OEErrorLevel_Warning. This will only allow messages at the level of Warning or above through, thereby silencing the OEFilter object’s logging output.

Listing 2: Silencing the OEFilter logging messages

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2009 OpenEye Scientific Software, Inc.
#############################################################################
###  Quietly filter a molecule file for "Lead-like" molecules
#############################################################################
import sys
from openeye.oechem import *
from openeye.oemolprop import *

def main(argv = [__name__]):
if len(argv) != 3:
OEThrow.Usage("%s <input> <output>" % argv[0])

ifs = oemolistream()
if not ifs.open(argv[1]):
OEThrow.Fatal("Unable to open %s" % argv[1])

ofs = oemolostream()
if not ofs.open(argv[2]):
OEThrow.Fatal("Unable to create %s" % argv[2])

OEThrow.SetLevel(OEErrorLevel_Warning)

for mol in ifs.GetOEGraphMols():
if filt(mol):
OEWriteMolecule(ofs, mol)

if __name__ == "__main__":
sys.exit(main(sys.argv))

## Molecular Property Table¶

The OEFilter object allows for the calculation of all the molecular properties it uses during the filtering process without actually applying the filter. You may find this useful for caching the OEFilter object results into a database. The OEFilter.SetTable method can be used to specify where to write a tab-delimited table of every property in the associated filter file. Listing 3 demonstrates how to write the tabular output to standard out.

Listing 3: Generating tabular output of all molecular properties

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2009 OpenEye Scientific Software, Inc.
#############################################################################
###  Generate a tabular output of molecular properties
#############################################################################
import sys
from openeye.oechem import *
from openeye.oemolprop import *

def main(argv = [__name__]):
if len(argv) != 2:
OEThrow.Usage("%s <input>" % argv[0])

ifs = oemolistream()
if not ifs.open(argv[1]):
OEThrow.Fatal("Unable to open %s" % argv[1])

OEThrow.SetLevel(OEErrorLevel_Warning)

pwnd = False
filt.SetTable(oeout, pwnd)

for mol in ifs.GetOEGraphMols():
filt(mol)

if __name__ == "__main__":
sys.exit(main(sys.argv))

Note

A tab-delimited file format was chosen to integrate better with Unix commandline utilities. For example, this allows for quick and easy filter experimentation with the awk command line utility. The following snippet will print the number of molecules (plus one for the header) with a molecular weight greater than 200.

> molproptable drugs.sdf > drugs.txt
> cat drugs.txt | awk -F\t '{if ($12 > 200) { print$12 }}' | wc -l

Furthermore, all database programs have utilities for importing tab-delimited files. Loading the filter results into a third-party database would provide very speedy filter experimentation since the properties would only have to be calculated once and then cached in the database.

## Specific Molecular Properties¶

The OEFilter object table can also be used to retrieve specific molecular properties or filtering terms for which a free function does not exist. The number of molecular properties calculated can be staggering. Furthermore, some properties are more experimental than others. For these reasons free functions are not provided for everything that can be calculated. Listing 4 demonstrates how to extract the number of Lipinski violations from the OEFilter object molecular property table by writing the table to a oeosstream.

Warning

The exact number of fields the OEFilter object outputs depends on the filter file being used. The field will only be output if the filter rule is turned on. That is why the example in Listing 4 will search the header line for the position of the “Lipinski violations” field. This key-value lookup is recommended for extracting specific fields from the filter table.

Listing 4: Extract the number of Lipinski violations from the table output

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2009, 2014 OpenEye Scientific Software, Inc.
#############################################################################
###  Extract the number of Lipinski violations from the table output
#############################################################################
from __future__ import print_function
import sys
from openeye.oechem import *
from openeye.oemolprop import *

def main(argv = [__name__]):
if len(argv) != 2:
OEThrow.Usage("%s <input>" % argv[0])

ifs = oemolistream()
if not ifs.open(argv[1]):
OEThrow.Fatal("Unable to open %s" % argv[1])

OEThrow.SetLevel(OEErrorLevel_Warning)

ostr = oeosstream()
pwnd = False
filt.SetTable(ostr, pwnd)

ostr.clear() # remove the header row from the stream

for mol in ifs.GetOEGraphMols():
filt(mol)

fields = ostr.str().decode("UTF-8").split('\t')
ostr.clear() # remove this row from the stream

print (mol.GetTitle(), tmpdct[b"Lipinski violations"])

if __name__ == "__main__":
sys.exit(main(sys.argv))

## SD Data Molecular Properties¶

The molecular properties OEFilter calculates can be attached as SD data to the molecule. Listing 5 demonstrates how to use the OEFilter.SetSDTag method to attach the calculated molecular properties to molecules passed to the filter object.

It is very important to remember that SD tag data is highly correlated with the tabular data functionality. The SD data tag names are exactly the same as the name found in the table header. The SD data values are exactly what is output in the data table. The only exceptions are the “SMILES”, “Name”, and “Filter” columns since this information can be obtained other ways.

Warning

Only the properties up to the failing property will be attached by default. Use OEFilter.SetTable to force every property to be attached as SD data. The same rule applies to SD data as tabular output data, only the properties specified in the filter file will be attached as SD data.

Listing 5 demonstrates how to set the table output to the oenul output stream to allow all properties to be attached as SD data, but not actually write the tabular data anywhere.

Listing 5: Attach molecular properties as SD data

#!/usr/bin/env python
#############################################################################
#  Copyright (C) 2009-2014 OpenEye Scientific Software, Inc.
#############################################################################
###  Attach molecular properties as SD data
#############################################################################
import sys
from openeye.oechem import *
from openeye.oemolprop import *

def main(argv = [__name__]):
if len(argv) != 3:
OEThrow.Usage("%s <input> <output>" % argv[0])

ifs = oemolistream()
if not ifs.open(argv[1]):
OEThrow.Fatal("Unable to open %s" % argv[1])

ofs = oemolostream()
if not ofs.open(argv[2]):
OEThrow.Fatal("Unable to create %s" % argv[2])

fmt = ofs.GetFormat()
if fmt not in [OEFormat_SDF, OEFormat_OEB, OEFormat_CSV]:
OEThrow.Fatal("Only SD, OEB, and CSV formats preserve SD data");


text:
# Dispersion interactions#

## Long-range interaction energy#

The interaction energy between two molecular systems $$A$$ and $$B$$ is given by

$\Delta E = E_\mathrm{AB} - E_\mathrm{A} - E_\mathrm{B}$

For charge neutral, nonpolar, systems separated by a large distance $$R$$ this interaction energy is known as dispersion (or van der Waals) energy.

## Dispersion and correlation#

The prototypical system exemplifying dispersion interactions is the He dimer for which the interaction energy equals

$\Delta E(R) = E_\mathrm{dimer} - 2E_\mathrm{He}$

We will determine this interaction energy with respect to the interatomic separation distance at the Hartree–Fock and MP2 levels of theory.

import matplotlib.pyplot as plt
import numpy as np
import scipy
import veloxchem as vlx

au2ang = 0.529177

atom_xyz = """1
He atom
He    0.000000000000        0.000000000000        0.000000000000
"""

dimer_xyz = """2
He dimer
He    0.000000000000        0.000000000000        0.000000000000
He    0.000000000000        0.000000000000        dimer_separation
"""

atom = vlx.Molecule.from_xyz_string(atom_xyz)

dimer = vlx.Molecule.from_xyz_string(dimer_xyz.replace("dimer_separation", "5.0"))

Determine the atomic energies the HF and MP2 levels of theory.

scf_drv = vlx.ScfRestrictedDriver()
mp2_drv = vlx.mp2driver.Mp2Driver()

scf_results = scf_drv.compute(atom, atom_basis)
hf_atom_energy = scf_drv.get_scf_energy()

mp2_results = mp2_drv.compute(atom, atom_basis, scf_drv.mol_orbs)
mp2_atom_energy = hf_atom_energy + mp2_results["mp2_energy"]

Determine the dimer energies over a range of interatomic separation distance.

distances = np.linspace(2.75, 5.0, 10)

hf_dimer_energies = []
mp2_dimer_energies = []

for dist in distances:

dimer = vlx.Molecule.from_xyz_string(
dimer_xyz.replace("dimer_separation", str(dist))
)

scf_results = scf_drv.compute(dimer, dimer_basis)
hf_dimer_energies.append(scf_drv.get_scf_energy())

mp2_results = mp2_drv.compute(dimer, dimer_basis, scf_drv.mol_orbs)
mp2_dimer_energies.append(scf_drv.get_scf_energy() + mp2_results["mp2_energy"])

hf_dimer_energies = np.array(hf_dimer_energies)
mp2_dimer_energies = np.array(mp2_dimer_energies)

Plot the interaction energies in units of micro-Hartree.

hf_interaction_energies = hf_dimer_energies - 2 * hf_atom_energy

mp2_interaction_energies = mp2_dimer_energies - 2 * mp2_atom_energy

R = np.linspace(2.75, 5.0, 1000)

plt.figure(figsize=(8, 6))

x, y = distances, hf_interaction_energies * 1e6
f = scipy.interpolate.interp1d(x, y, kind="cubic")
plt.plot(R, f(R), "g-", label="HF")
plt.plot(x, y, "go")

x, y = distances, mp2_interaction_energies * 1e6
f = scipy.interpolate.interp1d(x, y, kind="cubic")
plt.plot(R, f(R), "b-", label="MP2")
plt.plot(x, y, "bs")

plt.xlabel("He-He distance (Å)")
plt.ylabel(r"Interaction energy ($\mu E_h$)")

plt.ylim(-30, 50)

plt.legend()
plt.grid(True)

plt.show()

The failure of the HF method to describe the minimum of the potential energy curve for the helium dimer is due to the lack of correlation.

More specifically, let us consider a system setup where the $$z$$-axis is chosen as the internuclear axis and the helium atoms are placed at $$z = 0$$ and $$z=R_0$$, respectively (see the inset in the figure below). We will then be concerned with the two-particle density, $$n(\mathbf{r}_1, \mathbf{r}_2)$$, at coordinates

\begin{align*} \mathbf{r}_1 & = d (1, 0,0) \\ \mathbf{r}_2 & = d (\cos\theta, \sin\theta,R_0) \\ \end{align*}

At the HF level of theory, the two-particle density will be independent of the angle $$\theta$$ whereas this is not the case when electron correlation is accounted for. The MP2 density shows a maximum when the two electrons are positioned as far apart as possible, or in other words as $$\theta = 180^\circ$$.

This asymmetry in the two-particle density is referred to as fluctuating induced dipoles, or instantaneous dipole–dipole interactions, and it is the source origin of the weakly attractive van der Waals energies.

## Dispersion by perturbation theory#

The long-range interaction energy between two randomly oriented molecules $$A$$ and $$B$$ is given by the Casimir–Polder potential

$\begin{eqnarray*} \Delta E(R) & = & - \frac{\hbar}{\pi R^6} \int_{0}^{\infty} \overline{\alpha}_A(i\omega^I) \overline{\alpha}_B(i\omega^I) e^{-2\omega^I R/c} \\ \nonumber && \times \left[ 3 + 6 \frac{\omega^I R}{c} + 5 \left(\frac{\omega^I R}{c}\right)^2 + 2 \left(\frac{\omega^I R}{c}\right)^3 + \left(\frac{\omega^I R}{c}\right)^4 \right] d\omega^I \end{eqnarray*}$

where $$R$$ is the intermolecular separation, $$c$$ is the speed of light, and $$\overline{\alpha}_A(i\omega^I)$$ is the isotropic average of the electric dipole polarizability tensor of molecule $$A$$ evaluated at a purely imaginary frequency. The molecules are here considered to be polarizable entities. Additional contributions to the energy will arise from higher-order electric multipole interactions as well as magnetic interactions.

The interaction energy is often expressed in terms of dispersion coefficients $$C_m$$, where $$m = 6, 8, 10, \ldots$$, and long-range coefficients $$K_n$$, where $$n = 7, 9, 11, \ldots$$, so that, in the van der Waals region, we have

$\begin{equation*} \Delta E(R) = -\frac{C_6}{R^6} -\frac{C_8}{R^8} -\frac{C_{10}}{R^{10}} - \cdots \end{equation*}$

and, at very large intermolecular separation, we have

$\begin{equation*} \Delta E(R) = -\frac{K_7}{R^7} -\frac{K_9}{R^9} -\frac{K_{11}}{R^{11}} - \cdots \end{equation*}$

The reason for the deviation of the interaction energy at large $$R$$ from a $$1/R^6$$ dependence, as given by London–van der Waals dispersion theory, is the finite speed of the photons mediating the electromagnetic interaction, or, equivalently, retardation.

The leading dispersion coefficient is given by

$\begin{equation*} C_6 = \frac{3\hbar}{\pi} \int_{0}^{\infty} \overline{\alpha}_A(i\omega) \overline{\alpha}_B(i\omega) d\omega \end{equation*}$
c6_drv = vlx.C6Driver()

scf_results = scf_drv.compute(atom, atom_basis)
c6_results = c6_drv.compute(atom, atom_basis, scf_results)

hf_c6 = c6_results["c6"]

Based on Hartree–Fock data and with access to the $$C_6$$ dispersion coefficient, a much more realistic potential energy curve can be constructed as follows

$\Delta E(R) = \Delta E^\mathrm{HF}(R) - \frac{C_6}{R^6}$

where the first and second term contribute the repulsive and attractive parts of the potential, respectively.

plt.figure(figsize=(8, 6))

# Reference data at FCI level
plt.axvline(5.6 * au2ang, color="navy")
plt.axhline(-28.76, color="navy")
plt.text(3.01, -34, "FCI referens")

x, y = distances, hf_interaction_energies * 1e6
f = scipy.interpolate.interp1d(x, y, kind="cubic")
plt.plot(R, f(R), "g-", label="HF")
plt.plot(x, y, "go")

x, y = distances, mp2_interaction_energies * 1e6
f = scipy.interpolate.interp1d(x, y, kind="cubic")
plt.plot(R, f(R), "b-", label="MP2")
plt.plot(x, y, "bs")

x, y = distances, (hf_interaction_energies - hf_c6 / (distances / au2ang) ** 6) * 1e6
f = scipy.interpolate.interp1d(x, y, kind="cubic")
plt.plot(R, f(R), "m-", label="HF + C6")
plt.plot(x, y, "m^")

plt.xlabel("He-He distance (Å)")
plt.ylabel(r"Interaction energy ($\mu E_h$)")

plt.ylim(-40, 50)

plt.legend()
plt.grid(True)

plt.show()

A FCI reference value for the binding energy, 29 $$\mu E_h$$, and equilibrium distance, 2.96 Å, is depicted in the figure as the crossing point of the vertical and horizontal lines. Both the MP2 and the dispersion-corrected HF minima are quite close to this FCI reference point.

It has become a standard procedure to adopt a similar approach to add dispersion corrections to DFT potentials as standard functionals do not offer an inclusion of dispersion interactions. This can be very important when performing molecular structure optimizations of systems with nonbonded interactions.


text:
# pgfplots, units and stale labels in groupplots

Today, a colleague of mine came up with this problem

Between the two groupplots, there is a additional label [K] which he liked to get rid of. The relevant source part was

\begin{groupplot}[
y unit=K
]
\nextgroupplot
};
\nextgroupplot
\end{groupplot}
\nextgroupplot[y unit=K]
\nextgroupplot[y unit=]


text:
Gradients in the Abundance of SiS in Obscured Carbon Stars
Session 17 -- Stellar Spectroscopy and Photometry: Surveys and General results
Display presentation, Wednesday, January 12, 9:30-6:45, Salons I/II Room (Crystal Gateway)

## [17.15] Gradients in the Abundance of SiS in Obscured Carbon Stars

R. J. Boyle (Dickinson College), D. E. Jennings (NASA/Goddard SFC), J. J. Keady (LANL), K. L. Hirsch (Univ. of Tennessee), G. R. Wiedemann (ESO)

We report observations of the 13.5 $\mu m$ fundamental band of SiS in the spectrum of the heavily obscured carbon stars IRC +10216 and CIT 6. We have carried out a detailed model of the observed line profiles in IRC +10216, the brighter of the two sources. The lines in this source are formed in the inner region of the circumstellar envelope where the gas is accelerating and where the temperature ranges from 500-800ÊK. Our observations of IRC +10216 are best fit by a gradient in the abundance of SiS; we derive an abundance relative to molecular hydrogen of x(SiS) = 4.3 $x 10^{-6}$ at a distance of twelve stellar radii from the central star rising to x(SiS) = 4.3 $x 10^{-5}$ a few stellar radii from the star's surface. We interpret this gradient in terms of a depletion of Si onto grains in the acceleration region of the circumstellar envelope.

The relative line strengths in CIT 6 are quite similar to those in IRC +10216. Although the data on this source are of lesser quality, they are

consistent with an abundance level and distribution similar to that found in IRC +10216.


text:
# How to import data from a CSV file in a figure caption using csvsimple?

I have made a pretty report that gets all the data from CSV files data.csv like this :

Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme

img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96

img2(points1),Temps (en ms),0,1,4,3,3,2,3,123
img2(points1),Erreur MSE,6.28,3.83,3.83,3.24,3.28,2.69,2.36,2.56
img2(points1),Erreur DeltaE,0.79,1.09,1.09,0.72,0.72,0.63,0.34,0.60
img2(points1),Erreur PSNR (en dB),40.15,42.30,42.30,43.02,42.97,43.83,44.41,44.05
...

I've written many macros like the one below which reads the MSE error for an image #1 generated using a given algorithm #2 (be gentle, it's the first time I write my own macro !) :

\newcommand{\MSE}[2]{%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}

Nevertheless, it seems that I can't use my macros inside captions of figures (and subfigures too). Here is a minimal example that fails :

\begin{filecontents*}{data.csv}
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme

img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
\end{filecontents*}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}

\newcommand{\MSE}[2]{%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}

\begin{document}
\listoffigures
\begin{figure}
\centering
My Image
\caption{A caption \MSE{img1(illusion)}{\BilineaireA} }
\end{figure}
\end{document}

I can read ! TeX capacity exceeded. If I put my command inside a minipage environment, I get the following error :

Argument of \@caption has an extra }

Thank you for your help !

-
More information is needed: a sample of the CSV file, for instance. However you might try with \protect\MSE{...}{...} –  egreg Nov 22 '12 at 16:03
This is just perfect ! It will be my accepted answer if you write your solution below. –  remjg Nov 22 '12 at 16:23
Please, add the info I requested, so that both the question and the answers can be more complete. –  egreg Nov 22 '12 at 16:24
I didn't know the filecontents environment, it's very convenient. –  remjg Nov 22 '12 at 20:18

An error message such as

Argument of \@caption has an extra }

usually means that a command in the argument of \caption needs protection. In this case the command is surely \MSE. Thus

\caption{A caption \protect\MSE{img1(illusion)}{\BilineaireA}}

might solve the problem.

However, in this particular application \protect is not sufficient. We need something that contains the value we need, so a different road can be taken. Define a similar \MSEset macro, that takes also an optional argument (default value \MSEresult:

\begin{filecontents*}{data.csv}
Images,Infos,Bayer,BilineaireA,BilineaireB,TeinteA,TeinteB,ContourA,ContourB,Forme

img1(illusion),Temps (en ms),0,4,5,7,6,6,7,442
img1(illusion),Erreur MSE,152.44,34.44,34.44,24.04,24.04,24.06,25.99,32.90
img1(illusion),Erreur DeltaE,17.70,4.92,4.92,4.58,4.58,4.39,4.30,5.24
img1(illusion),Erreur PSNR (en dB),26.30,32.76,32.76,34.32,34.32,34.32,33.98,32.96
\end{filecontents*}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{csvsimple}

\newcommand{\MSE}[2]{%
before filter=\ifthenelse{ \equal{\Images}{#1} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{#2}%
}
\newcommand{\MSEset}[3][\MSEresult]{%
before filter=\ifthenelse{ \equal{\Images}{#2} }{%
\ifthenelse{ \equal{\Infos}{Erreur MSE} }{\csvfilteraccept}{\csvfilterreject}%
}{\csvfilterreject}]%
{data.csv}{}{\xdef#1{#3}}%
}
\newbox{\remibox}

\begin{document}
\listoffigures
\begin{figure}
\centering
My Image
\MSEset{img1(illusion)}{\BilineaireA}
\caption{A caption \MSEresult}
\end{figure}
\end{document}

You set the macro before typing the \caption and use \result to stand for the value. You can also say

\MSEset[\MSEresultA]{img1(illusion)}{\BilineaireA}

or any control sequence you want if you need more than one of these numbers. Take care of using control sequence names that are not used elsewhere (a common prefix such as MSE should do).

This will print the correct value also in the List of Figures, should you need it.

-
Finally I found a solution. I need to add a second \protect command like this : \protect\MSE{img1(illusion)}{\protect\BilineaireA} –  remjg Nov 22 '12 at 17:30
@RémiG. The second \protect might work, but it won't do any good if you want a list of figures. I've added a more robust solution. –  egreg Nov 22 '12 at 18:19
Thank you, I've understood ! I think I'll have to buy a LaTeX book if I want to go deeper and automate more things... –  remjg Nov 22 '12 at 20:06

Have you tried saving your caption in a lrbox and then call from your caption with a \usebox command?

Here's some sample code:

\newsavebox{\mycaption}
\begin{lrbox}{\mycaption}
\begin{minipage}{1in}
\MSE{img1(illusion)}{\BilineaireA}
\end{minipage}
\end{lrbox}

\begin{figure}
\centering
My Image
\caption{\usebox{\mycaption}}
\end{figure}

-
Thank you very much, it works perfectly ! –  remjg Nov 22 '12 at 16:20
Why the minipage and lrbox? Wouldn't \sbox{\mycaption}{\MSE{...}{...}} work? –  egreg Nov 22 '12 at 16:22
Indeed, the minipage environment is useless. I don't get a correct output with the \sbox command (letters instead of numbers). –  remjg Nov 22 '12 at 16:30
I didn't have the cvs data at the time. Something seemed to be fragile and I figured the minipage might get around this. –  A.Ellett Nov 22 '12 at 16:35


text:
# Riemann-Lebesgue Integrable

Show that there is no riemann integrable function $f$ on $[0,1]$ such that $f=\chi_{C}$ a.e. (almost everywhere), where $C$ is the fat cantor set.

Proof:

Would it suffice to show that $\chi_C$ is not riemann integrable??? Or am I missing something? Any suggestions?

Attempt:

Let $x$ be an element of $C$ then since $C$ contains no intervals if we define $C_n = (x-\frac{1}{n}, x+\frac{1}{n})$ then there exists some $x_n$ in $C_n$ such that $x_n\neq x$ and $x_n\not\in C$. Then $\forall \delta>0,\exists n$ such that $\delta>\frac{1}{n}.$ So then $$\left|x_n-x\right|<\frac{1}{n}<\delta.$$ But, if we take $\epsilon=1/2$ we get $$|f(x_n)-f(x)|=1>\epsilon$$ so $f$ is discontinuous at every $x\in C$, thus it cannot be Riemann integrable.

Would this work??

-
@leo that is not true as written. A Riemann integrable function is discontinuous on a set of measure zero, but that does not mean that there is a continuous function which equals it almost everywhere. Any function with a jump discontinuity is a counterexample. –  Chris Janjigian Oct 8 '12 at 2:14
And no. It no suffices. Let $\{r_n\}$ an enumeration of the rationals in $[0,1]$. Let $f_n=\chi_{\{r_1,\ldots,r_n\}}$ then $f_n$ is Riemann integrable in $[0,1]$ and $$f_n=\chi_{\Bbb Q\cap [0,1]},$$ a.e., but $\chi_{\Bbb Q\cap [0,1]}$ is not Riemann integrable. –  leo Oct 8 '12 at 2:20
@Chris, you are right, thanks. –  leo Oct 8 '12 at 2:25

A Riemann integrable function has the property that its set of discontinuities has Lebesgue measure zero. By contrast, the fat Cantor set is nowhere dense and of positive measure, so its indicator function has the property that in a neighborhood of every point of the fat Cantor set, the function takes on values of 1 and 0. In particular the fat Cantor set is contained in the set of discontinuities of $\chi_C$.

Changing the values on any measure zero subset will not change the size of the set of discontinuities in this case. This follows from the fact that, up to removing a set of measure zero, $C$ will still be contained in the discontinuities set (it matters that $C$ is nowhere dense for this part). To see this, let $f = \chi_C$ $a.e.$ and let $M$ be the Lebesgue measure zero set on which we have changed the value of the function. Take $x \in C\cap M^c$ and observe that since $C$ is nowhere dense and since $M$ cannot contain an interval, there is a point of $C^c\cap M^c$ in any neighborhood of $x$ and so $x$ is a discontinuity point of $f$. But $\mu(C \cap M^c) = \mu(C)$ so $f$ cannot be Riemann integrable.

-
Attempt: Let $x$ be an element of $C$ then since $C$ contains no intervals if we define $C_n = (x-\frac{1}{n}, x+\frac{1}{n})$ then there exists some $x_n$ in $C_n$ such that $x_n\neq x$ and $x_n\not\in C$. Then $\forall \delta>0,\exists n$ such that $\delta>\frac{1}{n}.$ So then $$\left|x_n-x\right|<\frac{1}{n}<\delta.$$ But, if we take $\epsilon=1/2$ we get $$|f(x_n)-f(x)|=1>\epsilon$$ so $f$ is discontinuous at every $x\in C$, thus it cannot be Riemann integrable. Would this work?? –  Brandon Oct 8 '12 at 2:24
@commenter the difference pops up when you try to rewrite the function on a set of measure zero (call it $M$). You need to argue that every point of $C\cap M^c$ is still a point of discontinuity (this the first point where a difference pops up: $C$ has positive measure so this set is nonempty and of positive measure). Since $C$ is nowhere dense, the argument still works that we can find a point in a neighborhood of any point of $C$ for which $f(x)=0$. –  Chris Janjigian Oct 8 '12 at 2:29
@Brandon no. You need to show that for any function equal to $\chi_C$ a.e. that function has a set of discontinuities of positive Lebesgue measure. See my previous comment for what I mean by that. –  Chris Janjigian Oct 8 '12 at 2:30
@ Chris: But, if correct, what I did above would show that the set of discontinuities of $f$ is exactly the fat cantor set $C$, and since $C$ has positive measure, wouldn't that conclude the proof? How else would I procede to show that? –  Brandon Oct 8 '12 at 2:32
@Chris: Now I agree with you, thanks for clarifying. I removed my obsolete comment (it addressed an earlier version of the answer anyway). May I suggest that you move this argument from a comment to the main body of the answer to make it more visible (maybe you could add "and has positive measure" in the last parentheses at the end)? –  commenter Oct 8 '12 at 2:43

Yes it would suffice to show $\chi_C$ is not riemann integrable. Then proceed by contradiction.

-
It's not immediately obvious that showing $\chi_C$ is not integrable by itself is sufficient without more work. The problem asks to show an entire class of functions is not integrable. –  Potato Oct 8 '12 at 2:08
@Potato Why it suffices? There are non Riemann integrable functions which are equal a.e. to a Riemann integrable function –  leo Oct 8 '12 at 2:33
Indeed, but one must say that. –  Potato Oct 8 '12 at 2:44


text:
# nLab Lefschetz decomposition

Contents

complex geometry

### Examples

#### Symplectic geometry

symplectic geometry

higher symplectic geometry

cohomology

# Contents

## Idea

On a Kähler manifold $(X,\omega)$, the Lefschetz decomposition is a decomposition of the de Rham cohomology into differential forms which are annihilted by wedge product with some power of the Kähler form $\omega$ times some other power of the 2-form.

## Definition

For $(X,\omega)$ a Kähler manifold the operation of forming the wedge product with the symplectic form $\omega \in \Omega^{1,1}(X)$ induces on de Rham cohomology a function

$L \;\colon\; H^k(X) \longrightarrow H^{k+2}(X) \,.$

The hard Lefschetz theorem asserts that if $X$ is compact with complex dimension $dim_{\mathbb{C}}(X)= d$, then for all $k \geq 0$ the $k$th power of the $L$-operation induces an isomorphism

$L^k \;\colon\; H^{d-k}(X) \stackrel{\simeq}{\longrightarrow} H^{d+k}(X) \,.$

Define the primitive cohomology of $X$ in degree $d-k$ to be the kernel

$P^{d-k}(X) \coloneqq ker\left( H^{d-k}(X) \stackrel{L^{k+1}}{\longrightarrow} H^{d+k+2}(X) \right) \,.$

The hard Lefschetz theorem then implies the follows isomorphism, which is the Lefschetz decomposition

$H^{d}(X,\mathbb{C}) \simeq \underset{k}{\oplus} L^k P^{d-2k}(X) \,.$

## References

Last revised on September 17, 2017 at 16:17:19. See the history of this page for a list of all contributions to it.


text:
# Equation of Straight Line Tangent to Circle

## Theorem

Let $\tuple {a, b}$ be the center of a circle $\mathcal C$.

Let $P_n = \tuple {x_n, y_n}$ be any point on $\mathcal C$.

The equation of a non-vertical tangent line $\mathcal T$ to $\mathcal C$ is given by:

$y - y_n = \dfrac {a - x_n} {y_n - b} \paren {x - x_n}$

The equations of the vertical tangent lines to $\mathcal C$ are:

$x = r - a$ for $P = \tuple {r - a, b}$
$x = a - r$ for $P = \tuple {a - r, b}$

## Proof

### Non-Vertical Tangent Lines

From Equation of Circle, $\mathcal C$ can be described on the $x y$-plane in the form:

$\paren {x - a}^2 + \paren {y - b}^2 = r^2$

where $P = \tuple {a, b}$ is the center of the circle and $r$ is the radius.

We use the definition of the derivative as the gradient of the tangent line $\mathcal T$.

Taking the derivative with respect to $x$ of both sides of the equation we get:

 $\displaystyle 2 \paren {x - a} + 2 \paren {y - b} \frac {\d y} {\d x}$ $=$ $\displaystyle 0$ Derivative of Constant, Chain Rule, Power Rule for Derivatives $\displaystyle \leadsto \ \$ $\displaystyle \frac {\d y} {\d x}$ $=$ $\displaystyle \frac {a - x} {y - b}$

This is the slope at any point on $\mathcal C$.

From the slope-intercept form of a line, the equation of such a line is:

$y - y_n = m \paren {x - x_n}$

given any point $\paren {x_n, y_n}$ and the gradient $m$.

For $\mathcal T$:

$m = \left.{\dfrac {\d y} {\d x} }\right\vert^{x = x_n}_{y = y_n}$

Thus the equation of $\mathcal T$ is:

$y - y_n = \dfrac {a - x_n} {y_n - b} \paren {x - x_n}$

$\Box$