Write a user-defined function named Deflection_cougarnetID.m
You have not done that. You have not created a function.
which has one input (position x)
You have written a script, not a function. Scripts cannot accept any input parameters.
and one output, (deflection v)
You have written a script, not a function. Scripts cannot return any values.
Within your user-defined function, create a vector of values for deflection from 0 to the position entered by the user.
You assigned
y=0:x;
which is confusing because they talk about y being the deflection, but your y is position. Furthermore, you never use your y in the calculation: the v you calculate is only at the single input position, x. You should be calculating the deflection at every value 0:x not just at x.
Remember for this purpose that the equation is piecewise, so it is a mistake to be doing the assignment y=0:x within one individual piecewise branch.
You should probably be using a for loop, something like
xinput = ...
allx = 0 : xinput;
for xidx = 1 : length(allx)
x = allx(xidx);
if (0<x)&&(x<=120)
v = formula in x
elseif (120<x)&&(x<=240)
v = second formula
end
allv(xidx) = v;
end
plot(allx, allv)