File: evaluate.pl

package info (click to toggle)
libmath-utils-perl 1.14-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 252 kB
  • sloc: perl: 937; makefile: 8
file content (35 lines) | stat: -rwxr-xr-x 507 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/perl
#
#
use Carp;
use Math::Utils qw(:polynomial);
use Math::Complex;
use strict;
use warnings;

while (my $line = prompt("Polynomial: "))
{
	my @polynomial = split(/[, ] */, $line);

	$line = prompt("X values: ");
	last unless ($line);
	my(@xvals) = split(/,? /, $line);

	my(@yvals) = pl_evaluate(\@polynomial, \@xvals);

	for my $j (0 .. $#yvals)
	{
		print $xvals[$j], ", ", $yvals[$j], "\n";
	}
}
exit(0);


sub prompt
{
	my $pr = shift;
	print $pr;
	my $inp = <>;
	chomp $inp;
	return $inp;
}