77范文网 - 专业文章范例文档资料分享平台

矩阵乘法

来源:网络收集 时间:2018-11-14 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

矩阵乘法

一.程序代码

#include using namespace std; typedef int Script; struct node{

Script data; node *next; }; class List {

private: node *head; node *tail; int n; public:

List(); void Destroy();

Script Get(int index); void Add(Script data); node * Index(int index); }; List::List() {

head=NULL; tail=NULL; n=0;

}

void List::Add(Script data) {

node *p=new node; p->data=data; p->next=NULL; if(head==NULL) { } else {

tail->next=p; tail=p; head=tail=p;

}

n++; }

void List::Destroy() { }

node *p;

while(head!=NULL) { }

p=head;

head=head->next; delete p;

tail=NULL;

node * List::Index(int index) {

if(index<=n&&index>0) { node *p=head; }

node *p1=head; while(--index) { }

p1=p1->next; p=p1;

return p;

return NULL; }

Script List::Get(int index) {

if(index<=n&&index>0) { }

node *p=Index(index); return p->data;

return -999;

}

class Juzhen { public: int dim; List *list; public:

Juzhen();

Juzhen(int dd,Script *ps); void Destroy();

Juzhen operator *(Juzhen v); Script Get(int m,int n); void Print();

void operator =(Juzhen v);

};

Juzhen::Juzhen() {

dim=0; list=NULL;

}

Juzhen::Juzhen(int d,Script *pn) {

if(d>0) { } else { }

Juzhen(); int i=0; dim=d; list=new List(); int num=d*d; while(num) { list->Add(pn[i]); i++; }

num--;

}

void Juzhen::Destroy() { }

Juzhen Juzhen::operator *(Juzhen v) {

int data=0; Juzhen newV; if(list!=NULL)

list->Destroy(); this->dim=0; list=NULL;

newV.dim=dim; newV.list=new List(); int num=dim*dim; for(int i=0;i

for(int j=0;j

for(int k=0;k

int m=i*dim+k+1,n=j*dim+k+1;

data+=list->Get(i*dim+k+1)*v.list->Get(k*dim+j+1);

newV.list->Add(data); data=0;

return newV; }

void Juzhen::operator=(Juzhen v) {

dim=v.dim;

list=v.list; }

Script Juzhen::Get(int m,int n) {

int num=(m-1)*dim+n; return list->Get(num);

}

void Juzhen::Print() { } int main() {

int n=0;

cout<<\请输入矩阵维数:\for(int i=0;i

for(int j=0;j

cout<

int m=this->Get(i+1,j+1); cout<

}

cin>>n;

Script *A=new Script[n*n]; Script *B=new Script[n*n]; cout<

cout<<\请输入矩阵A:\for(int i=0;i

for(int j=0;j

cout<<\cin>>A[i*n+j];

}

cout<

cout<<\请输入矩阵B:\for(i=0;i

for(int j=0;j

cout<<\cin>>B[i*n+j];

Juzhen jz1(n,&A[0]); Juzhen jz2(n,&B[0]);

Juzhen jz3=jz1*jz2; cout<

cout<<\矩阵A*矩阵B=\jz3.Print(); return 0;

二,结果截图

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库矩阵乘法在线全文阅读。

矩阵乘法.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/273575.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: