您好,我正在以c-sharp windows格式创建行列式计算器,但是求和结果存在问题。 算法是: sum =(row11((row22 * row33)-(row23 * row32)))-(row12((row21 * row33)-(row23-row31)))+(row13((row21 * row32)-(row22-row31)) ));
例如,这是一个矩阵:| 1,2,3 | | 2,3,4 | | 5,6,7 | 结果应该为0,但在我的代码中我给25
const mongoose = require('mongoose');
const { Schema } = mongoose;
mongoose.Promise = global.Promise;
// document structure
const cartItemSchema = new Schema({
quantity: {
type: Number,
default: 1
},
item: {
type: mongoose.Schema.ObjectId,
ref: 'Item',
require: 'You must supply a item'
},
user: {
type: mongoose.Schema.ObjectId,
ref: 'User',
require: 'You must supply a user'
},
createdAt: {
type: Date,
default: Date.now
},
updatedAt: {
type: Date,
default: Date.now
}
});
function autopopulate(next) {
this.populate('item');
this.populate('user');
next();
}
cartItemSchema.pre('find', autopopulate);
cartItemSchema.pre('findOne', autopopulate);
// compile model and export
module.exports = mongoose.model('CartItem', cartItemSchema);
答案 0 :(得分:1)
通过分解行列式计算,您的样本中有0:
var determinant = a[0, 0] * (a[1, 1] * a[2, 2] - a[2, 1] * a[1, 2]) -
a[0, 1] * (a[1, 0] * a[2, 2] - a[2, 0] * a[1, 2]) +
a[0, 2] * (a[1, 0] * a[2, 1] - a[2, 0] * a[1, 1]);