Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Spring
- RaspberryPi
- boj
- ruby2d
- Android
- jetbrains
- rubymine
- 개발노트
- 루비
- gradle
- JS
- ruby
- Vane
- C
- error
- kotlin
- Godot
- Python
- maven
- IntelliJ
- CPP
- react
- Java
- OAuth
- gnuplot
- Shell
- plugin
- GitHub
- OTLanguage
- Baekjoon
Archives
- Today
- Total
PersesTitan(페르) 기술블로그
[Ruby] 루비로 tan 그래프 구현하기 본문
관련된 글
[Ruby] 루비로 sin 그래프 구현하기
[Ruby] 루비로 cos 그래프 구현하기
[Ruby] 루비로 sin 그래프 구현하기
관련된 글 [Ruby] 루비에서 그래프 구현하기 (gnuplot 설치) [Ruby] 루비에서 그래프 구현하기 (gnuplot 설치) 먼저 homebrew가 설치가 되어 있어야합니다. 그리고 아래 커맨드를 터미널에 입력해서 gnuplot를
persestitan.tistory.com
[Ruby] 루비로 cos 그래프 구현하기
관련된 글 [Ruby] 루비로 sin 그래프 구현하기 [Ruby] 루비로 sin 그래프 구현하기 관련된 글 [Ruby] 루비에서 그래프 구현하기 (gnuplot 설치) [Ruby] 루비에서 그래프 구현하기 (gnuplot 설치) 먼저 homebrew가
persestitan.tistory.com
풀이
sin과 cos과 마찬가지로 tan또한 tan을 사용하면 됩니다. 하지만 그래프가 이상하게 나오는 것 처럼 보이는데 tan는 점근선이 존재하기 때문에 점근선이상의 값을 가지게 된다면 출력1과 같이 그래프가 이상하게 나오게 됩니다.
따라서 점근선까지 범위를 제한하면 원하는 그래프를 출력할 수 있게 됩니다.
pi/2까지가 점근선이므로 단순하게 계산하여 pi를 3으로 생각하고 1.5를 범위를 지정하여 출력2와 같이 수정하였습니다.
코드1
require 'gnuplot'
Gnuplot.open do |g|
Gnuplot::Plot.new(g) do |plot|
x = (-5..5).step(0.1).collect { |v| v.to_f.round 1 }
y = x.collect { |v| Math.tan v }
plot.y
plot.data << Gnuplot::DataSet.new([x, y]) do |d|
d.with = "lines"
d.linewidth = 2
end
end
end
출력1
코드2
require 'gnuplot'
Gnuplot.open do |g|
Gnuplot::Plot.new(g) do |plot|
x = (-1.5..1.5).step(0.1).collect { |v| v.to_f.round 1 }
y = x.collect { |v| Math.tan v }
plot.y
plot.data << Gnuplot::DataSet.new([x, y]) do |d|
d.with = "lines"
d.linewidth = 2
end
end
end
출력2
'Language > Ruby' 카테고리의 다른 글
[Ruby] 루비 Gem 배포하는 법 (0) | 2023.12.09 |
---|---|
[Ruby] 루비 팩토리얼 함수 만들기 (0) | 2023.12.01 |
[Ruby] 루비로 cos 그래프 구현하기 (0) | 2023.04.12 |
[Ruby] 루비로 sin 그래프 구현하기 (0) | 2023.04.12 |
[Ruby] 루비에서 그래프 구현하기 (gnuplot 설치) (0) | 2023.04.12 |