MATLAB: Error using odearguments (line 93) BANANA must return a column vector.

MATLABode45

I have tried R1 = zeros(size(R1)) and R1 = zeros(R1), but it wont work. I am lost on why I keep getting Error using odearguments (line 93) BANANA must return a column vector. Thank you so much for the help!
Here is my function
function dtdz = banana(z,t)
%given conditions:
n = 1.23;
zi = 145*(10^-3);
z0 = 8.45;
u0 = 23*pi;
B0 = 0.0054;
h = 0.00734;
g = 10;
xs = 0;
xm = 0.00004386;
ps = 1937;
pm = 1.0995e+03;
c = 0.375;
T = 36;
%assume:
R1 = [10:400];
R = R1.*10^-6;
%initial conditions:
alpha = (8/9).*(((xs-xm).*B0.*R.^2)./(u0.*h.^2.*n));
beta = ((2.*R.^2)./(9.*n)).*(((ps-pm).*g-(2/h).*(((xs-xm).*B0.^2)/u0)));
dtdz = (1./(alpha.*z+beta));
end
Here is my script
t_zi = 0;
zspan = [1*(10^-3) 0.0205];
[z,t] = ode45(@banana, zspan, t_zi);
plot(z,t);
hold off
title('Radius of banana vs Time')
xlabel('Radius of banana (µm)')
ylabel('t0 (min)')

Best Answer

You make a vector of R1 with size 1x391 in the BANANA function. Thus you have a vector of 1x391 as result - one entry for every element of R1. Since you only provide only one initial time this leads to an error. To solve for many R1 the same time use an initial vector which provides as many elements as R1 has and transpose the result in BANANA:
t_zi = zeros(391,1);
zspan = [1*(10^-3) 0.0205];
[z,t] = ode45(@banana, zspan, t_zi);
plot(z,t);
hold off
title('Radius of banana vs Time')
xlabel('Radius of banana (µm)')
ylabel('t0 (min)')
function dtdz = banana(z,~)
%given conditions:
n = 1.23;
zi = 145*(10^-3);
z0 = 8.45;
u0 = 23*pi;
B0 = 0.0054;
h = 0.00734;
g = 10;
xs = 0;
xm = 0.00004386;
ps = 1937;
pm = 1.0995e+03;
c = 0.375;
T = 36;
%assume:
R1 = 10:400;
R = R1.*10^-6;
%initial conditions:
alpha = (8/9).*(((xs-xm).*B0.*R.^2)./(u0.*h.^2.*n));
beta = ((2.*R.^2)./(9.*n)).*(((ps-pm).*g-(2/h).*(((xs-xm).*B0.^2)/u0)));
dtdz = (1./(alpha.*z+beta))';
end