필터 지우기
필터 지우기

Solving Differential Equations With

조회 수: 13 (최근 30일)
Igor Braz Gonzaga
Igor Braz Gonzaga 2022년 3월 14일
댓글: Walter Roberson 2022년 3월 18일
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
Torsten
Torsten 2022년 3월 14일
What is the time vector corresponding to Ft ?

댓글을 달려면 로그인하십시오.

채택된 답변

Sam Chak
Sam Chak 2022년 3월 18일
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
Torsten
Torsten 2022년 3월 18일
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
Sam Chak 2022년 3월 18일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Torsten
Torsten 2022년 3월 14일
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
Igor Braz Gonzaga
Igor Braz Gonzaga 2022년 3월 15일
Hi Torsten, In this case, for a random force (discrete in time), is there any command in Matlab to solve this ODE?
Walter Roberson
Walter Roberson 2022년 3월 15일
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
Sam Chak 2022년 3월 15일
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
Torsten
Torsten 2022년 3월 16일
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
Walter Roberson 2022년 3월 16일
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
Igor Braz Gonzaga 2022년 3월 18일
Hi @Sam Chak, thanks a lot!! It works!!
Yes, My ideia is do a loop with a series of simulations (Monte Carlo) to attain the responses of the structure under stochastic load.
But I have another question, more simple, I guess.
If I want the acceleration of the structure, what should I do?
I try to derive y(:,2) vector, using the following code:
acel=diff(y(:,2));
t_acel=(tt(2:end)+tt(1:(end-1)))/2;
plot(t_acel,acel)
but the graph do not correspond with the expected values , that is, analytical solution (I try to use a more simple example, with a deterministic input load).
The graphs of y(:,2) (velocity of the structure) and y(:,1) (displacement of the structure) works well, but the acceleration does not.
Thanks
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 3월 18일
acel=diff(y(:,2));
That assumes that the items are all the same time apart.
You should use gradient(y(:,2), tt)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by