Issues with ode45
Mostrar comentarios más antiguos
I'm simulating the dynamics for an autonomous system and and the system is described as follows: x1dot=-ax1+x2, x2dot=-bx2+u, udot=-cu. My initial conditions for [x1 x2 u]=[0 0 0]. I am randomly generaring values of x1, x2, and u for 100 iterations and also randomly generating values for the constants a, b, and c. My code is pasted below. I keep getting the error "Not enough input arguments". I also would like to have x1(t), x2(t), and u(t) on three separate plots not one. If anyone has any suggestions it is much appreciated. Thanks.
low=1;
high=1000;
ASa=(high-low).*rand(100,1) + low;%column vector of uniformly distributed decimals between 1 and 1000 for constant a
ASb=(high-low).*rand(100,1) + low;%column vector of uniformly distributed decimals between 1 and 1000 for constant b
ASc=(high-low).*rand(100,1) + low;%column vector of uniformly distributed decimals between 1 and 1000 for constant c
ASx1=(high-low).*rand(100,1) + low;%column vector of uniformly distributed decimals between 1 and 1000 for variable x1
ASx2=(high-low).*rand(100,1) + low;%column vector of uniformly distributed decimals between 1 and 1000 for variable x2
ASu=(high-low).*rand(100,1) + low;%column vector of uniformly distributed decimals between 1 and 1000 for variable u
for ii = 1:100 %signifies 100 iterations for each variable x1,x2,u,a,b,c
a =ASa(ii);
b=ASb(ii);
b = max([b, 1/a]); % Make sure b > 1/a
c=ASc(ii);
c = max([c, 1/(2*b)]); % Make sure c is > 1/(2b)
x1=ASx1(ii);
x2=ASx2(ii);
u=ASu(ii);
tspan = [0 5];
options = odeset('reltol', 1e-5, 'abstol', 1e-8 );
x0 = [0 0 0];
[t, y] = ode45(@(x1,x2,u) dynamics(x1,x2,u,a,b,c), tspan, x0, options );
plot(t,y), hold on
end
title('Problem 1 System Dynamics')
xlabel('Time')
ylabel('Dynamic System')
hold off
function system = dynamics(x1,x2,u,a,b,c)
system=[-a*x1+x2;-b*x2+u;-c*u] ;
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Mathematics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

