solving odes that matrices should be update in every step.
Show older comments
Hi.I have a question that may be so elementary but so far I haven't found a solution. please if it is possible guide me.
i want to solve the 2nd order diffrential equation for vibration of 3DOF system.the equation is : [m]*{x"} + [C]*{x'} + [K]*{X} = -[M]*{r} d2g/dt2
that M is mass matrix . K , C are stiffness and damping matrices that should be update in every time step.also {r} = [ 0;0;1] and g" is the time-dependent external acceleration.(earthquake records).
for updating K and C matrices,i wrote a cod in matlab contains a for-loop that in every time step (=0.5 second) first update [K] and [C] matrices and then use ode45 to solve equation for time span=0.5 second.but i get suspicious result.for example ode45 output for every time span=0.5 second outputs a 61*1 vector but i think output should be a 6*1 vector like this : [x1; x'1; x2; x'2 ;x3;x'3]
can you tell me where is the problem? maybe i use ode45 in wrong method.
i attach my code to this question.
thank you for your help.
Answers (1)
darova
on 13 Jan 2020
I made some changes in your code. Pay attention to refreshing parameters:
function sdot = ODEFUN(t,x)
g1 = interp1(TIME,G,t);
ag1 = interp1(TIME,AG,t);
%% ...
end
Also i didn't refresh C and K matrices (don't know how)
See attached file
10 Comments
masoud azar
on 13 Jan 2020
darova
on 13 Jan 2020
What do they depend on? Do you have a condition/parameter?
masoud azar
on 14 Jan 2020
Edited: masoud azar
on 14 Jan 2020
Walter Roberson
on 14 Jan 2020
.the question is when i using ode45 how to update K and C matrices in every step?
Do not do that. Instead pass in a tspan that corresponds only to the next time interval, passing in "current" Cb and Kb values for that time interval. Take the output of ode45 as the new initial conditions and loop back for the next time interval with updated Cb and Kb values.
Any time you must "update parameters", that implies discontinuities, and ode45 cannot work with discontinuities within any one ode45() call. You need to stop the ode45 at the discontinuity and restart it again.
masoud azar
on 14 Jan 2020
darova
on 14 Jan 2020
Just place them in ode function
function sdot = ODEFUN(t,x)
Cb = f(x(1));
Kb = g(x(1))
C=[Cc,0,0;0,Ci,0;0,0,Cb];
K=[Kc,0,0;0,Ki,0;0,0,Kb];
g1 = interp1(TIME,G,t);
% ag1 = interp1(TIME,AG,t);
% F=[mc;mi;mc+mi+mb]*-ag1;
sdot = zeros(6,1);
sdot(1:3) = x(4:6); % dx/dt (velocity)
sdot(4:6) = -[0;0;1]*g1 - M1*C*x(4:6) - M1*K*x(1:3); % dx2/dt2 (acc)
end
Walter Roberson
on 15 Jan 2020
Just place them in ode function
No!! interp1 defaults to linear interpolation between the points on either side of the probe point. The result is something that is piecewise continuous but whose first derivative holds constant between breakpoints but is discontinuous at each breakpoint. That is not acceptable for ode45 purposes. ode45 uses the tension between quartic (degree 4) interpolation and quintic (degree 5) interpolation to adjust step sizes. quartic and quintic interpolation are not valid for any segment in which the function has discontinuities in the first derivative (or second derivative.)
Therefore, at any place in which a discontinuity is to be expected or can be detected to have occurred, you must stop the ode45() and restart it. Failure to do so is violating the mathematical conditions under which ode45() can be expected to produce a valid answer.
When you using interp1() like that, or you using if inside the calculations, ode45 might or might not notice a problem and complain, but if it does not complain then that does not mean that it produced the right answer.
Walter Roberson
on 15 Jan 2020
I recommend having a good look at the ballode example. It shows using loops that eventually cover the entire time span, using event functions to detect when a discontinuinity has occurred and stopping the run and restarting it.
masoud azar
on 18 Jan 2020
darova
on 18 Jan 2020
I will be here, waiting
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!