您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 电子设计/PCB > 基于MATLAB的简易矩阵计算器
1《MATLAB程序设计》程序设计报告设计题目:简易矩阵计算器班级:021231姓名:余颖智学号:021230212目录1.设计目标……………………2.设计内容……………………3.设计思想……………………4.设计说明……………………5.设计步骤及程序代码……………………6.运行计算器……………………7.总结…………………………31.设计目标1.熟悉MATLAB的主要控件使用方法。2.熟悉MATLAB的GUI设计流程。2.设计内容设计一个简易的矩阵计算器,通过对简单应用矩阵计算器的设计,编制、调试实现矩阵相加减,矩阵的转置等简单运算,以学习应用MATLAB编写程序原理,加深对MATLAB的学习及应用。3.设计思想基于MATLAB中GUI界面的设计,通过创建类成员函数成员变量,编辑控件创建消息映射,调用信息函数完成数据的输入输出,实现计算功能。生成简单的应用软件。4.设计说明1)包含的功能有:加、减、乘、转置等。2)输入的原始数据分别为A或B矩阵,分别显示在不同标签中,运算的结果则显示在输出部分。3)计算功能基本上是用系统内部函数。4)程序能够自动判断输入数据的正确性,如不能输入(1)。5.设计步骤及只要代码1)打开MATLAB,点击,出现GUI的42)设计计算器版面直至53)对功能键进行设计执行A矩阵加B矩阵,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));[iAjA]=size(A);[iBjB]=size(B);ifiA~=iB|jA~=jB|(iA~=iB&jA~=jB)R='error.Matrixdimensionsmustagree.';set(handles.Answer,'string',R)guidata(hObject,handles);elseresult=A+B;R=num2str(result);set(handles.Answer,'string',R)guidata(hObject,handles);end6执行A矩阵减B矩阵,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));[iAjA]=size(A);[iBjB]=size(B);ifiA~=iB|jA~=jB|(iA~=iB&jA~=jB)R='error.Matrixdimensionsmustagree.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=A-B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行A矩阵与B矩阵相乘,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));[iAjA]=size(A);[iBjB]=size(B);ifjA~=iBR='error.Innermatrixdimensionsmustagree.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=A*B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行A右除B矩阵,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));[iAjA]=size(A);[iBjB]=size(B);ifiA~=iB、R='error.Matrixdimensionsmustagree.';set(handles.Answer,'String',R)guidata(hObject,handles);else7result=A\B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行A.*B,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));result=A.*B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);执行A./B,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));result=A./B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);执行A的转置,其执行代码如下A=eval((get(handles.Matrix_A,'String')));result=A';R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);执行A右除B,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));[iAjA]=size(A);[iBjB]=size(B);ifiA~=iBþR='error.Matrixdimensionsmustagree.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=A/B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end8执行求A的行列式,其执行代码如下A=eval((get(handles.Matrix_A,'String')));[iAjA]=size(A);ifiA~=jAR='error.Matrixmustbesquare.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=det(A);R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行求A的逆,其执行代码如下A=eval((get(handles.Matrix_A,'String')));[iAjA]=size(A);ifiA~=jAR='error.Matrixmustbesquare.';set(handles.Answer,'String',R)guidata(hObject,handles);elseifdet(A)==0R='error.Matrixissingulartoworkingprecision.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=inv(A);R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);endend执行求A的非共轭转置,其执行代码如下A=eval((get(handles.Matrix_A,'String')));result=A.';R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);9执行求解系数阵为方阵且非奇异的线性方程组,其执行代码如下A=eval((get(handles.Matrix_A,'String')));B=eval((get(handles.Matrix_B,'String')));[iAjA]=size(A);[iBjB]=size(B);ifiA~=iBR='error.';set(handles.Answer,'String',R)guidata(hObject,handles);elseifiA~=jAR='error.Matrixmustbesquare.';set(handles.Answer,'String',R)guidata(hObject,handles);elseifdet(A)==0R='error.Matrixissingulartoworkingprecision.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=A\B;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);endendend执行求A的秩,其执行代码如下A=eval((get(handles.Matrix_A,'String')));result=rank(A);R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);执行求A的平方,其执行代码如下A=eval((get(handles.Matrix_A,'String')));[iAjA]=size(A);ifiA~=jAR='error.Inputsmustbeascalarandasquarematrix.';set(handles.Answer,'String',R)guidata(hObject,handles);else10result=A^2;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行求A的立方,其执行代码如下A=eval((get(handles.Matrix_A,'String')));[iAjA]=size(A);ifiA~=jAR='error.Inputsmustbeascalarandasquarematrix.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=A^3;R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行求A的特征值,其执行代码如下A=eval((get(handles.Matrix_A,'String')));[iAjA]=size(A);ifiA~=jAR='error.Matrixmustbesquare.';set(handles.Answer,'String',R)guidata(hObject,handles);elseresult=eig(A);R=num2str(result);set(handles.Answer,'String',R)guidata(hObject,handles);end执行求A开平方根,其执行代码如下A=eval(get(handles.Matrix_
本文标题:基于MATLAB的简易矩阵计算器
链接地址:https://www.777doc.com/doc-5368595 .html