Plotting a 2 dimensional graph

Function: S(p,N) = 1 - (1-p)^N
Plot a two-dimensional surface showing that probability: S(p,N), 0p1,2N10,000.

8 件のコメント

Geoff Hayes
Geoff Hayes 2020 年 2 月 18 日
Spencer - If this is homework, what have you tried so far?
Spencer S
Spencer S 2020 年 2 月 18 日
Hello Geoff!
This is not homework. Below is what I have so far. I am struggling to define the function and graph it.
the bounds are S(p,N), 0<=p<=1, 2<=N<=10,000
function [p,N] = (1-((1-p)^N))
p = 0:1;
N = 2:10000:
end
Geoff Hayes
Geoff Hayes 2020 年 2 月 18 日
編集済み: Geoff Hayes 2020 年 2 月 18 日
Are p and N inputs or outputs of this function? Please see Declare function name, inputs, and outputs for an idea of how to set the signature for your function.
Spencer S
Spencer S 2020 年 2 月 18 日
Its a probability formula where p is the probability something with happen and N is the number of incidents
Geoff Hayes
Geoff Hayes 2020 年 2 月 18 日
Does p just take on the values of 0 and 1 or are you interested in others? Consider meshgrid to create some data for your probability function.
Spencer S
Spencer S 2020 年 2 月 18 日
p is some number greater than or equal to zero and less than or equal to 1
Spencer S
Spencer S 2020 年 2 月 19 日
so P takes on all numbers between 0 and 1. Do you mind providing me with the code?
Geoff Hayes
Geoff Hayes 2020 年 2 月 19 日
Right but you still need to define what those values are for p. Is it sufficient to do something like
p = 0:0.01:1;
where the array p is all values 0, 0.01, 0.02, 0.03,..., 1.0? Or do you need more or fewer? Once you have determined that and done something similar for N (this is probably easier and you could use your code above), then you can use meshgrid as
[P,N] = meshgrid(0:0.01:1, 2:1:10000);
and then put those results in your above function. Then try using contour that Aquatris described below.

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

回答 (1 件)

Aquatris
Aquatris 2020 年 2 月 18 日

0 投票

What you are looking for is the "countour" function (or countourf) of Matlab. Check this link and you can adapty your equation to the given example.

2 件のコメント

Spencer S
Spencer S 2020 年 2 月 19 日
I can't get it to work. I think the problem is N is between 2 an 10,000. Do you mind providing me with your code?
Aquatris
Aquatris 2020 年 2 月 20 日
Dont exactly know your values but something like this;
p = linspace(0,1,1e3);
N = linspace(2,1000,1e3);
[X,Y] = meshgrid(p,N);
Z = 1-(1-X).^Y; % notice the .^ since we do not want matrix algebra
contourf(X,Y,Z)

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

カテゴリ

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

質問済み:

2020 年 2 月 18 日

コメント済み:

2020 年 2 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by