//: [Previous](@previous) // Xcode で Editor メニュー > Show Render Markup でお読みください //import UIKit /*: # 中学1年の数学 */ /*: ## 比例と反比例 下欄の□ボタン「Execute/Stop Playground」で実行して、それぞれ右欄の Show Result ボタンを押してみよう */ print("関数 𝑦 = 𝑥 のグラフ") for x in -50...50 { let y = x print(x, y) } print("関数 𝑦 = -𝑥 のグラフ") for x in -50...50 { let y = -x print(x, y) } print("関数 𝑦 = 1/𝑥 のグラフ") for x in -50...50 { if (x != 0) { let y = 1.0/Double(x) print(x, y) } } print("関数 𝑦 = 1/𝑥 のグラフ、実数版") for x in stride(from: -0.5, through: 0.5, by: 0.01) { if (x <= -0.01 || 0.01 <= x) { let y = 1.0/x print(x, y) } } /*: #### ある一点を通る比例 (𝑥, y) を通る y = 𝑎𝑥 を求める 𝑎 = y/𝑥 である */ func 一点を通る比例の関数(_ x: Double, _ y: Double) -> Double { return y/x } for (x, y) in [ (1.0, -10.0), (1.0, -9.0), (1.0, -8.0), (1.0, -7.0), (1.0, -6.0), (1.0, -5.0), (1.0, -4.0), (1.0, -3.0), (1.0, -2.0), (1.0, -1.0), (1.0, 0.0), (1.0, 1.0), (1.0, 2.0), (1.0, 3.0), (1.0, 4.0), (1.0, 5.0), (1.0, 6.0), (1.0, 7.0), (1.0, 8.0), (1.0, 9.0), (1.0, 10.0), ] { let a = 一点を通る比例の関数(x, y) print("(𝑥, 𝑦) = (\(x), \(y): 𝑦 = \(a)𝑥") } for a in stride(from: 1.0, through: 10.0, by: 1.0) { for x in stride(from: -5.0, through: 5.0, by: 0.1) { let y = a*x y } } /*: #### ある一点を通る反比例 (𝑥, 𝑦) を通る 𝑦 = 𝑎/𝑥 を求める 𝑎 = 𝑥𝑦 である */ func 一点を通る反比例の関数(_ x: Double, _ y: Double) -> Double { return x*y } for (x, y) in [ (1.0, -10.0), (1.0, -9.0), (1.0, -8.0), (1.0, -7.0), (1.0, -6.0), (1.0, -5.0), (1.0, -4.0), (1.0, -3.0), (1.0, -2.0), (1.0, -1.0), (1.0, 0.0), (1.0, 1.0), (1.0, 2.0), (1.0, 3.0), (1.0, 4.0), (1.0, 5.0), (1.0, 6.0), (1.0, 7.0), (1.0, 8.0), (1.0, 9.0), (1.0, 10.0), ] { let a = 一点を通る反比例の関数(x, y) print("(𝑥, 𝑦) = (\(x), \(y): 𝑦 = \(a)/𝑥") } for a in stride(from: -10.0, through: 10.0, by: 1.0) { for x in stride(from: -5.0, through: 5.0, by: 0.1) { if -1 < x && x < 1 { continue } let y = a/x y } } //: [Next](@next)