Solving Differential Equations With
23 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Igor Braz Gonzaga
el 14 de Mzo. de 2022
Comentada: Walter Roberson
el 18 de Mzo. de 2022
Hi, I'm new in Matlab and I have a problem with ODE45 comand.
Basically, I'm trying to solve the second order differential equation of a spring (ke) -mass (me) -damper (ce) system. With [0; 0] initial conditions. It follows the code:
[t,x] = ode45(@SMD,[0 Tmax],[0; 0]);
plot(t,x(:,1))
SMD is defined in a function as:
function dxdt = SMD(t,x,me,ce,ke,Ft)
fe=2;
Qsie=0.05;
me=32000;
ce=2*Qsie*(2*pi*fe)*me;
ke=me*(2*pi*fe)^2;
dxdt = [x(2); (-ce*x(2)-ke*x(1)+Ft)/me];
But Ft is a force vector (varying on time) calculated previously. How can I import this vector to dxdt function?
Is there any restriction in relation to the Length of vector Ft? I asked this question because I dont know the time increment of the integration when I use ODE45. The vectors of the analysis may be different Lengths (Ft and x).
Other question: there is a form of the variables me, ce and ke be imported from the main program? When I try compile the code without indicate the values of them in the function dxdt, an error was reported.
Thanks very much!
1 comentario
Respuesta aceptada
Sam Chak
el 18 de Mzo. de 2022
I add a new answer because the pieces of new info were scattered here and there. You should have edited the original post and included the new info about the stochastic load. Anyhow, I've added the interpolation (as initially suggested by @Torsten and @Walter Roberson) in the odefcn to get the stochastically continuous load.
function dydt = odefcn(t, y, tF, Fft)
dydt = zeros(2,1);
fe = 2;
Omega = 2*pi*fe; % undamped natural frequency
Qsie = 0.05; % damping ratio
me = 32000; % “generalized mass” coefficient
ce = 2*Qsie*(Omega)*me; % damping coefficient
ke = me*(Omega)^2; % stiffness coefficient
A = [0 1; -ke/me -ce/me]; % state matrix from ODE
B = [0; 1/me]; % input matrix from ODE
p = [-1+1i -1-1i]; % eigenvalues from desired x" + 2*x' + 2*x = 0
K = place(A, B, p); % control gains
Ft1 = - K(1)*y(1) - K(2)*y(2); % Case #1: control force
Ft2 = 0; % Case #2: no force (free response)
Ft3 = me*cos(Omega*t); % Case #3: disturbing sinusoidal force
Ft4 = interp1(tF, Fft, t); % Interpolate the stochastic data set
dydt(1) = y(2);
dydt(2) = (- ce*y(2) - ke*y(1) + Ft4)/me;
end
The stochastic load is generated from the teste_exluir m-file, but some variables are undefined. So, I have assigned some values to the number of pedestrians, Nped and L (because you never specify what it is), and renamed the time and force variables to tF and Fft, respectively. Rest assured that the stochastic load formula remains unchanged. I have added a few lines at the end of the script and ran for 3 tests. Please review if the results are expected or acceptable for your study.
Fft = Ft(:,1); % Force induced by the walking pedestrians
figure(1)
plot(tF, Fft)
tspan = [0 10];
y0 = [0 0];
[t, y] = ode45(@(t, y) odefcn(t, y, tF, Fft), tspan, y0);
figure(2)
plot(t, y)
Results:
3 comentarios
Torsten
el 18 de Mzo. de 2022
Further, assuming the integration scheme could handle such discontinuous inputs (which it can't), this is one possible realization of your stochastic process for Ft. The next realization will yield a different response. So you would have to run your equations thousands of times to get the distribution (not the values) of your unknowns y(1) and y(2).
That's where stochastic differential equations and the associated methods come into play.
Sam Chak
el 18 de Mzo. de 2022
Yes, @Igor Braz Gonzaga literally has to manually run the stochastic differential equations (SDE) many times with this approach, if he wants to perform the Monte Carlo Simulation. Unfortunately, I don't have the Financial Toolbox to perform SDE. I have checked the pricing here, if he wishes to get the license.
By the way, is there a workaround for this problem that @Walter Roberson and @Torsten can suggest to him so that he can automate the simulations and storing the data for a range of values for Nped and L in the teste_exluir script using the Standard MATLAB? Thank you for considering this request.
Más respuestas (3)
Torsten
el 14 de Mzo. de 2022
fe=2;
Qsie=0.05;
me=32000;
ce=2*Qsie*(2*pi*fe)*me;
ke=me*(2*pi*fe)^2;
[t,x] = ode45(@(t,x)SMD(t,x,me,ce,ke,tt,Ft),[0 Tmax],[0; 0]);
function dxdt = SMD(t,x,me,ce,ke,tt,ft)
Ft = interp1(tt,ft,t);
dxdt = [x(2); (-ce*x(2)-ke*x(1)+Ft)/me];
end
where tt is the time vector corresponding to Ft.
8 comentarios
Walter Roberson
el 15 de Mzo. de 2022
None of the ode*() functions support discontinuities in the equations such as might be due to random forces or impulses.
The Finance toolbox has some support for Stochastic Differential Equations; https://www.mathworks.com/help/finance/stochastic-differential-equation-sde-models.html
For the ode*() routines, you would need to stop integrating at every point that randomness occurs, and resume integrating again.
Sam Chak
el 15 de Mzo. de 2022
If this is an exercise in the Mechanics class, usually will be given. Anyhow, there are generally 3 cases for the force vector, :
- Case 1: feedback control force;
- Case 2: no force input (free response);
- Case 3: external disturbing force (can be a sinusoidal signal or a constant force).
You can investigate the system response by selecting the type of force (Ft1, Ft2, or Ft3) on the “dydt(2)” line.
function dydt = odefcn(t, y)
dydt = zeros(2,1);
fe = 2;
Omega = 2*pi*fe; % undamped natural frequency
Qsie = 0.05; % damping ratio
me = 32000; % mass coefficient
ce = 2*Qsie*(Omega)*me; % damping coefficient
ke = me*(Omega)^2; % stiffness coefficient
A = [0 1; -ke/me -ce/me]; % state matrix derived from ODE (for Case #1 only)
B = [0; 1/me]; % input matrix derived from ODE (for Case #1 only)
p = [-1+1i -1-1i]; % eigenvalues from desired x" + 2*x' + 2*x = 0 (for Case #1 only)
K = place(A, B, p); % control gains (for Case #1 only)
Ft1 = - K(1)*y(1) - K(2)*y(2); % Case #1: control force
Ft2 = 0; % Case #2: no force (free response)
Ft3 = me*cos(Omega*t); % Case #3: disturbing sinusoidal force
dydt(1) = y(2);
dydt(2) = (- ce*y(2) - ke*y(1) + Ft1)/me;
end
You can also set the simulation time, tspan, and the initial condition, y0, depending on your original problem. (, ) is the equilibrium point for Cases #1 & #2. If this is a control project, you will need to determine the eigenvalues (a.k.a poles) from the desired system response and then the control gains can be designed using the pole placement technique.
tspan = linspace(0, 20, 2001)';
y0 = [0.1; 0];
[t, y] = ode45(@(t, y) odefcn(t, y), tspan, y0);
plot(t, y)
Results:
13 comentarios
Torsten
el 16 de Mzo. de 2022
As pointed out several times, you cannot feed the differential equation with stochastic input.
So either you accept a way to smoothen the Ft curves or we should quit discussion here.
Walter Roberson
el 16 de Mzo. de 2022
As I posted earlier,
The Finance toolbox has some support for Stochastic Differential Equations; https://www.mathworks.com/help/finance/stochastic-differential-equation-sde-models.html
If you do not use that, then you need to stop integration each time you have a new random event.
Igor Braz Gonzaga
el 18 de Mzo. de 2022
1 comentario
Walter Roberson
el 18 de Mzo. de 2022
acel=diff(y(:,2));
That assumes that the items are all the same time apart.
You should use gradient(y(:,2), tt)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!