Plotting the summation of a Heaviside function

How to plot the summation of a this Heaviside function, i.e : where are real positive parameters with and u as real variable.

2 件のコメント

Toder
Toder 2020 年 5 月 7 日
Hi Gill, what have you tried so far? Is n fixed? It may be helpful to expand the summation on paper to better see what's going on. You can also plug in some sample points to get an idea of how the function behaves. Let's call the whole summation . Without even choosing values for we can figure out what S is for choices of μ. Three interesting ones to compute might be
,
Taking the time to figure these out will let us check the final plot once we make it. The documentation for the Heaviside function in Matlab can be found here.
Gill Judie
Gill Judie 2020 年 5 月 9 日
thank you for replying. As you said i already tried to compute this sum, but my main goal now is to expresse it as code and plot it in Matlab.

サインインしてコメントする。

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 5 月 7 日

1 投票

Try this
mu = sort(rand(5,1)); % random vectors of 5 \mu values in ascending order
x = linspace(0,1,1000); % values on x-axis
y = sum(heaviside(x-mu)); % command to create vector of heaviside and summing them
plot(x, y)

5 件のコメント

Gill Judie
Gill Judie 2020 年 5 月 9 日
thank you for replying. i have tried to run this code on my Matlab but the following error message appeared
I'm if there is something wrong in my matlab?
Ameer Hamza
Ameer Hamza 2020 年 5 月 9 日
Can you tell which MATLAB version are you using?
Ameer Hamza
Ameer Hamza 2020 年 5 月 9 日
If you are using a version older than R2016b than try this code
mu = sort(rand(5,1)); % random vectors of 5 \mu values in ascending order
x = linspace(0,1,1000); % values on x-axis
X = bsxfun(@minus, x, mu);
y = sum(heaviside(X)); % command to create vector of heaviside and summing them
plot(x, y)
Gill Judie
Gill Judie 2020 年 5 月 10 日
It worked perfectly now thank you. By the way, I'm using the MATLAB R2011a version.
Ameer Hamza
Ameer Hamza 2020 年 5 月 10 日
I am glad to be of help.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by