The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Math::LinearCombination - sum of variables with a numerical coefficient

SYNOPSIS

  use Math::LinearCombination;
  use Math::SimpleVariable; # for the variable objects

  # build a linear combination
  my $x1 = new Math::SimpleVariable(name => 'x1');
  my $x2 = new Math::SimpleVariable(name => 'x2');
  my $lc = new Math::LinearCombination();
  $lc->add_entry(var => $x1, coeff => 3.0);
  $lc->add_entry(var => $x2, coeff => 1.7);
  $lc->add_entry(var => $x2, coeff => 0.3); # so x2 has a coefficient of 2.0
  print $lc->stringify(), "\n";

  # do some manipulations
  $lc->negate_inplace(); # reverts the coefficient signs
  $lc->multiply_with_constant_inplace(2.0); # doubles all coefficients
 
  # evaluate the linear combination
  $x1->{value} = 3;
  $x2->{value} = -1;
  print $lc->evaluate(), "\n"; # prints -14

DESCRIPTION

Math::LinearCombination is a module for representing mathematical linear combinations of variables, i.e. expressions of the format

  a1 * x1 + a2 * x2 + ... + an * xn

with x1, x2, ..., xn variables, and a1, a2, ..., an numerical coefficients. Evaluation and manipulation of linear combinations is also supported.

... STILL TO BE FINISHED

SEE ALSO

perl(1).

VERSION

This is version $Revision: 1.10 $ of Math::LinearCombination, last edited at $Date: 2001/07/18 12:50:50 $.

AUTHOR

Wim Verhaegen <wimv@cpan.org>

COPYRIGHT

Copyright (C) 2001 Wim Verhaegen. All rights reserved. This program is free software; you may redistribute and/or modify it under the same terms as Perl itself.