数学2、指数関数、対数関数、三角関数

ruby
math
code
Author

geeknees

Published

July 23, 2023

require "charty"
require "datasets"
require "numo/narray"
false
{
  Charty::VERSION,
  Datasets::VERSION,
  Numo::NArray::VERSION
}
{:charty=>"0.2.12", :datasets=>"0.1.7", :numo_narray=>"0.9.2.1"}
Charty::Backends.use()
:plotly
penguins = Datasets::Penguins.new

plot = Charty.scatter_plot(penguins, , , )

sin-cos-tan

charty = Charty::Plotter.new()
#<Charty::Plotter:0x000000013d0dab18 @backend=#<Charty::Backends::Gruff:0x000000013efb60a0 @plot=Gruff>>
curve = charty.curve do
  function {|x| Math.sin(x) }
  range 0..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/sin.png")

curve = charty.curve do
  function {|x| Math.cos(x) }
  range 0..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/cos.png")

curve = charty.curve do
  function {|x| Math.tan(x) }
  range 0..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/tan.png")

squrt-log

curve = charty.curve do
  function {|x| Math.log(x) }
  range 1..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/log.png")

curve = charty.curve do
  function {|x| Math.log2(x) }
  range 1..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/log2.png")

curve = charty.curve do
  function {|x| Math.log10(x) }
  range 1..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/log10.png")

curve = charty.curve do
  function {|x| Math.sqrt(x) }
  range 0..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/sqrt.png")

curve = charty.curve do
  function {|x| Math.exp(x) }
  range 0..10, -1..1
  xlabel 'foo'
  ylabel 'bar'
end
curve.render("sample_images/exp.png")