# programming exercise 1.

$$\def\Real{\mathbb{R}} \def\Comp{\mathbb{C}} \def\Rat{\mathbb{Q}} \def\Field{\mathbb{F}} \def\Fun{\mathbf{Fun}} \def\e{\mathbf{e}} \def\f{\mathbf{f}} \def\bv{\mathbf{v}}$$

Use any language or library. The assignments are due by midnight of 3.14 (Monday).

#### 3 credits students

Consider the piecewise linear function $$f$$ on $$[-4,4]$$
with nodes at the integer points $$-4,-3,\ldots, 3, 4$$ (it means that the function is continuous and linear on each interval $$[k,k+1]$$, such that $$f(k)$$ is the $$(k+5)$$-th digit of your UIN.

Piecewise linear function (red) is approximated (not especially well) by a polynomial (blue).

Find the polynomial
$p=a_o+a_1x+\ldots+a_4x^4$
of degree $$4$$ minimizing the mean square error
$\int_{-4}^4 |p(x)-f(x)|^2 dx.$
Submit the solution in the following format:

• text file with the first line giving the coefficients of $$f$$,

[a_o a_1 a_2 a_3 a_4]

followed by

• the code and
• the execution output.
• Also attach a pdf  where $$f$$ and $$p$$ are plotted on $$[-4,4]$$ simultaneously.

#### 4 credits students

Consider the spring networks: a network of points, $$p_{ij}, i=0,\ldots,10, j=0,\ldots,10,$$, where two points $$p_{ij}$$ and $$p_{kl}$$ are connected by a spring if either $$i=k, |j-l|=1$$ (horizontal neighbors) or $$|i-k|=1, j=l$$ (vertical neighbors).

Rectangular network to embed.

A configuration is a 2D placement of the network nodes, that is an assignment of two coordinates,
$(x_{ij}, y_{ij})$
to each node $$p_{ij}$$.

$f=\frac12\left(\sum_{(i,j)\sim (k,l)}(x_{ij}-x_{kl})^2+(y_{ij}-y_{kl})^2\right),$
(the summation is over all neighboring pairs of nodes), subject to constraints
$x_{0,0}=0,y_{0,0}=0,x_{0,10}=0,y_{0,10}=10,x_{10,0}=10,y_{10,0}=0,x_{10,10}=10,y_{10,10}=10,$
and
$x_{5,5}=A_e, y_{5,5}=A_o,$
where $$A_e$$ is the sum of digits of your UIN at even places, and $$A_o$$ is the sum of digits of your UIN at odd places.

Submit the solution in the following format:

• text file with the coefficients $$x_{ij}$$:

x=[x(0,0) x(0,1) ... x(0,10); x(1,0) ... x(10,10)]

followed by coefficients $$y_{ij}$$:

y=[y(0,0) y(0,1) ... y(0,10); y(1,0) ... y(10,10)];

• the code and
• the execution output.