matlabsimulink

Integrating Sine Wave shifted up by 1


When I integrate sine waves with 1Hz in Matlab, why does the result shift by 1? The integral block's initial value is 0. I would like to know why this happens and the correct way to solve it. The solution I came up with is to change the initial value to -1 and this solved the issue but I'm not sure about the consequences of changing the initial value. It seems Matlab assumes the integration constant is 2.

enter image description here


Solution

  • You're working with machines here! This one does not know the simplified paradigma(integral sin = -cos) we learn in maths! ;)

    Simulink here just numerically integrates the sine. And it just starts from zero as you set. If you imagine the integration as area below the sine-curve, you can easily follow, what it does: The integral starts from zero and increases until x=pi, with a maximum slope where the sine is at its maximum (x=pi/2). Then, the sine changes to negative values, so the integral decreases again until it reaches 0 at x=2pi, where the two halfes of the sine just equalise. Just as to expect.

    Or mathematically said: The general antiderivative of sin(x) is -cos(x) + A. As the initial value of the integral is set to zero, you get the constraint of -cos(0) + A = 0, which comes to A=1. And y = -cos(x) + 1 is just the blue curve you see.