ODE45 must return column vector

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.

 Risposta accettata

Star Strider
Star Strider il 30 Nov 2020
Modificato: Star Strider il 30 Nov 2020
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.
.

Più risposte (1)

What are the values of alpha and beta you are using? Following code works without error
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];
alpha = 1;
beta = 2;
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')

1 Commento

Oh sorry about that alpha and beta are vectors. I edited my question to include them.

Accedi per commentare.

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by