Solve a system of Differential Equations with a piecewise function
Show older comments
I'm trying to solve a system of 2 differential equations (with second, first and zero order derivatives)


in which there is a piecewise function



This problem comes from the analysis of a vibrating system.
The unknowns of the system and the piecewise function are functions of time.
The unknowns are: 1. beta=beta(t) ; 2. x=x(t)
beta and x with one dot at the top are first order derivatives (respect to time).
beta and x with two dots at the top are second order derivatives (respect to time).

I have to obtain a plot for each of the two unknows and their second and first order derivatives (respect to time).
To solve the problem, I've tried every system: ODE (returned error), dsolve (impossible to find solution), ecc. … without results.
The only way I think it can solve the problem is to separate the various components of the piecewise function and use dsolve to obtain distinct solutions. Unfortunately, in this way code runs for at least 12 hours to plot data.
There is a better way to solve my problem?
6 Comments
Torsten
on 15 May 2018
Please show the code where you used a numeric solver together with the error message you obtained.
Francesco Tegazzini
on 15 May 2018
Torsten
on 15 May 2018
Remove the "syms t" and "alpha = piecewise..." lines in your code.
Instead, use
if t <= T1
alpha = ...;
else if (t > t1) && (t <= T2)
alpha = ...;
...
endif
Best wishes
Torsten.
Francesco Tegazzini
on 16 May 2018
Torsten
on 17 May 2018
if (t>=0)&&(t<=T1)
alpha=alphamax*(10*(t/T1)^3-15*(t/T1)^4+6*(t/T1)^5);
Dalpha=alphamax*(10*3*(t/T1)^2/T1-15*4*(t/T1)^3/T1+6*5*(t/T1)^4/T1;
D2alpha=alphamax*(10*3*2*(t/T1)/T1/T1-15*4*3*(t/T1)^2/T1/T1+6*5*4*(T/T1)^3/T1/T1;
elseif (t>T1)&&(t<=T2)
alpha=alphamax;
Dalpha=0.0;
D2alpha=0.0;
elseif (t>T2)&&(t<=T3)
alpha=alphamax*(10*((T3-t)/T1)^3-15*((T3-t)/T1)^4+6*((T3-t)/T1)^5);
Dalpha=alphamax*(10*3*((T3-t)/T1)^2*(-1/T1)-15*4*((T3-t)/T1)^3*(-1/T1)+6*5*((T3-t)/T1)^4*(-1/T1));
D2alpha=alphamax*(10*3*2*((T3-t)/T1)*(-1/T1)*(-1/T1)-15*4*3*((T3-t)/T1)^2*(-1/T1)*(-1/T1)+6*5*4*((T3-t)/T1)^3*(-1/T1)*(-1/T1));
elseif (t>T3)&&(t<=T4)
alpha=0;
Dalpha=0.0;
D2alpha=0.0;
end
Best wishes
Torsten.
Francesco Tegazzini
on 17 May 2018
Edited: Francesco Tegazzini
on 17 May 2018
Accepted Answer
More Answers (1)
Walter Roberson
on 17 May 2018
2 votes
None of the ode* routines can handle piecewise expressions. All of them require that the calculation in any one ode* call is continuous and that the first two derivatives of everything you programmed is also continuous (numeric estimates of them are created.) If the first derivative is not continuous then often a message about integration tolerance is shownń if it is the second derivatives that are not then it will typically just produce an incorrect solution.
You need to recode so that every time that your piecewise would switch branches, that you fire an event function set to terminal. Then call ode* again for the remainder of the tspan, using the last output of the previous run as the initial condition of the next. Keep doing this until the full tspan is processed.
There was a case about 2 weeks ago where the event function was firing every 3 to 7 calls. I posted example code there showing how to run the ode.
1 Comment
Francesco Tegazzini
on 17 May 2018
Categories
Find more on Numerical Integration and 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!
