MATLAB: ODE45 must return column vector

errorgraphhelpMATLABode45

I just have to solve using ode45 for every value of I and plot the solution but i cant quite figure it out.
I=[80,131,189,270,320,407,450,530,620,686,740,900,1095];
t2=[74,29,21,12,8,5.7,4.4,3.6,2.1,1.8,1.5,1.0,0.7];
a=.000104;
b=.000073;
p=1089;
R=0.000003;
n=0.001;
M=0.05;
u=4*pi*10^(-7);
x1=0.36;
alpha=-(p*M*R^2*u.*I)/(9*pi*n);
beta=-(x1*R^2*u.*I.^(2))/(18*pi.^(2)*n);
ode = @(t2,x,I) (1./(alpha.*x^(-2)+beta.*x^(-3)));
for k = 1:numel(I)
[t2,x(:,k)]=ode45(@(t,x) ode(t,x,I(k)),[0:.1:20],0.1);
end
figure
loglog(t2,x)
grid
xlim([0 1])
xlabel('t_1')
ylabel('x')
nstr = compose('I = %.2f',I);
legend(nstr, 'Location','NW')
Aything helps.

Best Answer

Try this:
I=[80,131,189,270,320,407,450,530,620,686,740,900,1095];
t2=[74,29,21,12,8,5.7,4.4,3.6,2.1,1.8,1.5,1.0,0.7];
a=.000104;
b=.000073;
p=1089;
R=0.000003;
n=0.001;
M=0.05;
u=4*pi*10^(-7);
x1=0.36;
alpha=@(k) -(p*M*R^2*u.*I(k))/(9*pi*n);
beta= @(k) -(x1*R^2*u.*I(k).^(2))/(18*pi.^(2)*n);
ode = @(t2,x,k) (1./(alpha(k).*x^(-2)+beta(k).*x^(-3)));
tv = logspace(-10, log10(20), 50);
for k = 1:numel(I)
[t2,x(:,k)]=ode45(@(t,x) ode(t,x,k),tv,0.1);
end
figure
loglog(t2,x)
grid
xlim([0 1])
xlabel('t_1')
ylabel('x')
nstr = compose('I = %5g',I);
legend(nstr, 'Location','eastoutside')
EDIT — (30 Nov 2020 at 21:02)
Changed time vector to ‘tv’, defining it with logspace.
.