Your use of the if elseif to determine what the appropriate function to evaluate is good, but you have a conceptual error on what you are looping through.
Basically you need to first define a vector xdim of the values of the dimensionless distance you are interested in.Then you should loop through each element of this vector, determine the range it is in, and the corresponding function for calculating the velocity, u, and then calculate it.
Finally once you have all of the u values calculated you plot u vs xdim.
So something like this:
f1 =
f2 =
Uu =
Uc =
n1 =
n2 =
xdimMin =
xdimMax =
numPoints =
xdim = linspace(xdimMin,xdimMax,numPoints)
u = zeros(numPoints,1)
for idx = 1:numPoints
if xdim(idx) <= -n1 - n2/2
u(idx) = Uu
elseif xdim(idx)< -n1 + n2/2
u(idx) = f2*(xdim + n1 + n2/2)^2 + Uu
elseif xdim(idx)<= 0
u(idx) = f1*xdim + Uc
elseif xdim(idx) <= n1 - n2/2
u(idx) = -f1*xdim + Uc
elseif xdim(idx) < n1 + n2/2
u(idx) = f2*(xdim-n1-n2/2)^2 + Uu
elseif xdim(idx)>= n1 + n2/2
u(idx) = Uu
end
end
plot(xdim,u)
xlabel('dimensionless position xdim')
ylabel('dimensionless velocity u')
Alternatively you could just have a line of code for each range of xdim and assign all of the u values for the x's in each range and then plot so something like
xdim = linspace(xdimMin,xdimMax,numPoints);
u = zeros(numPoints,1);
u(xdim <= -n1 - n2/2) = Uu;
u(-n1 - n2/2 < xdim & xdim< -n1 - n2/2) = f2*(xdim + n1 + n2/2)^2 + Uu;
u( -n1 + n2/2 <= xdim & xdim <= 0) = f1*xdim + Uc;
u( 0 <= xdim & xdim<= n1 - n2/2) = -f1*xdim + Uc;
u(n1 - n2/2 < xdim & xdim < n1-n2/2) = f2*(xdim-n1-n2/2)^2 + Uu;
u(xdim >= n1 + n2/2) = Uu;
plot(xdim,u)
xlabel('dimensionless position xdim')
ylabel('dimensionless velocity u')
p.s. Better check the ranges I have carefully to make sure there aren't some typos in there