是的,@ TheSoundDefense是对的。 Swift Sandbox没有直接绘图输出。但是,我建议你仍然使用Swift Sandbox。只需运行代码,然后将输出以逗号分隔的格式复制并粘贴到Excel或MATLAB中以绘制它。我做了一些调整你的sum2作为一个例子,同时也使它在这个过程中更具功能性:
func sum2(N: Int) -> Float { let a: Float = (1...N).reduce(0) { let nDouble = Double($1) return Float((2.0 * nDouble - 1) / (2.0 * nDouble)) + $0 } let b: Float = (1...N).reduce(0) { let nDouble = Double($1) return Float((2.0 * nDouble) / (2.0 * nDouble + 1)) + $0 } return b - a } let N = 10 let out = (1...N).map(){ sum2(N: $0)} let output = out.reduce(""){$0 + "\($1), "} print(output)
0.166667,0.216667,0.240476,0.254365,0.263456,0.269867,0.274629,0.278306,0.28123,0.2383611,