Effacer les filtres
Effacer les filtres

Simulating dynamics for an autonomous system

7 vues (au cours des 30 derniers jours)
Matthew Tortorella
Matthew Tortorella le 23 Sep 2021
Hello. I am looking to simulate the dynamics of an autonomous system represented by the following equations:
x1dot=-ax1+x2
x2dot=-bx2+u
udot=-cu
I need to simulate the dynamics for 100 random values of x1, x2, and u all for (t=0) and 100 random values of the constants a,b,c. After performing Lyapunov analysis with the given Lyapunov candidate function of V(zeta)=0.5x1^2+0.5x2^2+0.5u^2 where zeta is a function of x1,x2, and u, I identified constraints for a, b, and c to be:
a>0
b>1/a
c>1/2
I am knew to plotting differential equations but from what I have seen online I think I need to use the ode45 function. My code for x1dot is as follows:
function [x1dot] = f(x1,x2)
x1dot=-a*x1+x2;
end
[x1,x2]=ode45('f',[0,200],0);
plot(x1,x2)
If I assign a value to a, the code will run, but I am confused on how to assign 100 random variables to a while also constraining it to be greater than zero. I also am confused on how to assign 100 random values to x1, x2, and u and how to plot each of them versus time on their own plot with each of the 100 trajectories showing. I am pretty stuck on this issue so any help is much appreciated. Thanks.

Réponse acceptée

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 23 Sep 2021
There are a few different ways by which you can generate a, b, c. Here is one of the viable cases:
a = rand(1, 100); % [0, 1] uniform distributed decimal digit numbers
a = rand(1, 100)*100; % [0, 100] uniform distributed decimal digit numbers
a = randi([100,200],1, 100); % [100, 200] uniform distributed integers
...
Then you can employ a loop to simulate your simulation code, e.g.:
AS= randi([100, 200], 1, 100);
%%
for ii = 1:100
a = AS(ii);
tspan = [0 5];
OPT = odeset('reltol', 1e-5, 'abstol', 1e-8);
x0 = [0 0];
[t, y] = ode45(@(x1, x2) Fun(x1, x2, a), tspan, x0, OPT);
plot(t,y), hold all
end
function dx1 = Fun(a, x1,x2)
dx1=-a*x1+x2;
end
Note that your exercise as shown above is not complete and your fomulations need to be correctly coded and embedded as shown in the above example.
  2 commentaires
Matthew Tortorella
Matthew Tortorella le 26 Sep 2021
Thank you for the insight Sulaymon. Much appreciated.
Sulaymon Eshkabilov
Sulaymon Eshkabilov le 26 Sep 2021
Most Welcome!

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by