高斯消元法java语言设计_高斯消元法的简单实现

1 #ifndef GAUSS_ELIMINATION_H2 #define GAUSS_ELIMINATION_H

3

4 #include

5 #include

6 #include

7 #include

9 #include

10 #include

11 #include

12 #include

13 #include //a private matrix library

14

15 namespacejtf{16 namespacealgorithm{17

18 /**19 * @brief store an expression A * i, where A is the coeffieient20 *21 */

22 template

23 classexpression{24 public:25 expression():index(-1),coefficient(0){}26 expression(const size_t & index_, const T &coefficient_)27 : index(index_), coefficient(coefficient_){}28 size_t index;29 T coefficient;30 /**31 * @brief operator < is used to determin which expression ha32 *33 * @param other input other expression34 * @return bool35 */

36 bool operator < (const expression & b) const{37 return index

40 /**41 * @brief To determin whether coefficent of this expression is zeros42 *43 * @return bool44 */

45 bool is_zero() const{ return fabs(coefficient) < 1e-6;}46 };47

48 /**49 * @brief make expression with node_idx and value50 *51 * @param node_idx52 * @param value53 * @return expression54 */

55 template

56 expression make_expression(const size_t & node_idx, const T &value)57 {58 expressiontemp(node_idx, value);59 returntemp;60 }61

62 /**63 * @brief equation class64 *65 */

66 template

67 classequation{68 public:69 typedef typename std::list >::const_iterator eq_const_iterator;70 typedef typename std::list >::iterator eq_iterator;71

72 equation():value_(static_cast(0)){}73

74 eq_const_iterator begin() const {returne_vec_.begin();}75 eq_iterator begin(){returne_vec_.begin();}76

77 eq_const_iterator end() const {returne_vec_.end();}78 eq_iterator end(){returne_vec_.end();}79

80 /**81 * @brief used to standardizate the equation, sort the expressions and merge82 * similar items and normalization to make the first item's coefficient83 * equal 184 *85 * @return int86 */

87 intstandardization(){88 sort_equation();89 merge_similar();90 normalization();91 return 0;92 }93

94 /**95 * @brief update the equation with given node idx and value96 *97 * @param node_idx input node idx98 * @param node_value input node value99 * @return int100 */

101 int update(const size_t & node_idx, const T &node_value);102 /**103 * @brief sort equation accronding to the expressions104 *105 * @return int106 */

107 intsort_equation(){108 e_vec_.sort();109 return 0;110 }111

112 /**113 * @brief merge similar items, WARNING. this function should be used after114 * sorting.115 *

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值