How can I create a unit step function u(t) in symbolic function form?

Hi,
I have an homework in which a part includes a function which is applied to an LTI system. The problem is, the function is desired to be defined as a symbolic function and I did that part easily but it is multiplied with the unit step function u(t) and problem begins here. Normally, I define the unit step with a loop or a simple statement like unitstepsignal = t>=0; but this statement does not respond to the calculation and loops does not respond as well since MATLAB cannot convert symbolic to logical and gives the error message "Conversion to logical from sym is not possible.". I tried the heaviside function but it turns 1/2 when t=0 yet I need 1 for t=0. That is why, it is not useful for the current situation. I'm adding the part that I need and I left unitstepsignal as how it is because I'm really tired of trying. So, thanks in advance for your help about defining u(t).
syms x(t)
syms h(t)
x(t)=44.*exp(3.27.*t).*unitstepsignal; %unitstepsignal is u(t) but I could not define it as symbolic.
h(t)=0.5.*44.*exp(0.5.*3.27.*t).*unitstepsignal;

 Risposta accettata

Use the heaviside function.

4 Commenti

I used it but when I set the value of t as 0 (x(0)) it turns the result as 22 but it should be 44 since u(t) is 1 when t=0 and if we multiply the heaviside with 2 other values of t, which are greater then 0, results in 2 times bigger than the value they should get. I don't know if I'm missing something you try to mean but it did not work so far.
No, it should not according to the documentation for heaviside. It is giving the correct result.
  • H = heaviside(x) evaluates the Heaviside step function (also known as the unit step function) at x. The Heaviside function is a discontinuous function that returns 0 for x < 0, 1/2 for x = 0, and 1 for x > 0.
If you want to create your own version that does what you describe, use:
u = @(t) t>=0;
That will return 0 for t<0 and 1 for t>=0.
Call it as you would any other function:
us = u(t);
having first defined 't’ as a variable (scalar or vector) in your workspace.
EDIT — (20 Dec 2020 at 2:24)
Note that the heaviside function is by definition differentiable. The ‘u’ function I created (because it does what you want), is not differentiable, because its derivative is +Inf at t=0. Do not be surprised if it fails if you attempt to use it in a symbolic function that involves a derivative.
According to the heaviside page, the value of the heaviside function can be changed at origin by using the sympref function. So, thanks a lot for your help and recommendation.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by