MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] 初学matlab请教各位大大 (https://www.labfans.com/bbs/showthread.php?t=13873)

tlsmouse 2011-09-08 15:32

初学matlab请教各位大大
 
an=p(1-p)^(n-1)
Pr=a1+a2+...+an

我要求以上Pr关于p的函数曲线图,具体代码该怎么写啊?
假设p=0:0.1:1.
请教各位大大帮忙啊,小弟感激不尽!

loalive 2011-10-11 12:57

回复: 初学matlab请教各位大大
 
在你这个问题中,我几点让我感到疑惑的地方,可能是未表达清楚:
1、p为一m维向量,那(1-p)^(n-1)是不是应该表达成(1-p).^(n-1)?同样 an=p.*(1-p).^(n-1)
2、Pr是不是应该为Pn?
我便按照我的理解(上面提到的)写了下面的这个函数:

function P=plot_P_p(p,n)
pl=length(p);
a=[];
pm=zeros(1,pl);
P=[];
for m=1:n
am=[a p.*(1-p).^(m-1)];
pm=pm+am;
P=[P;pm];
end
figure;
plot(p,P);


所有时间均为北京时间。现在的时间是 11:22

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.