public static Variable Minus(Variable v1, Variable v2) { Variable newV2; if (v2.IsComplexDimension) { newV2 = new Variable(v2.Value * (-1), CloneDimension.Clone(v2.ComplexDimension)); } else { newV2 = new Variable(v2.Value * (-1), v2.Dimension); } return(ReturnVariable(v1, newV2)); }
public static Variable Multiplication(Variable v1, Variable v2) { var newV1 = toSiConvertor.Convert(v1); var newV2 = toSiConvertor.Convert(v2); var siDimensionV1 = Expan(newV1); var siDimensionV2 = Expan(newV2); var compositeDimension = CloneDimension.Clone(siDimensionV1); foreach (var item in siDimensionV2) { if (compositeDimension.ContainsKey(item.Key)) { if (compositeDimension[item.Key] + item.Value != 0) { compositeDimension[item.Key] += item.Value; } else { compositeDimension.Remove(item.Key); } } else { compositeDimension.Add(item.Key, item.Value); } } double newValue = newV1.Value * newV2.Value; if (compositeDimension.Count != 0) { return(new Variable(newValue, DimensionConvertor.Narrow(compositeDimension))); } else { return(new Variable(newValue, Si.ND)); } }
private static Variable Convert(Variable v, double coefficient, Dimension si, Dimension notSi) { if (!v.IsComplexDimension) { return(new Variable(v.Value * coefficient, si)); } else { var dimension = CloneDimension.Clone(v.ComplexDimension); var power = dimension[notSi]; dimension.Remove(notSi); dimension.Add(si, power); if (power > 0) { return(new Variable(v.Value * Math.Pow(coefficient, power), dimension)); } else { return(new Variable(v.Value / Math.Pow(coefficient, power * (-1)), dimension)); } } }
public Variable Convert(Variable v) { if (!v.IsComplexDimension && !v.Dimension.IsSi) { return(convertors[v.Dimension](v)); } else if (v.IsComplexDimension) { var newV = new Variable (v.Value, CloneDimension.Clone(v.ComplexDimension)); foreach (var item in v.ComplexDimension) { if (!item.Key.IsSi) { newV = convertors[item.Key](newV); } } return(newV); } return(v); }