Generating Equidistant Points on Unit Disk

Recently I needed an algorithm to generate equidistant points inside the unit disk with some of them placed on the boundary (circle). To my surprise, quick search didn’t reveal any simple method for this. Below is obvious solution & code, hopefully it will save some time for others.

MATLAB code:

function [x, y, Nb, Np] = eqdisk(Nr)
%EQDISK Generates equidistant points inside the unit disk.
%   Nr  [in]  - number of radial circles
%   x,y [out] - coordinates of generated points
%   Np  [out] - total number of generated points
%   Nb  [out] - points on boundary (on r = 1 circle)

dR = 1/Nr;

x(1) = 0;
y(1) = 0;

k = 1;
for r = dR:dR:1
    n = round(pi/asin(1/(2*k)));
    theta = linspace(0, 2*pi, n+1)'; 
    x = [x; r.*cos(theta(1:n))];
    y = [y; r.*sin(theta(1:n))];
    k = k+1;

Nb = n;
Np = size(x,1);

Algorithm is based on the idea of placing the points on concentric circles with (near-) equal arc length between them. Here is some examples:

Read More »

Posted in Numeric Analysis, Programming | 1 Comment

Computing Mixed Derivatives by Finite Differences

The post is aimed to summarize various finite difference schemes for partial derivatives estimation dispersed in comments on the Central Differences page. To gather them all in one place as a reference.

Listed formulas are selected as being advantageous among others of similar class – highest order of approximation, low rounding errors, etc. Please use comments to add other schemes.

Second order


(1)   \begin{equation*} \displaystyle{{\frac{\partial^2{f}}{\partial{x}\partial{y}}}\approx \frac{1}{4\,h^2}\left[f_{-1,-1}+f_{1,1}-f_{1,-1}-f_{-1,1}\right]} \end{equation*}


(2)   \begin{equation*} \frac{\partial^2 f}{\partial x \partial y} \approx \frac{1}{144 h^2}\left[   \begin{array}{l}     8(f_{1,-2}+f_{2,-1}+f_{-2,1}+f_{-1,2})-8(f_{-1,-2}+f_{-2,-1}+f_{1,2}+f_{2,1})\\    -(f_{2,-2}+f_{-2,2}-f_{-2,-2}-f_{2,2})+64(f_{-1,-1}+f_{1,1}-f_{1,-1}-f_{-1,1})   \end{array}\right] \end{equation*}

Read More »

Posted in Finite Differences, Numeric Analysis, Numerical Derivative | 1 Comment

Sinc Function and Gauss-Legendre quadrature

UPDATE: August 13, 2015.
Finally I was able to see the relation between the two. Gauss-Legendre quadrature is based on exactness on polynomials, which can be re-formulated in terms of frequency domain. As it turned out, this condition has very simple form:

    \[  \frac{d^n}{d\omega^n} H(\omega) \Biggr|_{\omega=0}= 2\,\frac{d^n}{d\omega^n} \text{sinc}(\omega) \Biggr|_{\omega=0}=\frac{2\,(-1)^{n}}{n+1} \]

where n=0,2,4,\dots,2k is polynomial degree and H(\omega) is frequency response of a quadrature rule.

This relation is very interesting as it allows us to build numerical integrators in frequency domain (see differentiators and smoothers for example).

How these two could possibly relate to each other? I had no idea, until I saw these two plots today:
Green curve is a frequency response of Gauss-Legendre quadrature of order N=15, red – N=25 and blue curve is the \mathrm{sinc}(\omega) function.

Read More »

Posted in Filter Design, Numeric Analysis, Numerical Integration | Leave a comment

MPFR C++ Debugger Visualizer in Visual Studio

Built-in debugger in Visual Studio has very nice extension capabilities. One particularly useful feature – developer can create custom visualizers for his own complex data types. Usually interactive debugger just shows data members of user-defined (and unknown to him) classes and structures, e.g.:

Obviously this is not very handy. In example above mpreal is arbitrary precision floating-point numeric type. It is only natural to show variables of the type as numbers, not as collection of low-level data pointers and properties.
Read More »

Posted in MPFR, Programming | 6 Comments

Chemistry in WordPress using QuickLaTeX

New version of QuickLaTeX is out – 3.7.7. Besides improvements in general functionality it includes special features for chemistry-oriented web sites:

  • Support of myChemistry environment \begin{rxn} ...\end{rxn} directly in the text (do not forget to include myChemistry into global/local preamble). Check examples on myChemistry home page.
  • Correct support of ChemFig package, no tikzpicture wrapping required anymore. However you have to use [latex] ... [/latex] tags to mark ChemFig code sections. We didn’t implement support ChemFig commands directly in the text since one picture can be generated using long sequence of commands, there is no way for QuickLaTeX to know where diagram starts/ends. Read More »
Posted in QuickLaTeX | Leave a comment

QuickLaTeX: Hackenbush diagram

Today I stumbled across Tikz Diagrams in Math Mode topic on tex.SE. Here is how QuickLaTeX solves the task (example is taken from one of the answers in the thread):

Rendered by

Read More »

Posted in QuickLaTeX | Tagged , , | Leave a comment

QuickLaTeX: tikZ-timing package

LaTeX package tikZ-timing created by Martin Scharrer allows easy typing of timing diagrams (digital waveforms) in offline documents.

With the aid of QuickLaTeX tikZ-timing diagrams can be used seamlessly in the WordPress blogs (or any other website). You can just paste tikZ-timing commands directly in the text – QuickLaTeX will compile them into images and embed in the published page.

Read More »

Posted in QuickLaTeX | Tagged , , | 2 Comments

QuickLaTeX: Laplace Transformation Symbols

There are special commands for Laplace-Transformation Symbols in trfsigns package (see The Comprehensive \textrm{\LaTeX} Symbol List, Table 81, page 40): \laplace and \Laplace .

To use them with QuickLaTeX, just include trfsigns in preamble (local or global), e.g:

  f(t) \laplace F(s) \qquad F(s) \Laplace f(t)

results in

    \[   f(t) \laplace F(s) \qquad F(s) \Laplace f(t) \]

Can you do that with other LaTeX plugins for WordPress :-)?

Posted in QuickLaTeX | Tagged , | 1 Comment

QuickLaTeX: tikZ graphics

QuickLaTeX is free online service which allows LaTeX usage on the web pages.

QuickLaTeX supports tikZ graphics since version 3.7.1.

User can insert tikZ code snippets directly on the page (in WordPress editor) between \begin{tikzpicture} ... \end{tikzpicture} commands. QuickLaTeX will render it into image and place on the page.

Read More »

Posted in QuickLaTeX | Tagged , , | 5 Comments

How To: QextSerialPort for Visual Studio 2010

QextSerialPort is a nice library for serial port communication. It is based on C++ cross-platform Qt framework and must have in the toolkit of DSP/embedded software developer.

I’ve spent several hours trying to compile QextSerialPort for Visual Studio 2010 + Qt 4.7.1. Here is my recipe to success.

We assume that Qt is installed in C:\Qt\4.7.1 (see How To Compile Qt 4.7 with Visual Studio 2010 for instructions).

Read More »

Posted in Programming | Tagged , , | 12 Comments