1
$\begingroup$

I am attempting to model the following SDOF system with a variable spring and having a sinusoidal input, $$m\ddot{x}+(k_0+k_1)x = m(2\pi f)^2\sin(2\pi ft)$$ where $m$ is the mass, $k_0$ the original spring and $k_1 = k_0$ for $x\dot{x}>0$ and $k_1 = 0$ otherwise.

I was able to code this in Matlab, but for low frequencies, say $f=0.05$, a chattering effect would happen in the plot of $x\dot{x}$ vs. $t$. The following is my code and plots of the result for low frequencies.

f = 0.05;
t_f = 10;
tspan = [0 t_f];
z0 = [0 ; 0];

options = odeset( 'RelTol', 1e-13, 'AbsTol', 1e-13, 'Stats','on' );


[t, z] = ode23s(@(t,z) sys_13(t, z, f), tspan, z0, options);

figure(1)
set(gcf,'units','normalized','outerposition',[0 0 1 1])

subplot(2,1,1);
plot(t,z(:,1),'b');
title(['Time history of $y(t)\,\,(\ddot{u}_{gx}=-(2\pi f)^2\sin(2\pi f t)) \,\, f=\, $' num2str(f) ' $ $'],'interpreter','latex','fontsize',20)
ylabel('$y$','interpreter','latex','fontsize',15)
xlabel('$t$','interpreter','latex','fontsize',15)
xlim(tspan)

grid on
hold on

subplot(2,1,2);
plot(t,z(:,2),'b')
ylabel('$\dot{y}$','interpreter','latex','fontsize',15)
xlabel('$t$','interpreter','latex','fontsize',15)
xlim(tspan)

grid on
hold on

figure(2)
plot(t,z(:,1).*z(:,2),'b')

grid on
grid minor
hold on

base_stiffness = 4;
scale = 1e-5;
k0 = base_stiffness*ones(size(z(:,1),1),1)*scale;
k1 = zeros(size(z(:,1),1),1);

for ii = 1:size(z(:,1),1)
    k1(ii) = ( 1./(1 + exp( -(z(ii,1)*z(ii,2))/(1e-14) )) )*base_stiffness*scale;
end

plot(t, k1)

function dz = sys_13(t, z , f)
dz = zeros(2,1);

m = 1;
k0 = 4;
% tol = 1e-6;
% if abs(z(1)*z(2)) > tol && z(1)*z(2) > 0
%     k1 = 4;
% else
%     k1 = 0;
% end

% if z(1)*z(2) > 0
%     k1 = 4;
% else
%     k1 = 0;
% end

k1 = ( 1/(1 + exp( -(z(1)*z(2))/(1e-14) )) );
finput = ( -(2*pi*f)^2 )*sin( 2*pi*f*t );

dz(1) = z(2);
dz(2) = - finput - ((k0 + k1)/m)*z(1);
end

The plot of the time history of the position and velocity are enter image description here

The plot of $x\dot{x}$ vs. $t$ is enter image description here

If I zoom in close to where the plot is zero I see the following behavior enter image description here

The plots with reduced absolute error and relative error tolerances set to 1e-9 are

Time History plot: enter image description here

The $x\dot{x}$ plot: enter image description here

Zoomed in $x\dot{x}$ plot: enter image description here

I also tried applying a tolerance so to avoid the constantly switching on and off and instead the chattering occurs about the tolerance I set.

Now, I'm not sure what is causing these issues, but my best guess would be that the discontinuity in the state-space matrix $$ A=\begin{bmatrix}0&&1\\-\frac{k_0+k_1}{m}&&0\end{bmatrix}$$ when $k_1$ switches from $0$ to $k_0$ or vice versa is causing some sort of numerical errors in the solver. I was thinking about using an event location to find when $x\dot{x}$ passes through zero and start/stop the solver to avoid the discontinuity.

Thank you for any help or advice!

EDIT: Using the advice from LutzL I was able to remove the chattering, yet the way the additional stiffness $k_1$ is added to the system is gradual, whereas it should be more step like.

The $x\dot{x}$ plot with the additional stiffness value is:

enter image description here

  • 0
    Could you test how the last graph looks if you reduce the error tolerances (esp. the relative error) from their defaults `1e-6` to `1e-9` or `1e-12`?2017-01-18
  • 0
    Sure. I'll run the simulations now. I'll use 1e-9 for both the relative tolerance and absolute tolerance.2017-01-18
  • 0
    @Lutzl What are you hoping to see happen to the graphs as the error tolerance gets smaller?2017-01-18
  • 0
    That the automatic step size is adjusted even more towards zero, perhaps even producing matlab errors that the time update is stalling because `dt/t` is too small. As long as that does not happen, the oscillation should be proportionally smaller, above it is about `1e-8` for tolerance `1e-6`, with tolerance `1e-9` it should have amplitude of about `1e-11`.2017-01-18
  • 0
    At the zeros of $x$, the term $k_1(x\dot x)·x$ is still continuous but has a kink, which is no problem for the existence of a solution but for any numerical solver that expects smoothness for a working error estimator. At the zero crossings of $\dot x$, extrema of $x(t)$, I would expect more problems but that seems not the case in the graph.2017-01-18
  • 0
    I updated my question to include the graphs with lower tolerances. It still seems to chatter, but at a much smaller scale. Is the chattering possibly due to modeling the problem incorrectly? If not, is there a way to go around the discontinuity by stopping the solver? I was thinking of stopping the solver using the event location approach, similar to the ballode.m example, but input a new state matrix into ode23s.2017-01-18
  • 0
    Yes, you can use events to stop the solver at specific points. Or use a sigmoid function like $s(u)=0.5·(1+u/(1+|u|))$ (or using the logistic function, arcus tangent,...) and make the jump in `k1` smooth by using $s(x\dot x/\epsilon)$ as factor with a small but not too small $\epsilon$.2017-01-18
  • 0
    Okay. I will try your suggestions. Just so I understand this correctly, you're saying to smoothly vary the jump instead of doing so by an actual step function, like the signum function?2017-01-18
  • 0
    Yes. That promotes the system from "discontinuous" to "stiff". On second thought, using the absolute value is also not very smooth. Use the logistic sigmoid $s(u)=1/(1+e^{-u})$.2017-01-18
  • 0
    @Lutzl I went ahead and updated my question with the advice you gave above. Using the logistic sigmoid has eliminated the chattering, yet what happens now is that in the area where chattering was occuring, the additional stiffness being added either decreases or increases gradually and not suddenly like a step function. I updated my question with the graph of $x\dot{x}$ and the additional stiffness $k_1$ as it changes. Is there anyway to set a tolerance on $x\dot{x}$ (without introducing chattering) to have $k_1$ set to zero?2017-01-22
  • 0
    You can only make the ramp steeper by decreasing $ϵ$. You could also experiment using $s(x\dot x/(|x|+|\dot x|)/ϵ)$ to not be too flat around zero. However, having as in the original a jump in the equation leads to the behavior as described in the answer where there is no classical solution when this type of jump is encountered.2017-01-22
  • 0
    With your original suggestion, I've already taken $\epsilon=1e-14$. I will experiment with $s(x\dot{x}/(|x|+|\dot{x}|)/\epsilon)$ to see where I get. Thank you for your help.2017-01-22
  • 0
    @LutzL I played around with your last suggestion and it doesn't really help fix the problem. What I did notice is that at higher frequencies, say $f=3$, the suggestions you made work (in addition to my original approach using the signum function). The plot of the $k_1$ also looks step like. If the solution does not exist for some choices of $f$, does that mean the plots produced for those frequencies have no physical meaning?2017-01-23
  • 0
    As far as I can tell this has nothing whatsoever to do with [tag:coding-theory]. Please read the tag descriptions before using a tag you are not familiar with.2017-01-23
  • 0
    My mistake. When I read error-correcting codes, I misinterpreted as fixing error in code. I'll make sure to be more thorough next time I use a new tag.2017-01-23

1 Answers 1

3

The "chattering" may not just be a numerical artefact: it may be telling you that the solution ceases to exist. Note that the Existence and Uniqueness Theorem just guarantees existence of a solution when the functions in the differential equation are continuous.

Suppose as $t \to t_0$ you approach a point $x = x_0 $, $\dot{x} = 0$, with $\dot{x} > 0$ for $t < t_0$. Suppose $$ \frac{k_0}{m} < -(2\pi f)^2 \sin(2\pi f) < \frac{2k_0}{m} $$ Since $x \dot{x} > 0$, $k_1 = k_0$ and $\ddot{x} = -(2\pi f)^2 \sin(2 \pi f) - 2 k_0/m$, which will be negative. But if you cross $\dot{x} = 0$, $x \dot{x} < 0$, so $k_1 = 0$ and $\ddot{x} = -(2\pi f)^2 \sin(2 \pi f) - k_0/m$, which all of a sudden is positive. The result is that $\dot{x}$ can't actually go from positive to negative here. But it can't stay positive or $0$ here either. Thus the solution ceases to exist.

  • 0
    I apologize, I made a mistake in typing up the ODE. I went ahead and edited the question to include the time dependence in the sine function. I applied your approach above with the edits. I noticed with the values $k_0=4,m=1,$ and $f=0.05$, the condition you supposed above for when the discontinuity occurs in $\ddot{x}$ doesn't hold. With $f=0.05$, $(2\pi f)^2\sin(2\pi ft)\leq(2\pi f)^2=0.09869$. I believe though, there still is a jump in $\ddot{x}$ since it changes size. Would this still cause the numerical issue?2017-01-18