MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   [MATLAB基础] 求和问题~急~~· (https://www.labfans.com/bbs/showthread.php?t=11476)

matlabmichael 2010-05-07 18:14

求和问题~急~~·
 
R=1:1:15; Rlen=length(R);
for j=1:Rlen
n=0;
p=chi2cdf(j,6)-chi2cdf(j-1,6);
R=[34 27 25 23 17 26 18 21 24 29 27 18 32 25 34;];
n=n+R(j)*p
end
这一段程序得到的是15个单个的n值,怎样用程序实现这15个R(j)*p的和呀?谢谢了。。:)

未注册 2010-05-07 22:52

回复: 求和问题~急~~·
 
将n=0;移至循环体之外即可!或使用求和函数sum求解!

laosam280 2010-05-08 16:29

回复: 求和问题~急~~·
 
R=1:1:15;
Rlen=length(R);
n(1)=0;
for j=1:Rlen
p=chi2cdf(j,6)-chi2cdf(j-1,6);
R=[34 27 25 23 17 26 18 21 24 29 27 18 32 25 34;];
n(j+1)=n(j)+R(j)*p;
end
sum(n)


所有时间均为北京时间。现在的时间是 14:38

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