diff --git a/prism/src/explicit/StateValues.java b/prism/src/explicit/StateValues.java index a7366057..31f010cf 100644 --- a/prism/src/explicit/StateValues.java +++ b/prism/src/explicit/StateValues.java @@ -1267,6 +1267,22 @@ public class StateValues implements StateVector } } + /** + * Compute dot (inner) product of this and another vector {@code sv}. + */ + public double dotProduct(StateValues sv) throws PrismException + { + if (type instanceof TypeDouble) { + double dotProduct = 0; + for (int i = 0; i < size; i++) { + dotProduct += valuesD[i] * sv.valuesI[i]; + } + return dotProduct; + } else { + throw new PrismException("Dot product can only be applied to double vectors"); + } + } + /** * Set the elements of this vector by reading them in from a file. */