This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Model for a vending machine that has the following items | |
# Item #1 15 | |
# Item #2 25 | |
# Item #3 30 | |
import re | |
def accept_tokens(tokens): | |
regex = r'[ab]|[[aa|b][a|c]]|[ac]' | |
regex_eval = re.findall(regex, tokens) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Numerical Analysis, Summer Semester A.Y. 2015-2016, Adamson University | |
# Author: A.F. Agarap | |
# Error Analysis | |
import os | |
def main(): | |
true_value = float(eval(input("Enter true value: "))) | |
approximate_value = float(eval(input("Enter approximate value: "))) | |
float_range = int(input("Enter number of precision values: ")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
print("Newton's method\n") | |
A = int(input("Enter value of Xn: ")) | |
X = 0; E = 1 | |
while (True): | |
B = 3**(3 * A + 1) - 7 * 5**(2 * A) | |
C = math.log(3) * 3**(3 * A + 2) - 14 * math.log(5) * 5**(2 * A) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
A = 0; B = 12 | |
while True: | |
C = (A + B) / 2 | |
val_a = evaluate_function(A) | |
val_b = evaluate_function(B) | |
val_c = evaluate_function(C) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Numerical Analysis | |
# Trapezoidal Method | |
# Author: A.F. Agarap | |
# Function = SUM(i = 1, n) h / 2 (f(x[1]) + f(x[n + 1]) + 2(f(x[2]) + f(x[3]) + ... + f(x[n]))) | |
# f(x) = cos(x**2) * exp(x**3) | |
import math | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Numerical Analysis | |
# Simpson's Method | |
# Author: A.F. Agarap | |
# Function = (h / 3) (f(x[0]) + 4f(x[1]) + 2f(x[2]) + 4f(x[3]) + 2f(x[4]) + ... + 4f(x[n-1]) + f(x[n])) | |
# f(x) = cos(x**2) * exp(x**3) | |
import definite_integral as di | |
import os |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
print("\t\t\t10th degree of Maclaurin series, cos(x)") | |
x = float(input("Enter value of x (in Radians): ")) | |
answer = 1; i = 1; j = 2 | |
while(i < 10 and j <= 10): | |
if (i % 2 == 0): | |
answer += (x ** j) / factorial(j) | |
elif (i % 2 != 0): | |
answer -= (x ** j) /factorial(j) | |
i += 1; j += 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
print("\t\t\t10th degree of Maclaurin series, sin(x)") | |
x = float(input("Enter value of x (in Radians): ")) | |
answer = x; i = 1; j = 1 | |
while(i < 10): | |
if(i == 1): | |
answer -= (x ** (j + 2)) / factorial(j + 2) | |
elif(i % 2 == 0): | |
answer += (x ** (j + 2)) / factorial(j + 2) | |
elif(i % 2 != 0): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
print("\t\t\t10th degree of Maclaurin Series, e^x") | |
x = float(input("Enter value of x: ")) | |
answer = 1; i = 1 | |
while(i < 10): | |
answer += (x ** i) / factorial(i) | |
i += 1 | |
print(answer) | |
def factorial(number): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = '0' | |
for i in range(1, 11): | |
print('{} * 9 + {} = {}'.format(int(n), i, (int(n) * 9 + i))) | |
n += str(i) |
OlderNewer