﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-牵着老婆满街逛-随笔分类-Blitz++</title><link>http://www.cppblog.com/tx7do/category/2076.html</link><description>危机感是一种强大前进的动力！&lt;/br&gt;
GMail/GTalk: yanglinbo#google.com;&lt;/br&gt;
MSN/Email: tx7do#yahoo.com.cn;&lt;/br&gt;
QQ: 3 0 3 3 9 6 9 2 0 .</description><language>zh-cn</language><lastBuildDate>Mon, 19 May 2008 12:31:45 GMT</lastBuildDate><pubDate>Mon, 19 May 2008 12:31:45 GMT</pubDate><ttl>60</ttl><item><title>The Matrix Template Library</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9270.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:40:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9270.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9270.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9270.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9270.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9270.html</trackback:ping><description><![CDATA[
		<a href="http://osl.iu.edu/research/mtl/">http://osl.iu.edu/research/mtl/</a>
		<br />
		<p>The Matrix Template Library (MTL) is a high-performance generic component library that provides comprehensive linear algebra functionality for a wide variety of matrix formats. </p>
		<p>As with the <a href="http://www.sgi.com/tech/stl/">Standard Template Library (STL)</a>, MTL uses a five-fold approach, consisting of generic functions, containers, iterators, adaptors, and function objects, all developed specifically for high performance numerical linear algebra. Within this framework, MTL provides generic algorithms corresponding to the mathematical operations that define linear algebra. Similarly, the containers, adaptors, and iterators are used to represent and to manipulate concrete linear algebra objects such as matrices and vectors. </p>
		<p>To many scientific computing users, however, the advantages of an elegant programming interface are secondary to issues of performance. Generic programming is a powerful tool in this regard as well - performance tuning can itself be described in a generic fashion. These performance tuning abstractions are realized in a generic low-level library - the Basic Linear Algebra Instruction Set (BLAIS). Experimental results show that MTL with the BLAIS achieves performance that is as good as, or better than, vendor-tuned libraries. Thus, MTL demonstrates that the proper abstractions can be used to achieve high levels of performance, contrary to conventional wisdom. In addition, MTL requires orders of magnitude fewer lines of code for its implementation, with the concomitant savings in development and maintenance effort. </p>
		<h3>News</h3>
		<ul>
				<li>
						<b>July 5, 2005</b>: Distribution 2.1.2-22, which is adapted to the stricter syntax requirements in new compilers like gcc 4.0 can be <a href="http://osl.iu.edu/research/mtl/download.php3">downloaded here</a>. 
</li>
				<li>In parallel, <a href="http://www.osl.iu.edu/~pgottsch">Peter Gottschling</a> and <a href="http://www.boost.org/people/dave_abrahams.htm">Dave Abrahams</a> started the development of MTL version 4.0. It was planned to have an alpha version already released. "A good plan today is better than a perfect plan tomorrow" Robert De Niro said in "Wag the dog". This is certainly true for crisis management but we doubt the same applies for scientific software development. </li>
		</ul>
		<h3>Features</h3>
		<p>The Matrix Template Library is:</p>
		<dl compact="">
				<dt>
						<strong>Generic</strong>, <strong>Orthogonal</strong>, and <strong>Comprehensive</strong>: 
</dt>
				<dd>MTL includes a large number of data formats and algorithms, including most popular sparse and dense matrix formats and functionality equivalent to Level 3 <a href="http://www.netlib.org/blas/index.html">BLAS</a>. 
</dd>
				<dt>
						<strong>Flexible</strong> and <strong>Extensible</strong>: 
</dt>
				<dd>The MTL interface is designed to allow new functionality to be easily incorporated. 
</dd>
				<dt>
						<strong>High Performance</strong>: 
</dt>
				<dd>With a good optimizing compiler, such as <a href="http://www.kai.com/C_plus_plus/">KAI's C++</a>, MTL provides performance equal to (and in many cases better than) vendor-tuned math libraries. 
</dd>
				<dt>
						<strong>Reliable</strong>: 
</dt>
				<dd>MTL is extensively tested on a regular basis. 
</dd>
				<dt>
						<strong>Portable</strong>: 
</dt>
				<dd>MTL is written in ANSI C++ and can be compiled and used on any target platform with an ANSI C++ compiler. Currently, compilers known to work are <a href="http://www.kai.com/C_plus_plus/">KAI's C++</a> on various platforms, MIPSp ro 7.3 on SGI, Visual C++ 6.0 and Metrowerks CodeWarrior Pro 5 on NT, egcs-2.91.60 and gcc 2.95.x on various platforms. See <a href="http://osl.iu.edu/research/mtl/faq.php3">FAQ</a> for more information. </dd>
		</dl>
		<h3>Current Release</h3>
		<p>This is version 2.1.2 of MTL and its second full release. If you would like to be kept informed as new releases of MTL are made available, please <a href="http://osl.iu.edu/research/mtl/support.php3#mailing">subscribe to our announcement list</a>. </p>
<img src ="http://www.cppblog.com/tx7do/aggbug/9270.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:40 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9270.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>vc.net2003下安装和使用blitz++详细指南</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9268.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:34:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9268.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9268.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9268.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9268.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9268.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: @author:armylau														@date:2004-8-12																						 																				一．起因																																										安装和使用						blitz++						时经常...&nbsp;&nbsp;<a href='http://www.cppblog.com/tx7do/archive/2006/07/01/9268.html'>阅读全文</a><img src ="http://www.cppblog.com/tx7do/aggbug/9268.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:34 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9268.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC++ .NET 2003 –安装和使用Boost 1.30和Blitz++0.6 </title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9266.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:29:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9266.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9266.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9266.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9266.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9266.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 小气的神																		2003-05-01																																 																																										Article Type: In-Depth  																				...&nbsp;&nbsp;<a href='http://www.cppblog.com/tx7do/archive/2006/07/01/9266.html'>阅读全文</a><img src ="http://www.cppblog.com/tx7do/aggbug/9266.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:29 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9266.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>在VS.net下安装使用blitz++科学计算库</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9265.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:28:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9265.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9265.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9265.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9265.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9265.html</trackback:ping><description><![CDATA[     我做图像处理经常要用到矩阵运算，最常用到的工具就是matlab。不过matlab也就只能用在实验，真正做程序的时候，好多东西都要自己写，很麻烦。在网上搜了一下科学计算库，找到了三个，gsl、blitz++和MTL，没时间仔细研究哪个效率更高了，听了Oscargreat的推荐，开始用blitz++。
<p>      blitz++的代码下载下来发现，只是适合linux下编译，幸好在网上搜到了几篇不错的文档，在其指导下顺利的编译了blitz.lib。</p><ul><li><a href="http://blog.csdn.net/ccBoy/archive/2003/05/02/10433.aspx"><font color="#59708c">体验：VC++ .NET 2003 –安装和使用Boost 1.30和Blitz++0.6</font></a></li><li>armylau的《VC.NET2003下安装和使用BLITZ++详细指南》原始出处不知道，大家可以自己去google，网上很多. </li></ul><p>      按照文档所述，编译blitz.lib和运行测试程序，都不会有问题。不过，我在尝试把blitz库用到自己的程序时，有了一些问题.</p><p>     建了一个MFC应用程序，代码如下:</p><blockquote><p>#include stdafx.h"<br />#include "config.h"<br />#include &lt;blitz/array.h&gt;<br />using namespace blitz;</p><p>...</p></blockquote><p>      这样会报错。和Oscargreat分析了一会，发现是MFC和blitz冲突了，MFC居然把min和max用宏定义了（windef.h)，这样和blitz里的min和max冲突，暂时的解决办法是用#undef在前面屏蔽掉min和max，以后再找其他的办法吧。</p><p>      还有就是blitz由于是C++ template库，所以，有很多情况下的应用是不需要链接blitz.lib的，但是最好还是链接上，因为blitz源文件里还是有一些cpp的。 </p><img src ="http://www.cppblog.com/tx7do/aggbug/9265.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:28 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9265.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>标准库rand()函数的缺陷以及Blitz++随机数生成的简介</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9264.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:27:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9264.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9264.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9264.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9264.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9264.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: （				newsuppy, 				转载请注明出处）																																		当我们需要在某个任务中使用随机数，通常我们习惯于使用标准库的rand函数。像这样：srand(time(0)); // 时间种子								        rand() % MAX_RAND				；				...&nbsp;&nbsp;<a href='http://www.cppblog.com/tx7do/archive/2006/07/01/9264.html'>阅读全文</a><img src ="http://www.cppblog.com/tx7do/aggbug/9264.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:27 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9264.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> Blitz++与MTL两大数值计算程序库(C++)的简介</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9263.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:26:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9263.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9263.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9263.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9263.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9263.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Blitz++																				与																				MTL																				两大数值计算程序库																				(C++)																				的简介																																...&nbsp;&nbsp;<a href='http://www.cppblog.com/tx7do/archive/2006/07/01/9263.html'>阅读全文</a><img src ="http://www.cppblog.com/tx7do/aggbug/9263.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:26 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9263.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux 下 Blitz++ 的安装</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9261.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:24:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9261.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9261.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9261.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9261.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9261.html</trackback:ping><description><![CDATA[
		<p>1 下载 <a href="http://www.oonumerics.org/blitz/download/releases/blitz-0.6.tar.gz">http://www.oonumerics.org/blitz/download/releases/blitz-0.6.tar.gz</a></p>
		<p>2  tar zxvf   <a href="http://blitz-0.6.tar.gz/">blitz-0.6.tar.gz</a></p>
		<p>3 ./configure</p>
		<p>4 make</p>
		<p>5 make install</p>
<img src ="http://www.cppblog.com/tx7do/aggbug/9261.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:24 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9261.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Blitz++ 矩阵相乘(张量运算) 示例</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9262.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:24:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9262.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9262.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9262.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9262.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9262.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">整理 by RobinKin<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">Blitz++ 张量计算的示例</span>
				<span style="COLOR: #008000">
						<br />
						<img id="Codehighlighter1_35_320_Open_Image" onclick="this.style.display='none'; Codehighlighter1_35_320_Open_Text.style.display='none'; Codehighlighter1_35_320_Closed_Image.style.display='inline'; Codehighlighter1_35_320_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_35_320_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_35_320_Closed_Text.style.display='none'; Codehighlighter1_35_320_Open_Image.style.display='inline'; Codehighlighter1_35_320_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span id="Codehighlighter1_35_320_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
				<span id="Codehighlighter1_35_320_Open_Text">
						<span style="COLOR: #008000">/*</span>
						<span style="COLOR: #008000">****************************************************************************<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> * matmult.cpp     Blitz++ tensor notation example<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> *****************************************************************************<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> * This example illustrates the tensor-like notation provided by Blitz++.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span>
						<span style="COLOR: #008000">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">blitz</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">array.h</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">iostream</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> blitz;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_404_3883_Open_Image" onclick="this.style.display='none'; Codehighlighter1_404_3883_Open_Text.style.display='none'; Codehighlighter1_404_3883_Closed_Image.style.display='inline'; Codehighlighter1_404_3883_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_404_3883_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_404_3883_Closed_Text.style.display='none'; Codehighlighter1_404_3883_Open_Image.style.display='inline'; Codehighlighter1_404_3883_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_404_3883_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_404_3883_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Create two 4x4 arrays.  We want them to look like matrices, so<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> we'll make the valid index range 1..4 (rather than 0..3 which is<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> the default).</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Range r(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">4</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Array</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> A(r,r), B(r,r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> The first will be a Hilbert matrix:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> a   =   1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">  ij   -----<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">       i+j-1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Blitz++ provides a set of types { firstIndex, secondIndex, <img src="http://www.cppblog.com/images/dot.gif" /> }<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> which act as placeholders for indices.  These can be used directly<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> in expressions.  For example, we can fill out the A matrix like this:</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    firstIndex i;    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Placeholder for the first index</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    secondIndex j;   </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Placeholder for the second index</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    A </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1.0</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> (i</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">j</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">A = </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> A </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> A = 4 x 4<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">         1       0.5  0.333333      0.25<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">       0.5  0.333333      0.25       0.2<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">  0.333333      0.25       0.2  0.166667<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">      0.25       0.2  0.166667  0.142857<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Now the A matrix has each element equal to a_ij = 1/(i+j-1).<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> The matrix B will be the permutation matrix<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> [ 0 0 0 1 ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> [ 0 0 1 0 ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> [ 0 1 0 0 ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> [ 1 0 0 0 ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Here are two ways of filling out B:</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    B </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> (i </span>
						<span style="COLOR: #000000">==</span>
						<span style="COLOR: #000000"> (</span>
						<span style="COLOR: #000000">5</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">j));         </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Using an equation -- a bit cryptic</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">B = </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> B </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> B = 4 x 4<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">         0         0         0         1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">         0         0         1         0<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">         0         1         0         0<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">         1         0         0         0</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    B </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,           </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Using an initializer list</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">        </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">,           <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">,<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">B = </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> B </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Now some examples of tensor-like notation.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Array</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> C(r,r,r);  </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> A three-dimensional array: 1..4, 1..4, 1..4</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    thirdIndex k;             </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Placeholder for the third index<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> This expression will set<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> c    = a   * b<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">  ijk    ik    kj<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">   C = A(i,k) * B(k,j);</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">   cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">C = </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> C </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> In real tensor notation, the repeated k index would imply a<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> contraction (or summation) along k.  In Blitz++, you must explicitly<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> indicate contractions using the sum(expr, index) function:</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Array</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> D(r,r);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    D </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> sum(A(i,k) </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> B(k,j), k);</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">指标收缩, 计算矩阵积<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> The above expression computes the matrix product of A and B.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">D = </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> D </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> D = 4 x 4<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">      0.25  0.333333       0.5         1<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">       0.2      0.25  0.333333       0.5<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">  0.166667       0.2      0.25  0.333333<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">  0.142857  0.166667       0.2      0.25<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Indices like i,j,k can be used in any order in an expression.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> For example, the following computes a kronecker product of A and B,<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> but permutes the indices along the way:</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Array</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">4</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> E(r,r,r,r);    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> A four-dimensional array</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    fourthIndex l;                </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Placeholder for the fourth index</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    E </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> A(l,j) </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> B(k,i);</span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">指标轮换<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">cout &lt;&lt; "E = " &lt;&lt; E &lt;&lt; endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Now let's fill out a two-dimensional array with a radially symmetric<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> decaying sinusoid.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> N </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">64</span>
						<span style="COLOR: #000000">;                   </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Size of array: N x N</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    Array</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000">,</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> F(N,N);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000"> midpoint </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> (N</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)</span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">.;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> cycles </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">3</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000"> omega </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2.0</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> M_PI </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> cycles </span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000">(N);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">float</span>
						<span style="COLOR: #000000"> tau </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">10.0</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> N;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    F </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> cos(omega </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> sqrt(pow2(i</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">midpoint) </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> pow2(j</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">midpoint)))<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> exp(tau </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> sqrt(pow2(i</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">midpoint) </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> pow2(j</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">midpoint)));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /></span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">cout &lt;&lt; "F = " &lt;&lt; F &lt;&lt; endl;</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">输出</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">A </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000"> x </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">[         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.5</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.333333</span>
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0.5</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.333333</span>
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.2</span>
				<span style="COLOR: #000000">    </span>
				<span style="COLOR: #000000">0.333333</span>
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.2</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.166667</span>
				<span style="COLOR: #000000">        </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.2</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.166667</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.142857</span>
				<span style="COLOR: #000000"> ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />B </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000"> x </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />[         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />          </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />          </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />          </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />B </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000"> x </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />[         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />          </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />          </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />          </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000"> ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />D </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000"> x </span>
				<span style="COLOR: #000000">4</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />[      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.333333</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.5</span>
				<span style="COLOR: #000000">         </span>
				<span style="COLOR: #000000">1</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />        </span>
				<span style="COLOR: #000000">0.2</span>
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.333333</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.5</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   </span>
				<span style="COLOR: #000000">0.166667</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.2</span>
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.333333</span>
				<span style="COLOR: #000000"> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   </span>
				<span style="COLOR: #000000">0.142857</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">0.166667</span>
				<span style="COLOR: #000000">       </span>
				<span style="COLOR: #000000">0.2</span>
				<span style="COLOR: #000000">      </span>
				<span style="COLOR: #000000">0.25</span>
				<span style="COLOR: #000000"> ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
		</div>
<img src ="http://www.cppblog.com/tx7do/aggbug/9262.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:24 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9262.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Blitz++ 计算二阶导数</title><link>http://www.cppblog.com/tx7do/archive/2006/07/01/9260.html</link><dc:creator>杨粼波</dc:creator><author>杨粼波</author><pubDate>Sat, 01 Jul 2006 05:23:00 GMT</pubDate><guid>http://www.cppblog.com/tx7do/archive/2006/07/01/9260.html</guid><wfw:comment>http://www.cppblog.com/tx7do/comments/9260.html</wfw:comment><comments>http://www.cppblog.com/tx7do/archive/2006/07/01/9260.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/tx7do/comments/commentRss/9260.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/tx7do/services/trackbacks/9260.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #008000">//</span>
				<span style="COLOR: #008000">整理 by RobinKin</span>
				<span style="COLOR: #008000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />#include </span>
				<span style="COLOR: #000000">&lt;</span>
				<span style="COLOR: #000000">blitz</span>
				<span style="COLOR: #000000">/</span>
				<span style="COLOR: #000000">vector.h</span>
				<span style="COLOR: #000000">&gt;</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">using</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">namespace</span>
				<span style="COLOR: #000000"> blitz;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">int</span>
				<span style="COLOR: #000000"> main()<br /><img id="Codehighlighter1_80_2296_Open_Image" onclick="this.style.display='none'; Codehighlighter1_80_2296_Open_Text.style.display='none'; Codehighlighter1_80_2296_Closed_Image.style.display='inline'; Codehighlighter1_80_2296_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_80_2296_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_80_2296_Closed_Text.style.display='none'; Codehighlighter1_80_2296_Open_Image.style.display='inline'; Codehighlighter1_80_2296_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_80_2296_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.cppblog.com/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_80_2296_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> In this example, the function cos(x)^2 and its second derivative<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> 2 (sin(x)^2 - cos(x)^2) are sampled over the range [0,1).<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> The second derivative is approximated numerically using a<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> [ 1 -2  1 ] mask, and the approximation error is computed.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_351_456_Open_Image" onclick="this.style.display='none'; Codehighlighter1_351_456_Open_Text.style.display='none'; Codehighlighter1_351_456_Closed_Image.style.display='inline'; Codehighlighter1_351_456_Closed_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_351_456_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_351_456_Closed_Text.style.display='none'; Codehighlighter1_351_456_Open_Image.style.display='inline'; Codehighlighter1_351_456_Open_Text.style.display='inline';" src="http://www.cppblog.com/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
						</span>
						<span id="Codehighlighter1_351_456_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span>
						<span id="Codehighlighter1_351_456_Open_Text">
								<span style="COLOR: #008000">/*</span>
								<span style="COLOR: #008000"> cos(x)^2  的二阶导数 是2 (sin(x)^2 - cos(x)^2)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />下面在[0,1) 的范围中，以delta为步长 ，用[ 1 -2  1 ] 的方法计算二阶导数<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />看看和精确值的误差<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" /></span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">const</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">int</span>
						<span style="COLOR: #000000"> numSamples </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">100</span>
						<span style="COLOR: #000000">;              </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Number of samples</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> delta </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">. </span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> numSamples;          </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Spacing of samples</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    Range R(</span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">, numSamples </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">);              </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Index set of the vector<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Sample the function y = cos(x)^2 over [0,1)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> An object of type Range can be treated as a vector, and used<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> as a term in vector expressions.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> The initialization for y (below) will be translated via expression<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> templates into something of the flavour<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> for (unsigned i=0; i &lt; 99; ++i)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> {<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">     double _t1 = cos(i * delta);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">     y[i] = _t1 * _t1;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> }</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Vector</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> y </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> sqr(cos(R </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> delta));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Sample the exact second derivative</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    Vector</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> y2exact </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2.0</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> (sqr(sin(R </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> delta)) </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> sqr(cos(R </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> delta)));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Approximate the 2nd derivative using a [ 1 -2  1 ] mask<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> We can only apply this mask to the elements 1 .. 98, since<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> we need one element on either side to apply the mask.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    Range I(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">,numSamples</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    Vector</span>
						<span style="COLOR: #000000">&lt;</span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000">&gt;</span>
						<span style="COLOR: #000000"> y2(numSamples);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    y2(I) </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> (y(I</span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">) </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">2</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000"> y(I) </span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000"> y(I</span>
						<span style="COLOR: #000000">+</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">)) </span>
						<span style="COLOR: #000000">/</span>
						<span style="COLOR: #000000"> (delta</span>
						<span style="COLOR: #000000">*</span>
						<span style="COLOR: #000000">delta);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />  <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> The above difference equation will be transformed into<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> something along the lines of<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> double _t2 = delta*delta;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> for (int i=1; i &lt; 99; ++i)<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000">     y2[i] = (y[i-1] - 2 * y[i] + y[i+1]) / _t2;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Now calculate the root mean square approximation error:</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">double</span>
						<span style="COLOR: #000000"> error </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> sqrt(mean(sqr(y2(I) </span>
						<span style="COLOR: #000000">-</span>
						<span style="COLOR: #000000"> y2exact(I))));<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> Display a few elements from the vectors.<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> This range constructor means elements 1 to 91 in increments<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #008000">//</span>
						<span style="COLOR: #008000"> of 15.</span>
						<span style="COLOR: #008000">
								<br />
								<img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />
						</span>
						<span style="COLOR: #000000">    Range displayRange(</span>
						<span style="COLOR: #000000">1</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">91</span>
						<span style="COLOR: #000000">, </span>
						<span style="COLOR: #000000">15</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /> <br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    cout </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Exact derivative:</span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> y2exact(displayRange) </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />         </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">Approximation:   </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> y2(Range(displayRange)) </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />         </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000">RMS Error:       </span>
						<span style="COLOR: #000000">"</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> error </span>
						<span style="COLOR: #000000">&lt;&lt;</span>
						<span style="COLOR: #000000"> endl;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">return</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #000000">0</span>
						<span style="COLOR: #000000">;<br /><img src="http://www.cppblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Output:<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Exact derivative:[    </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.9996</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.89847</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.62776</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.21164</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">0.687291</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">0.1015495</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />Approximation:   [   </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.99953</span>
				<span style="COLOR: #000000">  </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.89841</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.6277</span>
				<span style="COLOR: #000000">   </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">1.2116</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">0.687269</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">-</span>
				<span style="COLOR: #000000">0.1015468</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />   ]<br /><img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />RMS Error:       </span>
				<span style="COLOR: #000000">4.24826e-05</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
						<br />
						<img src="http://www.cppblog.com/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.cppblog.com/tx7do/aggbug/9260.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/tx7do/" target="_blank">杨粼波</a> 2006-07-01 13:23 <a href="http://www.cppblog.com/tx7do/archive/2006/07/01/9260.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>