📄 vc在线 _ 编程技术文章.htm
字号:
<LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=3" target="_self" title="System Programming"><font color="#000000">系统类编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=4" target="_self" title="Network and Communications"><font color="#000000">网络类编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=5" target="_self" title="Template and Module"><font color="#000000">模板组件类</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=6" target="_self" title="File and Print"><font color="#000000">打印类编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=7" target="_self" title="Database Programming"><font color="#000000">数据库编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=8" target="_self" title="Graph,Image and MultiMedia"><font color="#000000">多媒体编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=12" target="_self" title="Game Programming"><font color="#000000">游戏类编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=13" target="_self" title="Dll Programming"><font color="#000000">dll 编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=11" target="_self" title="Various Controls"><font color="#000000">控件类编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=14" target="_self" title="Various Arithmetic"><font color="#000000">经典算法</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=9" target="_self" title="C and C++"><font color="#000000">C/C++编程</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=10" target="_self" title="XML/.NET"><font color="#000000">XML/.NET</font></a></td> </tr> <tr> <td heiht=22 width=1 align=left valign=middle> <LI type=square></LI></td> <td onmouseover="this.bgColor='#dddddd'" onmouseout="this.bgColor='#ffffff'" height="22" align="left" valign="middle"><a href="../article/list_srccode.php?type=15" target="_self" title="Other"><font color="#000000">其它编程</font></a></td> </tr> </table> </td> </tr></table>--> <br> </td> </tr> </table> <!-- 菜单结束 --> </td> <td align="left" valign="top"> <table width="99%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td> <table width="99%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td align="left"> 当前位置: <a href='http://www.vczx.com' target='_self' class='b'>首页</a> >> <a href='./list.php' target='_self' class='b'>技术文章</a> >> 各种算法 </td> </tr> </table> </td> </tr> </table> <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"> <tr> <td align="left" bgcolor=#EFEFEF width="2%"> </td> <td align="left" bgcolor=#EFEFEF width="83%"><br> 文章标题:<b>矩阵运算代码(包括加减乘除以及求逆运算等)</b><br>原 作 者:黄运新<br>原 出 处:不详<br>发 布 者:loose_went<br>发布类型:转载<br>发布日期:2004-08-31<br>今日浏览:17<br>总 浏 览:724<br> </td> <td align="left" bgcolor=#EFEFEF width="15%" valign="bottom"> <a href="./file/20040831084745_vczx_matrix_arithmetic.rar" target=_blank>下载本文所附源代码<img border=0 src="./images/zip.gif" title="下载 20040831084745_vczx_matrix_arithmetic.rar"></a> </td> </tr> </table> <table border=0 cellpadding=0 width=96% align="center" cellspacing=0> <tr> <td bgcolor="#FFFFFF" align="left" valign="top"><br> <tr><td>程序运行效果截图:<br><img src=./img/20040831084740_vczx_matrix_arithmetic.gif align=left ></td></tr><tr><td><br><br>矩阵运算程序
<br>功能分析:
<br>本程序能完成矩阵的输入、输出。具有相同行数和列数的矩阵间的加法、减法。符合矩阵乘法规则要求的矩阵间的乘法。方阵间的除法,方阵的求逆。矩阵的求转置矩阵等功能。
<br>设计思想:
<br>本程序要完成矩阵的一般运算。同时本程序的截面要友好,操作要简单,并具有较强的自我适应能力,即根据每人输入矩阵的方法不同,在生成矩阵时,程序能适当根据输入的各种格式来达到输入矩阵的功能;
<br>本程序为每个矩阵变量都分配一个矩阵变量名,用户可以通过操作矩阵变量来达到运算目的。如果用户对同一个矩阵变量定义了多次,则程序能根据系统内是否存在这个矩阵变量名,来给同一个矩阵变量进行多次赋值。
<br>本程序能根据矩阵表达式来进行表达式求解。也就是说程序能判定各个运算符的优先权,然后进行分析计算。
<br>结构分析:
<br>class CArrayMatrix : public CObject
<br>该类是Cobject类的派生类。是用来存储数据和进行一般矩阵运算的类。在vc用户手册中强烈建议如果程序自己定义的类,最要是从Cobject派生出来。详细原因请参考MSDN。
<br>数据成员:
<br> CArray<float,float &> m_Array;
<br> CString m_Name;
<br> UINT m_wRow;
<br> UINT m_wCon;
<br>m_Array是CArray类的一个对象,用来保存矩阵中每个元素的值。
<br>m_Name是一个字符串类的对象,用来保存矩阵对象的名称。
<br>m_wRow是用来保存矩阵的行数。
<br>m_wCon是用来保存矩阵的列数。
<br>成员函数:
<br>BOOL CArrayMatrix::CanAddSub(const CArrayMatrix &m)const
<br>这个函数是用来判断矩阵是否可以相加。如果是返回TRUE;反之返回FALSE。
<br>BOOL CArrayMatrix::CanContrary()const
<br>这个函数是用来判断矩阵是否可逆。如果是返回TRUE;反之返回FALSE。
<br>BOOL CArrayMatrix::CanMutiply(const CArrayMatrix &m)const
<br>这个函数是用来判断矩阵是否可相乘。如果是返回TRUE;反之返回FALSE。
<br>CArrayMatrix::CArrayMatrix()
<br>无参构造函数。
<br>CArrayMatrix::CArrayMatrix(const CArrayMatrix & m)
<br>拷贝构造函数。进行深拷贝。
<br>CArrayMatrix::~CArrayMatrix()
<br>析构函数。
<br>BOOL CArrayMatrix::ConvertToNum
<br>(const CString & sRowString, const int & nAtCon, float & fResult)//nAtCon从0---m_wCon-1
<br>此函数是把字符串中第nAtCon个子字符串转化成浮点型。
<br>void CArrayMatrix::DeleteHeadEnter(CString & RightString)
<br>void CArrayMatrix::ProcString(CString & RightString)
<br>void CArrayMatrix::ProcStringBlank(CString & sHead)
<br>void CArrayMatrix::ProcStringComma(CString & sHead)
<br>void CArrayMatrix::ProcStringEnter(CString & sHead)
<br>这些函数是用来过滤输入字符串的。
<br>BOOL CArrayMatrix::DisPlay(CString & out)const
<br>显示矩阵函数,把结果存到out里。
<br>CArrayMatrix CArrayMatrix::GetAccompany()const
<br>得到矩阵的伴随矩阵,并返回
<br>CString CArrayMatrix::GetName()
<br>得到矩阵的名称
<br>float CArrayMatrix::GetRange() const
<br>得到矩阵的行列式的值。
<br>BOOL CArrayMatrix::InputCon(const CString & RS,CString * &PtRSBuffer)
<br>根据过滤函数得出的字符串来给矩阵的类数赋值,并返回一个指向子字符串项的指针。
<br>BOOL CArrayMatrix::InputRow(const CString & RS)
<br>得到矩阵的行数。
<br>CArrayMatrix CArrayMatrix::operator *(float m)
<br>CArrayMatrix CArrayMatrix::operator *(const CArrayMatrix &m)
<br>如果乘法运算符重载。
<br>CArrayMatrix CArrayMatrix::operator +(const CArrayMatrix & m)
<br>矩阵加法运算符重载。
<br>CArrayMatrix CArrayMatrix::operator -(const CArrayMatrix & m)
<br>矩阵减法运算符重载。
<br>CArrayMatrix CArrayMatrix::operator /(float m)
<br>CArrayMatrix CArrayMatrix::operator / (CArrayMatrix &m)
<br>矩阵除法运算符重载。
<br>CArrayMatrix & CArrayMatrix::operator =(float m)
<br>CArrayMatrix & CArrayMatrix::operator =(const CArrayMatrix & m)
<br>矩阵赋值运算符重载。
<br>CArrayMatrix CArrayMatrix::operator ~()
<br>求逆运算符重载。
<br>BOOL CArrayMatrix::SetName(CString m)
<br>给矩阵对象名称赋值。
<br>BOOL CArrayMatrix::SetStringName(CString &DataString,CString & sName)
<br>自动截断输入字符串等号,右边是矩阵对象的数据部分,左边是矩阵对象的名称。
<br>CArrayMatrix CArrayMatrix::T()const
<br>求转置矩阵的函数。
<br>template<class T>
<br>class CStack:public CList<T,T &>
<br>标准栈类,是从链表类派生出来的。用来进行表达式求解时用到。
<br>程序测试:
<br>1、测试赋值和加法。
<br>输入数据:
<br>a=2 4 6 7
<br> 6 9 3 4
<br> 5 7 8 3
<br> 3 2 5 7;
<br>b=1 0 -1 2
<br>-1 1 3 0
<br>0 5 7 -6
<br>6 8 0 4;
<br>c=a+b;
<br>c=;
<br>输出结果:
<br>c=
<br>3 4 5 9
<br>5 10 6 4
<br>5 12 15 -3
<br>9 10 5 11 ;
<br>2、减法测试
<br>输入数据:
<br>d=c-b;
<br>d=;
<br>输出结果:
<br>d=
<br>2 4 6 7
<br>6 9 3 4
<br>5 7 8 3
<br>3 2 5 7 ;
<br>3、乘法测试
<br>输入数据:
<br>a=1 0 -1 2
<br>-1 1 3 0
<br>0 5 7 -6;
<br>b=0 -4
<br>1 2
<br>-3 -2
<br>-1 1;
<br>c=a*b;
<br>c=;
<br>输入结果:
<br>c=
<br>1 0
<br>-8 0
<br>-10 -10 ;
<br>4、求转置测试:
<br>输入:
<br>d=c';
<br>d=;
<br>输出:
<br>d=
<br>1 -8 -10
<br>0 0 -10 ;
<br>5、求逆
<br>输入:
<br>a=3 2 1
<br> 1 1 1
<br> 1 0 1;
<br>b=~a;
<br>b=;
<br>输出:
<br>b=
<br>0.5 -1 0.5
<br>0 1 -1
<br>-0.5 1 0.5 ;
<br>6、除法
<br>输入:
<br>a=1 2 -3
<br> 3 2 -4
<br> 2 -1 0;
<br>b=1 -3 0
<br> 10 2 7
<br> 10 7 8;
<br>c=b/a;
<br>c=;
<br>输出:
<br>c=
<br>20 -15 13
<br>-105 77 -58
<br>-152 112 -87 ;
<br>程序改进:
<br>本程序还须改进:
<br>1、 输入要求更灵活。
<br>2、 能进行矩阵的更多运算。
<br>3、 帮助系统更完善。
<br>由于时间仓促,本程序还存在很多不完善的地方,甚至是错误。所以还许更多的调试。
<br>
<br> 黄运新
<br> 计算机992
<br>
<br></td></tr> <br> </td> </tr> <tr align="right" valign="middle"> <td bgcolor="#FFFFFF" valign="bottom"> <input type=button onclick=window.close() value=关闭窗口 style='color: #000000; background-color: #ffffff'><br><br> </td> </tr> <tr align="right" valign="middle"> <td bgcolor="#FFFFFF" valign="middle" align="center"> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="99%" id="AutoNumber20" align="center"> <tr> <td background="../images/bg_dot.gif" colspan=10 height=1></td> </tr> </table> </td> </tr> <tr align="center" valign="middle"> <td bgcolor="#ffffff"> <br> <font color=red><b>特别声明:</b></font>文章版权归原作者所有, 未经允许请勿转载, 如有任何问题请<a href='mailto:webmaster@vczx.com'>联系我们</a>.<br><br> </td> </tr> </table> </td> </tr></table></body><center><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" align="center"><tr><td bgcolor="#666666" colspan=10 height=1></td></tr></table><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" ><tr><td width="100%"></td></tr></table><table border=0 cellPadding=0 cellSpacing=0 width=100% align="center"> <tr bgcolor="#f0f0f0"> <td valign="middle" align="center"><br> <a href="http://www.vczx.com" class="d" target="_self" title="Vczx.com Home"><font color=#000000>本站首页</font></a> | <a href="../sitemap.php" class="d" target="_self" title="Site Map"><font color=#000000>本站地图</font></a> | <a href="../aboutus.php" class="d" target="_self" title="About Vczx.com"><font color=#000000>关于本站</font></a> | <a href="../memorabilia.php" class="d" target="_self" title="Memorabilia of Vczx.com"><font color=#000000>本站大事记</font></a> | <a href="../copyright.php" class="d" target="_self" title="Copyright Announce"><font color=#000000>版权声明</font></a> | <a href="../link.php" class="d" target="_self" title="good-fellowship Link"><font color=#000000>友情链接</font></a> | <a href="../quote_ad.php" class="d" target="_self" title="Advertisement Operation "><font color=#000000>广告投放</font></a> | <a href="mailto:webmaster@vczx.com" class="d" title="Contact Us"><font color=#000000>联系我们</font></a> <br> <br> <font face='宋体' color='#000000'>Copyright © 2003-2004 <image src="http://www.vczx.com/images/footer_vczx.gif" width=55 height=10 border=0> Inc. All rights reserved.<br>本站由 loose_went 制作维护</font> </td> </tr><tr bgcolor="#f0f0f0"> <td valign="middle" align="center"> <script language="JavaScript1.2"> <!-- var correctwidth=1024 var correctheight=768 if (screen.width!=correctwidth||screen.height!=correctheight) document.write("<font color=#888888>本站最佳分辨率"+correctwidth+"*"+correctheight+",您当前的分辨率是"+screen.width+"*"+screen.height+".<br>设置合适的分辨率才能取得最佳的显示效果!</font>") //--> </script> </td></tr></table></center>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -