Skip to content

Instantly share code, notes, and snippets.

View ethanmpeterson's full-sized avatar

Ethan Peterson ethanmpeterson

View GitHub Profile
@ethanmpeterson
ethanmpeterson / rlc.m
Last active July 1, 2019 22:00
MATLAB RLC circuit demo code
clc
caps = [1, 2, 3, 4]; % put actual capacitor numbers here (Converted to SI units ie. Ferads)
inductors = [1, 2, 3, 4]; % put inductor values here (Converted to SI units ie. Henrys)
targetFrequency = 1200 * 10^3;
for i = 1 : length(caps) % goes through elements in caps array
for j = 1 : length(inductors) % goes through all inductors
% run the amplitude function (the loops will take care of every combo)
@ethanmpeterson
ethanmpeterson / main.m
Last active June 27, 2019 01:04
MTHE 225 Assignment #1: Matlab script for calculating amplitude responses of an RLC circuit to certain frequencies.
% RLC circuit calculation tool
% MTHE 225
% Ethan Peterson
% Student #: 20105011
% June 13, 2019
% Setup
clc % Clear previous output
% RLC Circuit Values
@ethanmpeterson
ethanmpeterson / circuit_configs.txt
Last active June 27, 2019 01:03
MTHE 225 Assignment #1: Amplitude result from each inductor and capacitor combination.
A = 0.000754, L = 0.100000, C = 0.100000
A = 0.002493, L = 0.100000, C = 0.330000
A = 0.005147, L = 0.100000, C = 0.680000
A = 0.007583, L = 0.100000, C = 1.000000
A = 0.025349, L = 0.100000, C = 3.300000
A = 0.053257, L = 0.100000, C = 6.800000
A = 0.079689, L = 0.100000, C = 10.000000
A = 0.292844, L = 0.100000, C = 33.000000
A = 0.641305, L = 0.100000, C = 68.000000
A = 0.867914, L = 0.100000, C = 100.000000
@ethanmpeterson
ethanmpeterson / user_accounts.c
Last active October 16, 2018 19:12
APSC 143 Lab 6 Code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define NUM 100 //Take 100 usernames
#define MAXLEN 20 // Max username and password length
// Function declarations
int readDatabase(char *usrDB[], int pswrdDB[]);
char *getUsername();
func timeDifference(firstHour : Int, firstMinute : Int, secondHour : Int, secondMinute : Int) -> Int {
return abs(((firstHour * 60) + firstMinute) - ((secondHour * 60) + secondMinute))
}
// your code here
func levelCost(heights : [Int], maxJump : Int) -> Int {
var points = 0
for i in stride(from: 0, through: heights.count, by: 1) {
if (i < heights.count - 1) {
if (heights[i] == heights[i + 1]) {
points += 1
} else if (heights[i] < heights[i + 1] && abs(heights[i + 1] - heights[i]) <= maxJump) {
let addedPoints = 2 * (abs(heights[i + 1] - heights[i]))
points += addedPoints
// your code here
func verify(expression : String) -> Bool {
// get all chars in an array
var closeP = 0
var openP = 0
for char in expression.characters {
if (char == "(") {
openP += 1
} else if (char == ")") {
closeP += 1
var input : String = "This:-(is str:-(:-(ange te:-)xt."
var sad = 0
var happy = 0
// convert input to char array
var inputChars = [Character]()
for char in input.characters {
inputChars.append(char)
}
import Foundation
/*
MAKING A PLAN
A common problem solving model is known as input-process-output.
1. What are the possible inputs I can expect to receive?
2. How should each type of input be processed?
let alphabet : [Character] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
let consonant : [Character] = ["b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z"]
let vowels : [Character] = ["a", "e", "i", "o", "u"]
let input : String = "joy"
var output : String = ""
func isCons(letter : Character) -> Bool {