# Plotting a density function

I am trying to plot the following function in MATLAB

$$f(x) = \lambda e^{-\lambda(x-\Delta)}w(x-\Delta)$$

where $$w(x) = \begin{cases} 1 &x \geq 0 \\ 0 & {\rm otherwise}\\ \end{cases}$$

I chose a value of $$\lambda$$ of 1 and $$\Delta$$ of 2. I am just not sure how to define $$w(x)$$ and shift the function by delta. Thank you.

You can plot samples of a continuous density function just as you would do with any continuous function. Assuming $$w(x)$$ represents the continuous-time unit step function,

$$w(x-\Delta) = \begin{cases}{ 1 ~~~,~~~x \geq \Delta \\ 0 ~~~,~~~ \text{otherwise} } \end{cases}$$

then the shifted exponential pdf can be plotted with the following matlab/octave code :

clc; clear all; close all

K1 = -1;        % evaluation interval begins
K2 = 9;         % evaluation interval ends
N = 1000;       % number of points to display
x = linspace(K1,K2, N); % x = domain to use for displaying

lam = 1;        % exponential PDF parameter
delta = 2;      % shift amount
f = lam*exp(-lam*(x-delta));
f = f.*(x>delta);   % to implement w(x-delta)

figure, plot(x,f);
title('shifted exponential pdf for \lambda = 1, \Delta = 2');


The output will be:

• Thank you very much! Nov 24, 2019 at 21:27