Skip to content

Instantly share code, notes, and snippets.

def integrate(E, x_low, x_high, delta, V, plot=True):
def f(x):
return 2.0 * (V(x) - E)
delta_sq = delta ** 2
N = int((x_high - x_low) / delta)
psi_left = 0.0
# psi_right = 0.0
psi_first = 1.0
infinite_well = {
"x_low": -1.0,
"x_high": 1.0,
"delta": 0.002,
"V": lambda x: 0.0
}
psi = integrate(E=1.0, **infinite_well)
def deviation(psi_computed, psi_actual):
return psi_computed - psi_actual
def find_energy_eigenstate(E_low, E_high, integration_params):
psi_right = 0.0
psi_low = integrate(E_low, **integration_params)
psi_high = integrate(E_high, **integration_params)
dev_low = deviation(psi_low[-1], psi_right)
dev_high = deviation(psi_high[-1], psi_right)
@ilamanov
ilamanov / PieSliceView.swift
Created April 25, 2021 04:26
Creating SwiftPieChart: PieSliceData
import SwiftUI
struct PieSliceView: View {
var body: some View {
Text("Hello, World!")
}
}
struct PieSliceData {
var startAngle: Angle
@ilamanov
ilamanov / PieSliceView.swift
Created April 25, 2021 04:38
Creating SwiftPieChart: PieSliceView
struct PieSliceView: View {
var pieSliceData: PieSliceData
var body: some View {
GeometryReader { geometry in
Path { path in
let width: CGFloat = min(geometry.size.width, geometry.size.height)
let height = width
let center = CGPoint(x: width * 0.5, y: height * 0.5)
@ilamanov
ilamanov / PieSliceView.swift
Created April 25, 2021 04:42
Creating SwiftPieChart: testing slice
struct PieSliceView_Previews: PreviewProvider {
static var previews: some View {
PieSliceView(pieSliceData: PieSliceData(
startAngle: Angle(degrees: 0.0),
endAngle: Angle(degrees: 220.0),
color: Color.black))
}
}
@ilamanov
ilamanov / PieSliceView.swift
Created April 25, 2021 04:47
Creating SwiftPieChart: PieSliceView complete
struct PieSliceView: View {
var pieSliceData: PieSliceData
var midRadians: Double {
return Double.pi / 2.0 - (pieSliceData.startAngle + pieSliceData.endAngle).radians / 2.0
}
var body: some View {
GeometryReader { geometry in
ZStack {
@ilamanov
ilamanov / PieChartView.swift
Created April 25, 2021 22:21
Creating SwiftPieChart: PieChartView init
import SwiftUI
struct PieChartView: View {
public let values: [Double]
public var colors: [Color]
var slices: [PieSliceData] {
let sum = values.reduce(0, +)
var endDeg: Double = 0
var tempSlices: [PieSliceData] = []
@ilamanov
ilamanov / PieChartView.swift
Created April 25, 2021 22:30
Creating SwiftPieChart: PieChartView combination
struct PieChartView: View {
public let values: [Double]
public var colors: [Color]
public var backgroundColor: Color
var slices: [PieSliceData] {
let sum = values.reduce(0, +)
var endDeg: Double = 0
var tempSlices: [PieSliceData] = []
@ilamanov
ilamanov / PieChartView.swift
Created April 25, 2021 22:38
Creating SwiftPieChart: inner circle
var body: some View {
GeometryReader { geometry in
ZStack{
ForEach(0..<self.values.count){ i in
PieSliceView(pieSliceData: self.slices[i])
}
.frame(width: geometry.size.width, height: geometry.size.width)
Circle()
.fill(self.backgroundColor)