mathematica;教學;pdf mathematica 6教學 mathematica基本教學
Write a function "pascal" would produce the (nested) list "{{1}, {1,1}, {1,2,1}, {1,3,3,1}....}".
Generate the triangle by addition; do not use the function "Binomial[ ]".
pascal[n_Integer]:=NestList[Insert[#,0,1]+Insert[#,0,Length[#]+1]&,{1},n]
or
pascal[n_Integer]:=Module[{t},t=n;
aa=NestList[Insert[#,0,1]+Insert[#,0,Length[#]+1]&,{1},t+1];
bb=Table[Insert[aa[[i]],"",Table[{m},{m,2,i}]],{i,1,t+1}];
Table[Nest[Insert[#,"",1]&,bb[[i]],t+1-i],{i,1,t+1}]//TableForm]
讀者回應 ( 0 意見 )
訂閱發佈留言 (Atom)
發佈留言
Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.
如果這篇文章對你有幫助,那請留個訊息給我~