| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 837 人关注过本帖
标题:大型稀疏矩阵非零系数的确定?
只看楼主 加入收藏
w2009w
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:190
专家分:542
注 册:2015-4-20
结帖率:100%
收藏
 问题点数:0 回复次数:4 
大型稀疏矩阵非零系数的确定?
大型稀疏矩阵的形式:程序代码运行带这一段就终止了,检查好几遍,看不不出错误,求指点!
图片附件: 游客没有浏览图片的权限,请 登录注册

图片附件: 游客没有浏览图片的权限,请 登录注册

for(i=0;i<(P+1)*(N+1);i++)
coefficients.push_back(Tri(i,i,1.0));  //第一个i表示A矩阵中的行数,第二个i表示A矩阵中的列数,1.0表示非零元素的系数
    //矩阵A中的中间行

    for(i=(P+1)*(N+1);i<SMADi-(P+1)*(N+1);i++)
    {
        k=i%(P+1)*(N+1);
        
        //矩阵A中每一个B矩阵中的首行

        for(k=0;k<P+1;k++)
        {
            //矩阵B中首行的每一个a矩阵中的首行
            if(k==0)   
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i+1,2.0));
                coefficients.push_back(Tri(i,i+(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
            }

            //矩阵B中首行的每一个a矩阵中的末行
            
            else if(k==P)
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,2.0));
                coefficients.push_back(Tri(i,i+(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
            }

            //矩阵B中首行的每一个a矩阵中的中间行
            
            else
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,1.0));
                coefficients.push_back(Tri(i,i+1,1.0));
                coefficients.push_back(Tri(i,i+(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
            }

        }
        //矩阵A中每一个B矩阵中的中间行

        for(k=P+1;k<N*(P+1);k++)
        {
            for(int m=1;m<N;m++)
            {
            //矩阵B中首行的每一个a矩阵中的首行

                if(k==m*(P+1))
                {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i+1,2.0));
                coefficients.push_back(Tri(i,i-(P+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1),1.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
                }

            //矩阵B中首行的每一个a矩阵中的末行
               
                else if(k==m*(P+1)+P)
                {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,2.0));
                coefficients.push_back(Tri(i,i-(P+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1),1.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
                }

            //矩阵B中首行的每一个a矩阵中的中间行
            
                else
                {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,1.0));
                coefficients.push_back(Tri(i,i+1,1.0));
                coefficients.push_back(Tri(i,i-(P+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1),1.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
                }
            }

        }

        //矩阵A中每一个B矩阵中的末行

        for(k=N*(P+1);k<(N+1)*(P+1);k++)
        {
        
            //矩阵B中首行的每一个a矩阵中的首行

            if(k==N*(P+1))   
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i+1,2.0));
                coefficients.push_back(Tri(i,i-(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
            }

            //矩阵B中首行的每一个a矩阵中的末行
            
            else if(k==(N+1)*(P+1)-1)
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,2.0));
                coefficients.push_back(Tri(i,i-(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
            }

            //矩阵B中首行的每一个a矩阵中的中间行
            
            else
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,1.0));
                coefficients.push_back(Tri(i,i+1,1.0));
                coefficients.push_back(Tri(i,i-(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),1.0));
                coefficients.push_back(Tri(i,i+(P+1)*(N+1),1.0));
            }

        }
        
    }

    //矩阵A中的末行

    for(i=SMADi-(P+1)*(N+1);i<SMADi;i++)
    {
        //B矩阵中的首行

        for(i=SMADi-(P+1)*(N+1);i<SMADi-(P+1)*N;i++)
        {
            if(i==SMADi-(P+1)*(N+1))
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i+1,2.0));
                coefficients.push_back(Tri(i,i+(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
            }

            else if(i==SMADi-(P+1)*N-1)
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,2.0));
                coefficients.push_back(Tri(i,i+(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
            }

            else
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,1.0));
                coefficients.push_back(Tri(i,i+1,1.0));
                coefficients.push_back(Tri(i,i+(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
            }
            
        }
        //B矩阵的中间行

        for(i=SMADi-N*(P+1);i<SMADi-(P+1);i++)
        {
            for(int k=0;k<N-1;k++)
            {
                if(i==SMADi-(N-k)*(P+1))
                {
                    coefficients.push_back(Tri(i,i,-6.0));
                    coefficients.push_back(Tri(i,i+1,2.0));
                    coefficients.push_back(Tri(i,i-(P+1),1.0));
                    coefficients.push_back(Tri(i,i+(P+1),1.0));
                    coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
                }
                else if(i==SMADi-(N-k)*(P+1)+P)
                {
                    coefficients.push_back(Tri(i,i,-6.0));
                    coefficients.push_back(Tri(i,i-1,2.0));
                    coefficients.push_back(Tri(i,i-(P+1),1.0));
                    coefficients.push_back(Tri(i,i+(P+1),1.0));
                    coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
                }
                else
                {
                    coefficients.push_back(Tri(i,i,-6.0));
                    coefficients.push_back(Tri(i,i-1,1.0));
                    coefficients.push_back(Tri(i,i+1,1.0));
                    coefficients.push_back(Tri(i,i-(P+1),1.0));
                    coefficients.push_back(Tri(i,i+(P+1),1.0));
                    coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
                }
            }
            
        }

        //B矩阵中的末行

        for(i=SMADi-(P+1);i<SMADi;i++)
        {
            if(i==SMADi-(P+1))
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i+1,2.0));
                coefficients.push_back(Tri(i,i-(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
            }

            else if(i==SMADi-1)
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,2.0));
                coefficients.push_back(Tri(i,i-(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
            }

            else
            {
                coefficients.push_back(Tri(i,i,-6.0));
                coefficients.push_back(Tri(i,i-1,1.0));
                coefficients.push_back(Tri(i,i+1,1.0));
                coefficients.push_back(Tri(i,i-(P+1),2.0));
                coefficients.push_back(Tri(i,i-(P+1)*(N+1),2.0));
            }
            
        }

    }
搜索更多相关主题的帖子: 元素 
2015-05-30 21:00
w2009w
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:190
专家分:542
注 册:2015-4-20
收藏
得分:0 
没人帮我检查一下啊!看来只能自己奋斗了!
2015-05-31 13:43
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:0 
大型稀疏矩阵的单位形式如何定义的?
说一下你定义的结构形式

剑栈风樯各苦辛,别时冰雪到时春
2015-06-02 17:02
lianyicq
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:26
帖 子:737
专家分:3488
注 册:2013-1-26
收藏
得分:0 
如果是找矩阵A的非零系数。
A是(P+1)*(N+1)*(M+1)阶方阵
首先能不能找A中任意第i列,j行元素A(i,j)对应于a,b,c中的某行某列。
A由B、C组合而来,没有加减。系数非零和零不会互变。

大开眼界
2015-06-02 17:25
w2009w
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:2
帖 子:190
专家分:542
注 册:2015-4-20
收藏
得分:0 
谢谢你们的回复,差不多弄对了!Thank you again!
2015-06-02 19:47
快速回复:大型稀疏矩阵非零系数的确定?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020846 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved