Guest User

Untitled

a guest
May 25th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use Chart::Gnuplot;
  6.  
  7. # perque no funciona" sub f { shift**2 } "?
  8. sub f {
  9. my $x = shift;
  10. return $x ** 2
  11. }
  12.  
  13. my @values = -10..10; #interval de 1
  14.  
  15. # Per donar millor frequencia de mostreig de la senyal seria genial
  16. # que el operador .. tingues un tercer parametre, per exemple
  17.  
  18. # my @values = -10..10|0.1 -10,-9.9,-9.8...9.8,9.9,10
  19.  
  20. # contemplant possibles problemes amb els rangs.
  21. # Si no,s'hauria de fer la funcio que va sumant el 0.1 desde -10 fins a 10 i contemplant
  22. # els casos de truncament i les excepcions. O hi ha una altra manera?
  23.  
  24.  
  25. my @fvalues = map {f($_)} @values;
  26.  
  27.  
  28. my $chart = Chart::Gnuplot->new(
  29. output => "discretequadratic.png",
  30. title => "test",
  31. xlabel => "My x-axis label",
  32. ylabel => "My y-axis label",
  33. );
  34.  
  35. # Create dataset object and specify the properties of the dataset
  36. my $dataSet = Chart::Gnuplot::DataSet->new(
  37. xdata => \@values,
  38. ydata => \@fvalues,
  39. style => "points",
  40. );
  41.  
  42. # Plot the data set on the chart
  43. $chart->plot2d($dataSet);
Add Comment
Please, Sign In to add comment