Your xinit_fcn is invoking interp1 with an x1_opt value derived from the t value that is passed into the function. However, bvpinit invokes the function with individual t values, not with the entire list of t values, so x1_opt will be a scalar. You are then trying to interp1(1 x 4452, 1 x 1, 1 x 1) . That fails because the second parameter must be the same length as the first parameter.
If you did have the entire original list of time values passed in, and were calculating x1_opt= -(pi/Tf)*All_t + pi and wanting to interpolate at the particular time, t, that was passed in to the xinit_fcn, then the result would always be the same as -(pi/Tf)*t + pi where t is the individual t. So it is not clear why you do not just have your xinit_fcn return -(pi/Tf)*t + pi .