I would like to have an analytic formula for certain functions that I can draw with a pen. For example, if I want a function like that
then I can model it with the function $$ V(x) = (x-a)^2 (x-b)^2.$$ In this way I can model multiple minima on the same height. But how can I model a potential with multiple minima with different height and some high barriers, like this:

EDIT
I tried the method from mathreadler trying to construct a polynomial that looks like this:
which is specified on nine points $x_1 = -2.7 ,\dots ,x_9 = 2$. I am looking for a polynom that satisfies $p(x_i) = a_i$ where $a_i$ can be found in the picture and $p'(x_i) = 0$. Also, according to the wish that $x_i$ is minimum or maximum I have conditions on $p''(x_i)$. These are 27 conditions, so that I have to find a polynom of degree 26 that fulfills these conditions. I wrote a short matlab code to construct the polynom as follows:
function findNicePoly()
h1=@(x)([x^26, x^25 , x^24 , x^23, x^22 , x^21 , x^20 ,x^19 ,x^18 ,x^17 ,x^16 ,x^15 , x^14 , x^13, x^12 ,x^11, x^10, x^9 ,x^8 , x^7 ,x^6 ,x^5 , x^4 ,x^3, x^2 ,x^1 , 1 ]);
h2=@(x)([26*x^25, 25*x^24 , 24*x^23 , 23*x^22, 22*x^21 , 21*x^20 , 20*x^19 ,19*x^18 ,18*x^17 ,17*x^16 ,16*x^15 ,15*x^14 , 14*x^13 , 13*x^12, 12*x^11 ,11*x^10, 10*x^9, 9*x^8 ,8*x^7 , 7*x^6 ,6*x^5 ,5*x^4 , 4*x^3 ,3*x^2, 2*x^1 ,1 , 0 ]);
h3=@(x)([25*26*x^24, 24*25*x^23 , 23*24*x^22 , 22*23*x^21, 21*22*x^20 , 20*21*x^19 , 19*20*x^18 ,18*19*x^17 ,17*18*x^16 ,16*17*x^15 ,15*16*x^14 ,14*15*x^13 , 13*14*x^12 , 12*13*x^11, 11*12*x^10 ,10*11*x^9, 9*10*x^8, 8*9*x^7 ,7*8*x^6 , 6*7*x^5 ,5*6*x^4 ,4*5*x^3 ,3*4*x^2 ,2*3*x^1, 2 ,0 , 0 ]);
M = zeros(27,27);
M(1,:)=h1(-2.7);
M(2,:)=h1(-2.5);
M(3,:)=h1(-2);
M(4,:)=h1(-1.5);
M(5,:)=h1(-1);
M(6,:)=h1(-0.5);
M(7,:)=h1(-0.3);
M(8,:)=h1(1);
M(9,:)=h1(2);
M(10,:)=h2(-2.7);
M(11,:)=h2(-2.5);
M(12,:)=h2(-2);
M(13,:)=h2(-1.5);
M(14,:)=h2(-1);
M(15,:)=h2(-0.5);
M(16,:)=h2(-0.3);
M(17,:)=h2(1);
M(18,:)=h2(2);
M(19,:)=h3(-2.7);
M(20,:)=h3(-2.5);
M(21,:)=h3(-2);
M(22,:)=h3(-1.5);
M(23,:)=h3(-1);
M(24,:)=h3(-0.5);
M(25,:)=h3(-0.3);
M(26,:)=h3(1);
M(27,:)=h3(2);
b=[1, 4, 2,3,2,3,1,8,1, 0,0,0,0,0,0,0,0,0, 1,-1,2,-2,2,-2,20,-50,10]'
a=M\b;
a
x=[-3:0.01:3];
y=polyval(a,x);
plot(x,y)
but the ploted polynom does not look as I wished for.

Is there a better method, or am I doing something completely wrong?


You can set that the first derivative should be $0$ at the points you are interested in. This gives one linear equation in the coefficients of the polynomial for each point.
For example third order polynomial $p(x)$ should have extremum at point $x_0$: $$p(x) = ax^3+bx^2+cx+d$$
$$p'(x_0) = 3a(x_0)^2+2bx_0 + c = 0$$
This equation is linear in a,b, and c. So if you gather enough constraints you can just build a large enough equation system and it will work.
Edit: you may want to ensure that you actually get a minima, you can do that by encouraging the values of the second derivative to be lower or higher than 0. But this can also be done with the same kind of approach: set $p''(x_0) = \pm \epsilon_0$ with the sign depending on maximum or minimum. Since derivative is linear with respect to the coefficients this will fit nicely into the linear equation system.
Another edit Let us define C to be the matrix $\bf C = \left[x^0,x^1,\cdots,x^n\right]$, $\bf x$ being the column vector of x:s for extrema. This way if we have a polynomial with coefficients into a vector $\bf v$ the values of $p(x_k) = ({\bf Cv})_k$
Now if we minimize $$O({\bf v}) = \|{\bf Wv}\|_2^2+ \|{\bf CDv}\|_2^2 + \|{\bf CD^2v} - {\bf e}\|_2^2$$ the first term is a regularization term with diagonal weight matrix $\bf W$ which pushes coefficients towards 0. Second term pushes the derivatives towards 0. Third term pushes second derivatives towards a vector $\bf e$ where each element is $\pm \epsilon$ with the sign depending on maxima or minima. We can also add a fourth term $\|{\bf Cv} - {\bf d} \|_2^2$, where $\bf d$ is a vector of values such that $p(x_k) = {\bf d}_k$ is encouraged (which you asked in the comment).
Just to show that it works. Here we want minima at 1,3,5 and maxima at 2,4. We don't put any constraints on the function values ( although we could do that if we want to ).