Answer
See the graphs below.
Work Step by Step
a) We have 3 stages, the first stage is a straight line from $x=0$ m to $x=0.5$ m, the second stage is also a straight line but from $x=0.5$ m to $x=1$ m, and the third stage from $x=1$ where the force is zero from now on.
The equation of the first stage is given by
$$y=mx+b$$
where $m={\rm slope}=\dfrac{2-0}{0.5-0}=4$, $b=0$, and $y=F_x$.
Thus,
$$(F_x)_1=4x\tag 1$$
By the same approach, the equation of the second line is given by
$$(F_x)_2=-4x+4\tag 2$$
We know that
$$F_x=-\dfrac{dU}{dx}$$
Thus,
$$dU=-F_xdx\tag 3$$
Plugging from (1);
$$dU=-4xdx $$
$$\int_0^U dU=\int_0^{x}-4xdx$$
$$ U_1=-4\int_0^{0.5}xdx= -4\left[\dfrac{x^2}{2}\right]_0^{0.5}$$
$$ \color{blue}{U_1= -2x^2}\tag{$0\leq x\leq0.5$}$$
Hence, for the first stage, $U_i=0$ J and $U_f=-0.5$ J
By the same approach, plugging (2) into (3);
$$dU=-(-4x+4)dx $$
$$\int_0^U dU=\int (4x-4)dx$$
$$ U_2= \dfrac{4x^2}{2}-4x+C$$
Hence, for the second stage $U_i$ must equal to $U_i=-0.5$ J, as the final point of the first stage since it is a continues function. So that the constant had to be 1.
$$ \color{blue}{ U_2= 2x^2 -4x+1}\tag{$0.5\leq x\leq1$}$$
And since the force is zero after $x=1$, the potential remail constant since then.
$$ \color{blue}{ U_3= -1\;\rm J}\tag{$ x\gt1$}$$
---
b)
We know that the equation of the strightline os given by
$$y=mx+b$$
And in our case, $y=U$, $b=0$ [for the first stage], and $m$ is the slope which is equal to 4 in the first stage.
Thus, in the first stage from $x=0$ to $x=0.5$
$$U=4x$$
And we know that
$$F_x=-\dfrac{dU}{dx}$$
Thus,
$$F_x=-\dfrac{d }{dx}\left(4x\right)$$
Hence, for the first stage,
$$\color{blue}{(F_x)_1=-4\;\rm N}\tag{$0\leq x\leq0.5$}$$
In the second stage,
$$U=-4x+C$$
and since $U=2$ at $x=0.5$, so $C=4$.
Thus,
$$F_x=-\dfrac{d }{dx}\left(-4x+4\right)$$
$$\color{blue}{(F_x)_2= 4\;\rm N}\tag{$0.5\leq x\leq 1$}$$
And then the force after $x=1$ is zero since the potential became zero.
$$\color{blue}{(F_x)_3= 0\;\rm N}\tag{$ x \gt1$}$$