• 改写UMFPACK算例中的压缩方式(动态)


    在上篇博文基础上修改,使之A能动态

    View Code
    /* -------------------------------------------------------------------------- */
    /* UMFPACK Copyright (c) Timothy A. Davis, CISE,                              */
    /* Univ. of Florida.  All Rights Reserved.  See ../Doc/License for License.   */
    /* web: http://www.cise.ufl.edu/research/sparse/umfpack                       */
    /* -------------------------------------------------------------------------- */
    
    #include <stdio.h>
    #include "umfpack.h"
    #include<vector>
    #include<iostream>
    using namespace std;
    
    int main (void)
    {
        //int A[5][5]={{2,3,0,0,0},{3,0,4,0,6},{0,-1,-3,2,0},{0,0,1,0,0},{0,4,2,0,1}};
        int    n = 5 ;
        int    Ap [ ] = {0, 2, 5, 9, 10, 12} ;
        //int *Ap=new int [n+1];
        //Ap [ ]= {0, 2, 5, 9, 10, 12} ;
        int **A=new int *[n];
        for(int k=0;k<n;k++)
            A[k]= new int [n];
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                cin>>A[i][j];
        int Apm[6]={0};//相当于Ap
        double epsilon=0.00001;
        int NZnum=0;//矩阵非零元的个数
        vector<int> Axm;//相当于Ax
        vector<int> Aim;//相当于Ai
        for(int j=0;j<n;j++)
        {
            for(int i=0;i<n;i++)
            {
                if(abs(A[i][j])>epsilon)
                {
                    //Axm[NZnum]=A[i][j];printf("%d\n",Axm[NZnum]);
                    Axm.push_back(A[i][j]);
                    Aim.push_back(i);
                    NZnum++;
                }
            }
            Apm[j+1]=NZnum;
            //printf("%d\n",Apm[j+1]);
        }
        for (int i=0; i<int(Axm.size()); i++)
        {
            printf("%d ", Axm[i]);
        }
        cout<<endl;
        for (int i=0; i<int(Aim.size()); i++)
        {
            printf("%d ", Aim[i]);
        }
        cout<<endl;
        int    Ai [ ] = { 0,  1,  0,   2,  4,  1,  2,  3,   4,  2,  1,  4} ;
        double Ax [ ] = {2., 3., 3., -1., 4., 4., -3., 1., 2., 2., 6., 1.} ;
        double b [ ] = {8., 45., -3., 3., 19.} ;
        double x [5] ;
        double *null = (double *) NULL ;
        int i ;
        void *Symbolic, *Numeric ;
        (void) umfpack_di_symbolic (n, n, Ap, Ai, Ax, &Symbolic, null, null) ;
        (void) umfpack_di_numeric (Ap, Ai, Ax, Symbolic, &Numeric, null, null) ;
        umfpack_di_free_symbolic (&Symbolic) ;
        (void) umfpack_di_solve (UMFPACK_A, Ap, Ai, Ax, x, b, Numeric, null, null) ;
        umfpack_di_free_numeric (&Numeric) ;
        for (i = 0 ; i < n ; i++) printf ("x [%d] = %g\n", i, x [i]) ;
        return (0) ;
    }
  • 相关阅读:
    python字典实现原理-哈希函数-解决哈希冲突方法
    ElasticSearch-倒排索引
    ElasticSearch-核心概念
    MarkdownPad2基础语法
    下载python3.6,进行编译安装,运行django程序
    linux-指令1
    注解和反射
    Htlm和Css
    JAVASE加强
    网络编程
  • 原文地址:https://www.cnblogs.com/kmliang/p/2924176.html
Copyright © 2020-2023  润新知