Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Heaviside unit step function - help

Subject: Heaviside unit step function - help

From: Sarah Coleman

Date: 19 Apr, 2012 08:20:13

Message: 1 of 7

Hi all, I want to plot 3 Heaviside step unit functions

1) u(t)

2) 4*u(t-1)

3) -5*u(t-1)

where u(t) is the unit Heaviside step function

Before that, how do write an equation using all three i.e

dxdt = u(t) + 4*u(t-1) - 5*u(t-1)

Thank you

Subject: Heaviside unit step function - help

From: Nasser M. Abbasi

Date: 19 Apr, 2012 08:38:39

Message: 2 of 7

On 4/19/2012 3:20 AM, Sarah Coleman wrote:
> Hi all, I want to plot 3 Heaviside step unit functions
>
> 1) u(t)
>
> 2) 4*u(t-1)
>
> 3) -5*u(t-1)
>
> where u(t) is the unit Heaviside step function
>
> Before that, how do write an equation using all three i.e
>
> dxdt = u(t) + 4*u(t-1) - 5*u(t-1)
>
> Thank you


just replace u(t) by heaviside(t) ?


close all
syms t
subplot(2,2,1);
r=[-1 2];
ezplot(heaviside(t),r)
subplot(2,2,2);
ezplot(4*heaviside(t-1),r)
subplot(2,2,3);
ezplot(-5*heaviside(t-1),r)
subplot(2,2,4);
ezplot(heaviside(t)+4*heaviside(t-1)-5*heaviside(t-1),r)

--Nasser

Subject: Heaviside unit step function - help

From: Sarah Coleman

Date: 19 Apr, 2012 09:40:11

Message: 3 of 7

I did my coding in a similar manner, but still didn't work. Here is a small section of my coding for finding "z" using ode45

%This function is used to integrate using "ode45", (beta, gamma, A = constants)

function [ dydt ] = IntegratingFunction2(t,y,beta,gamma,A)

z = y(1);
zdot = y(2);

dydt = zeros(size(y));
dydt(1) = zdot;
syms t;
dydt(2) = heaviside(A*t) + 4*heaviside(A*(t-1)) - 5*heaviside(A*(t-3)) - beta*gamma*zdot - beta*z;

return


Then in my main script I called the function:

[tLinear,y] = ode45(@(t,y)IntegratingFunction(t,y,beta,gamma,A(k)), tspan, xinit,options);

I then made

%This statement means that the first column from "y" are all the values for "z" (a function in terms of t(time)

z = y(:,1);

% the output "y" is technically dydt, as written in my function earlier
% I now plot "z" in terms of "t" (time)

plot(tLinear , z , 'r--');

Now here is the problem, nothing shows. Why?




"Nasser M. Abbasi" <nma@12000.org> wrote in message <jmoiuf$l7c$1@speranza.aioe.org>...
> On 4/19/2012 3:20 AM, Sarah Coleman wrote:
> > Hi all, I want to plot 3 Heaviside step unit functions
> >
> > 1) u(t)
> >
> > 2) 4*u(t-1)
> >
> > 3) -5*u(t-1)
> >
> > where u(t) is the unit Heaviside step function
> >
> > Before that, how do write an equation using all three i.e
> >
> > dxdt = u(t) + 4*u(t-1) - 5*u(t-1)
> >
> > Thank you
>
>
> just replace u(t) by heaviside(t) ?
>
>
> close all
> syms t
> subplot(2,2,1);
> r=[-1 2];
> ezplot(heaviside(t),r)
> subplot(2,2,2);
> ezplot(4*heaviside(t-1),r)
> subplot(2,2,3);
> ezplot(-5*heaviside(t-1),r)
> subplot(2,2,4);
> ezplot(heaviside(t)+4*heaviside(t-1)-5*heaviside(t-1),r)
>
> --Nasser

Subject: Heaviside unit step function - help

From: Torsten

Date: 19 Apr, 2012 10:21:07

Message: 4 of 7

On 19 Apr., 11:40, "Sarah Coleman" <gaurav91...@gmail.com> wrote:
> I did my coding in a similar manner, but still didn't work. Here is a small section of my coding for finding "z" using ode45
>
> %This function is used to integrate using "ode45", (beta, gamma, A = constants)
>
> function [ dydt ] = IntegratingFunction2(t,y,beta,gamma,A)
>
> z = y(1);
> zdot = y(2);
>
> dydt = zeros(size(y));
> dydt(1) = zdot;
> syms t;
> dydt(2) = heaviside(A*t) + 4*heaviside(A*(t-1)) - 5*heaviside(A*(t-3)) - beta*gamma*zdot - beta*z;
>
> return
>
> Then in my main script I called the function:
>
> [tLinear,y] = ode45(@(t,y)IntegratingFunction(t,y,beta,gamma,A(k)), tspan, xinit,options);
>
> I then made
>
> %This statement means that the first column from "y" are all the values for "z" (a function in terms of t(time)
>
> z = y(:,1);
>
> % the output "y" is technically dydt, as written in my function earlier
> % I now plot "z" in terms of "t" (time)
>
> plot(tLinear , z , 'r--');
>
> Now here is the problem, nothing shows. Why?
>
> "Nasser M. Abbasi" <n...@12000.org> wrote in message <jmoiuf$l7...@speranza.aioe.org>...
>
>
>
> > On 4/19/2012 3:20 AM, Sarah Coleman wrote:
> > > Hi all, I want to plot 3 Heaviside step unit functions
>
> > > 1) u(t)
>
> > > 2) 4*u(t-1)
>
> > > 3) -5*u(t-1)
>
> > > where u(t) is the unit Heaviside step function
>
> > > Before that, how do write an equation using all three i.e
>
> > > dxdt = u(t) + 4*u(t-1) - 5*u(t-1)
>
> > > Thank you
>
> > just replace u(t) by heaviside(t) ?
>
> > close all
> > syms t
> > subplot(2,2,1);
> > r=[-1 2];
> > ezplot(heaviside(t),r)
> > subplot(2,2,2);
> > ezplot(4*heaviside(t-1),r)
> > subplot(2,2,3);
> > ezplot(-5*heaviside(t-1),r)
> > subplot(2,2,4);
> > ezplot(heaviside(t)+4*heaviside(t-1)-5*heaviside(t-1),r)
>
> > --Nasser- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

In integratingFunction2, t is the actual time and of type double.
Don't replace it by a symbolic variable t for heaviside.

Best wishes
Torsten.

Subject: Heaviside unit step function - help

From: Steven_Lord

Date: 19 Apr, 2012 13:51:33

Message: 5 of 7



"Sarah Coleman" <gaurav91011@gmail.com> wrote in message
news:jmomhr$mq4$1@newscl01ah.mathworks.com...
> I did my coding in a similar manner, but still didn't work. Here is a
> small section of my coding for finding "z" using ode45
>
> %This function is used to integrate using "ode45", (beta, gamma, A =
> constants)
>
> function [ dydt ] = IntegratingFunction2(t,y,beta,gamma,A)
>
> z = y(1);
> zdot = y(2);
>
> dydt = zeros(size(y));
> dydt(1) = zdot;
> syms t;
> dydt(2) = heaviside(A*t) + 4*heaviside(A*(t-1)) - 5*heaviside(A*(t-3)) -
> beta*gamma*zdot - beta*z;

You should not mix symbolic expressions with ODE45. Either solve the system
completely numerically with ODE45 or solve the system completely
symbolically with DSOLVE. In this case, I'd probably go with the DSOLVE
approach.

*snip*

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Heaviside unit step function - help

From: Sarah Coleman

Date: 19 Apr, 2012 18:48:06

Message: 6 of 7

Even without "syms t", the graph still is isn't plotted. I've been thinking maybe the way I've written the heaviside function is incorrect

Subject: Heaviside unit step function - help

From: Muhammad Ali

Date: 25 Jan, 2014 13:05:05

Message: 7 of 7

just remove the semicolon ";" in the last of ur plot command....

--Ali

"Sarah Coleman" wrote in message <jmomhr$mq4$1@newscl01ah.mathworks.com>...
> I did my coding in a similar manner, but still didn't work. Here is a small section of my coding for finding "z" using ode45
>
> %This function is used to integrate using "ode45", (beta, gamma, A = constants)
>
> function [ dydt ] = IntegratingFunction2(t,y,beta,gamma,A)
>
> z = y(1);
> zdot = y(2);
>
> dydt = zeros(size(y));
> dydt(1) = zdot;
> syms t;
> dydt(2) = heaviside(A*t) + 4*heaviside(A*(t-1)) - 5*heaviside(A*(t-3)) - beta*gamma*zdot - beta*z;
>
> return
>
>
> Then in my main script I called the function:
>
> [tLinear,y] = ode45(@(t,y)IntegratingFunction(t,y,beta,gamma,A(k)), tspan, xinit,options);
>
> I then made
>
> %This statement means that the first column from "y" are all the values for "z" (a function in terms of t(time)
>
> z = y(:,1);
>
> % the output "y" is technically dydt, as written in my function earlier
> % I now plot "z" in terms of "t" (time)
>
> plot(tLinear , z , 'r--');
>
> Now here is the problem, nothing shows. Why?
>
>
>
>
> "Nasser M. Abbasi" <nma@12000.org> wrote in message <jmoiuf$l7c$1@speranza.aioe.org>...
> > On 4/19/2012 3:20 AM, Sarah Coleman wrote:
> > > Hi all, I want to plot 3 Heaviside step unit functions
> > >
> > > 1) u(t)
> > >
> > > 2) 4*u(t-1)
> > >
> > > 3) -5*u(t-1)
> > >
> > > where u(t) is the unit Heaviside step function
> > >
> > > Before that, how do write an equation using all three i.e
> > >
> > > dxdt = u(t) + 4*u(t-1) - 5*u(t-1)
> > >
> > > Thank you
> >
> >
> > just replace u(t) by heaviside(t) ?
> >
> >
> > close all
> > syms t
> > subplot(2,2,1);
> > r=[-1 2];
> > ezplot(heaviside(t),r)
> > subplot(2,2,2);
> > ezplot(4*heaviside(t-1),r)
> > subplot(2,2,3);
> > ezplot(-5*heaviside(t-1),r)
> > subplot(2,2,4);
> > ezplot(heaviside(t)+4*heaviside(t-1)-5*heaviside(t-1),r)
> >
> > --Nasser

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us