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

2 次查看(过去 30 天)
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)')

采纳的回答

Stephan
Stephan 2020-11-27
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by