## FreeFem to Matlab – fast mesh import

I recently wrote a brief introduction to FreeFem++ in this post. FreeFem is a software designed for the numerical study of partial differential equations. It has the advantage of being able to easily define the geometry of the domain, construct and modify meshes, finite element spaces and solve problems on these meshes.

I use Matlab very often for numerical computations. Most of the numerical stuff I’ve done (take a look here if you want) was based on finite differences methods, fundamental solutions and other classical techniques different from finite elements methods. Once I started using finite elements I quickly realized that Matlab is not that easy to work with if you want some automated quality meshing. PDEtool is good, but defining the geometry is not easy. There is also a simple tool: distmesh which performs a simple mesh construction for simple to state geometries. Nevertheless, once you have to define finite element spaces and solve problems things are not easy…

This brings us to the topic of this post: is it possible to interface Matlab and FreeFem? First, why would someone like to do this? Matlab is easier to code and use than FreeFem (for one who’s not a C expert…), but FreeFem deals better with meshes and solving PDE with finite elements. Since FreeFem can be called using system commands, it is possible to call a static program from Matlab. FreeFem can save meshes and variables to files. Let’s see how can we recover them in Matlab.

There is a tool called “FreeFem to Matlab” developed by Julien Dambrine (link on Mathworks). There’s also a longer explanation in this blog post. I recently tried to use the tool and I quickly found that it is not appropriate for large meshes. It probably scans the mesh file line by line which makes the loading process lengthy for high quality meshes. Fortunately there’s a way to speed up things and I present it below. I will not cover the import of the data (other than meshes) since the function importdata from the FreeFem to Matlab tool is fast enough for this.

## IMC 2016 – Day 2 – Problem 8

Problem 8. Let ${n}$ be a positive integer and denote by ${\Bbb{Z}_n}$ the ring of integers modulo ${n}$. Suppose that there exists a function ${f:\Bbb{Z}_n \rightarrow \Bbb{Z}_n}$ satisfying the following three properties:

• (i) ${f(x) \neq x}$,
• (ii) ${x = f(f(x))}$,
• (iii) ${f(f(f(x+1)+1)+1) = x}$ for all ${x \in \Bbb{Z}_n}$.

Prove that ${n \equiv 2}$ modulo ${4}$.

## IMC 2016 – Day 2 – Problem 7

Problem 7. Today, Ivan the Confessor prefers continuous functions ${f:[0,1]\rightarrow \Bbb{R}}$ satisfying ${f(x)+f(y) \geq |x-y|}$ for all ${x,y \in [0,1]}$. Fin the minimum of ${\int_0^1 f}$ over all preferred functions.

## IMC 2016 – Day 2 – Problem 6

July 28, 2016 1 comment

Problem 6. Let ${(x_1,x_2,...)}$ be a sequence of positive real numbers satisfying ${\displaystyle \sum_{n=1}^\infty \frac{x_n}{2n-1}=1}$. Prove that

$\displaystyle \sum_{k=1}^\infty \sum_{n=1}^k \frac{x_n}{k^2} \leq 2.$

## IMC 2016 Problems – Day 2

Problem 6. Let ${(x_1,x_2,...)}$ be a sequence of positive real numbers satisfying ${\displaystyle \sum_{n=1}^\infty \frac{x_n}{2n-1}=1}$. Prove that

$\displaystyle \sum_{k=1}^\infty \sum_{n=1}^k \frac{x_n}{k^2} \leq 2.$

Problem 7. Today, Ivan the Confessor prefers continuous functions ${f:[0,1]\rightarrow \Bbb{R}}$ satisfying ${f(x)+f(y) \geq |x-y|}$ for all ${x,y \in [0,1]}$. Fin the minimum of ${\int_0^1 f}$ over all preferred functions.

Problem 8. Let ${n}$ be a positive integer and denote by ${\Bbb{Z}_n}$ the ring of integers modulo ${n}$. Suppose that there exists a function ${f:\Bbb{Z}_n \rightarrow \Bbb{Z}_n}$ satisfying the following three properties:

• (i) ${f(x) \neq x}$,
• (ii) ${f(f(x))=x}$,
• (iii) ${f(f(f(x+1)+1)+1) = x}$ for all ${x \in \Bbb{Z}_n}$.

Prove that ${n \equiv 2}$ modulo ${4}$.

Problem 9. Let ${k}$ be a positive integer. For each nonnegative integer ${n}$ let ${f(n)}$ be the number of solutions ${(x_1,...,x_k) \in \Bbb{Z}^k}$ of the inequality ${|x_1|+...+|x_k| \leq n}$. Prove that for every ${n \geq 1}$ we have ${f(n-1)f(n+1) \leq f(n)^2}$.

Problem 10. Let ${A}$ be a ${n \times n}$ complex matrix whose eigenvalues have absolute value at most ${1}$. Prove that

$\displaystyle \|A^n\| \leq \frac{n}{\ln 2} \|A\|^{n-1}.$

(Here ${\|B\| = \sup_{\|x\|\leq 1} \|Bx\|}$ for every ${n \times n}$ matrix ${B}$ and ${\|x\| = \sqrt{\sum_{i=1}^n |x_i|^2 }}$ for every complex vector ${x \in \Bbb{C}^n}$.)

Categories: Olympiad, Uncategorized Tags: , ,

## IMC 2016 – Day 1 – Problem 2

Problem 2. Let ${k}$ and ${n}$ be positive integers. A sequence ${(A_1,...,A_k)}$ of ${n\times n}$ matrices is preferred by Ivan the Confessor if ${A_i^2 \neq 0}$ for ${1\leq i \leq k}$, but ${A_iA_j = 0}$ for ${1\leq i,j \leq k}$ with ${i \neq j}$. Show that if ${k \leq n}$ in al preferred sequences and give an example of a preferred sequence with ${k=n}$ for each ${n}$.
Problem 3. Let ${n}$ be a positive integer. Also let ${a_1,a_2,...,a_n}$ and ${b_1,b_2,...,b_n}$ be reap numbers such that ${a_i+b_i >0}$ for ${i = 1,2,...,n}$. Prove that
$\displaystyle \sum_{i=1}^n \frac{a_ib_i -b_i^2}{a_i+b_i} \leq \frac{\sum_{i=1}^n a_i \cdot \sum_{i=1}^n b_i - \left(\sum_{i=1}^n b_i \right)^2 }{\sum_{i=1}^n (a_i+b_i)}.$