Plotting a 2 dimensional graph

조회 수: 1 (최근 30일)
Spencer S
Spencer S 2020년 2월 18일
댓글: Aquatris 2020년 2월 20일
Function: S(p,N) = 1 - (1-p)^N
Plot a two-dimensional surface showing that probability: S(p,N), 0p1,2N10,000.
  댓글 수: 8
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일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by