function [ a, rhsval ] = hb_to_msm ( input_file )
%*****************************************************************************80
%
%% HB_TO_MSM reads a matrix and right hand side from an HB file.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 20 January 2014
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, string INPUT_FILE, the name of the file containing the
% Harwell-Boeing matrix data.
%
% Output, real A(M,N), a sparse matrix in MATLAB sparse matrix format.
%
% Output, real RHSVAL(M,NRHS), right hand side vectors.
%
input_unit = fopen ( input_file );
if ( input_unit < 0 )
fprintf ( 1, '\n' );
fprintf ( 1, 'HB_TO_MSM - Fatal error!\n' );
fprintf ( 1, ' Error opening the file.\n' );
error ( 'HB_TO_MSM - Fatal error!' );
end
[ title, key, totcrd, ptrcrd, indcrd, valcrd, rhscrd, mxtype, ...
nrow, ncol, nnzero, neltvl, ptrfmt, indfmt, valfmt, rhsfmt, rhstyp, ...
nrhs, nrhsix, colptr, rowind, values, rhsval, rhsptr, rhsind, guess, ...
exact ] = hb_file_read ( input_unit );
for col = 1 : ncol
for k = colptr(col) : colptr(col+1)-1
colind(k) = col;
end
end
a = sparse ( rowind, colind, values, nrow, ncol );
fclose ( input_unit );
return
end
function c = ch_cap ( c )
%*****************************************************************************80
%
%% CH_CAP capitalizes a single character.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 22 November 2003
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, character C, the character to capitalize.
%
% Output, character C, the capitalized character.
%
if ( 'a' <= c & c <= 'z' )
c = c + 'A' - 'a';
end
return
end
function truefalse = ch_eqi ( c1, c2 )
%*****************************************************************************80
%
%% CH_EQI is a case insensitive comparison of two characters for equality.
%
% Example:
%
% CH_EQI ( 'A', 'a' ) is TRUE.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 28 July 2000
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, character C1, C2, the characters to compare.
%
% Output, logical TRUEFALSE, is TRUE (1) if the characters are equal.
%
FALSE = 0;
TRUE = 1;
if ( ch_cap ( c1 ) == ch_cap ( c2 ) )
truefalse = TRUE;
else
truefalse = FALSE;
end
return
end
function truefalse = ch_is_digit ( c )
%*****************************************************************************80
%
%% CH_IS_DIGIT returns TRUE if the character C is a digit.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 11 December 2003
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, character C, a character.
%
% Output, integer TRUEFALSE, is TRUE (1) if C is a digit, FALSE (0) otherwise.
%
TRUE = 1;
FALSE = 0;
if ( '0' <= c & c <= '9' )
truefalse = TRUE;
else
truefalse = FALSE;
end
return
end
function truefalse = ch_is_format_code ( c )
%*****************************************************************************80
%
%% CH_IS_FORMAT_CODE returns TRUE if a character is a FORTRAN format code.
%
% Discussion:
%
% The format codes accepted here are not the only legal format
% codes in FORTRAN90. However, they are more than sufficient
% for my needs!
%
% Table:
%
% A Character
% B Binary digits
% D Real number, exponential representation
% E Real number, exponential representation
% F Real number, fixed point
% G General format
% I Integer
% L Logical variable
% O Octal digits
% Z Hexadecimal digits
% * Free format
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 21 November 2003
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, character C, the character to be analyzed.
%
% Output, logical TRUEFALSE, is TRUE (1) if C is a FORTRAN format code
% and FALSE (0) otherwise.
%
FALSE = 0;
TRUE = 1;
if ( ch_eqi ( c, 'A' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'B' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'D' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'E' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'F' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'G' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'I' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'L' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'O' ) )
truefalse = TRUE;
elseif ( ch_eqi ( c, 'Z' ) )
truefalse = TRUE;
elseif ( c == '*' )
truefalse = TRUE;
else
truefalse = FALSE;
end
return
end
function digit = ch_to_digit ( c )
%*****************************************************************************80
%
%% CH_TO_DIGIT returns the integer value of a base 10 digit.
%
% Example:
%
% C DIGIT
% --- -----
% '0' 0
% '1' 1
% ... ...
% '9' 9
% ' ' 0
% 'X' -1
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 22 November 2003
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, character C, the decimal digit, '0' through '9' or blank
% are legal.
%
% Output, integer DIGIT, the corresponding integer value. If C was
% 'illegal', then DIGIT is -1.
%
if ( '0' <= c & c <= '9' )
digit = c - '0';
elseif ( c == ' ' )
digit = 0;
else
digit = -1;
end
return
end
function exact = hb_exact_read ( input_unit, nrow, nrhs, rhscrd, rhsfmt, rhstyp )
%*****************************************************************************80
%
%% HB_EXACT_READ reads the exact solution vectors in an HB file.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 04 February 2005
%
% Author:
%
% John Burkardt
%
% Reference:
%
% Iain Duff, Roger Grimes, John Lewis,
% User's Guide for the Harwell-Boeing Sparse Matrix Collection,
% October 1992.
%
% Parameters:
%
% Input, integer INPUT_UNIT, the unit from which data is read.
%
% Input, integer NROW, the number of rows or variables.
%
% Input, integer NRHS, the number of right hand sides.
%
% Input, integer RHSCRD, the number of lines in the file for
% right hand sides.
%
% Input, character ( len = 20 ) RHSFMT, the format for reading values
% of the right hand side.
%
% Input, character ( len = 3 ) RHSTYP, the right hand side type.
% First character is F for full storage or M for same as matrix.
% Second character is G if starting "guess" vectors are supplied.
% Third character is X if exact solution vectors are supplied.
% Ignored if NRHS = 0.
%
% Output, real EXACT(NROW,NRHS), the exact solution vectors.
%
exact = [];
if ( 0 < rhscrd )
if ( rhstyp(3) == 'X' )
[ p, code, w, m ] = s_to_format ( rhsfmt );
line_num = 1 + floor ( ( nrow - 1 ) / p );
for irhs = 1 : nrhs
jhi = 0;
for i = 1 : line_num
line = fgetl ( input_unit );
jlo = jhi + 1;
jhi = min ( jlo + p - 1, nrow );
khi = 0;
for j = jlo : jhi
klo = khi + 1;
khi = min ( klo + w - 1, length ( line ) );
s = line(klo:khi);
exact(j,irhs) = str2num ( s );
end
end
end
end
end
return
end
function [ title, key, totcrd, ptrcrd, indcrd, valcrd, rhscrd, mxtype, ...
nrow, ncol, nnzero, neltvl, ptrfmt, indfmt, valfmt, rhsfmt, rhstyp, ...
正则化方法matlab程序
1星 需积分: 43 100 浏览量
2018-04-16
10:41:44
上传
评论 17
收藏 22KB ZIP 举报
wmy234
- 粉丝: 2
- 资源: 1
最新资源
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈