<jupyter_start><jupyter_text>Chapter 1 - Modelling & programming environmentsA mathematical model is a description of a system which uses abstractions and mathematical language. The development of of one of these is know as mathematical modelling.The mathematical models usally are made of relations and variables, such relations can be described by operators (algebraical and/or differential), functions, etc. The variables are abstractions of the studied system's parameters which can be quantified. Homework 01  First approach - Deal with data and model implementationsNowdays in almost every field of the human knowledge is necessary to deal with data. Use a programming language becomes an essential tool when we want to automatize the implementation of our models.1) implement a function to read data from a directory taking in count the file extention.<jupyter_code>import os
import numpy as np 
path = "/data/"

def read_dir(path, ext):
    l = []
    for f in os.listdir(os.getcwd()+path):
        if f.endswith(ext):
            r = open(os.getcwd()+path+f).read()
            r = np.array(r[:-1].split())
            l.append({f:r})
    return l<jupyter_output><empty_output><jupyter_text>2) Use the funtion to load the data on memory<jupyter_code>input_data = read_dir(path,'.in') 
ans_data = read_dir(path,'.ans')<jupyter_output><empty_output><jupyter_text>3) Create a set of functions that implements a model to treat our data.<jupyter_code>def price(l):
    p = int(l[0])
    a = int(l[1])
    b = int(l[2])
    c = int(l[3])
    d = int(l[4])
    n = int(l[5])
    P = []
    for k in range(int(n)):
        P.append(p*(np.sin(a*(k+1)+b)+np.cos(c*(k+1)+d)+2))
    return P
def max_decline(prices):
    max_dif = 0.0
    dif = max(prices)-min(prices)
    if dif >  0.0:
        max_dif = dif
    return max_dif
def max_dec_list(data):
    declines = []
    for d in data:
        key = d.keys()[0]
        value = d.values()[0]
        stock_prices = price(value)
        declines.append({key:[max_decline(stock_prices)]})
    return declines
comp_data = max_dec_list(input_data)<jupyter_output><empty_output><jupyter_text>4) Compute the error between the computed data and the teorical.<jupyter_code>for l1 in ans_data:
    for l2 in comp_data:
        if l1.keys()[0][0:2] == l2.keys()[0][0:2]:
            print l1.keys()[0], l2.keys()[0]
            print 'error in file', l1.keys()[0][0:2], 'is ', '%.6f' % abs(float(l1.get(l1.keys()[0])[0])- float(l2.get(l2.keys()[0])[0]))<jupyter_output>13.ans 13.in
error in file 13 is  0.008911
03.ans 03.in
error in file 03 is  0.000000
04.ans 04.in
error in file 04 is  0.000000
05.ans 05.in
error in file 05 is  0.000000
06.ans 06.in
error in file 06 is  76.507643
07.ans 07.in
error in file 07 is  0.015731
08.ans 08.in
error in file 08 is  0.004480
09.ans 09.in
error in file 09 is  0.000892
10.ans 10.in
error in file 10 is  0.000000
11.ans 11.in
error in file 11 is  0.000000
12.ans 12.in
error in file 12 is  0.000000
14.ans 14.in
error in file 14 is  0.000000
15.ans 15.in
error in file 15 is  0.000000
16.ans 16.in
error in file 16 is  63.880478
17.ans 17.in
error in file 17 is  0.000000
18.ans 18.in
error in file 18 is  0.000000
19.ans 19.in
error in file 19 is  0.000000
20.ans 20.in
error in file 20 is  0.000000
21.ans 21.in
error in file 21 is  0.000000
22.ans 22.in
error in file 22 is  0.000204
23.ans 23.in
error in file 23 is  0.000010
24.ans 24.in
error in file 24 is  0.001627
25.ans 25.in
error in file 25 is  0.000539
26.ans 26[...]
{'fraction_non_alphanumeric': 0.11095305832147938, 'fraction_numerical': 0.10099573257467995, 'mean_word_length': 3.2825822168087697, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '224771', 'license': 'MIT', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1249, 'n_words': 440, 'path': 'Homework01/01 - First approach.ipynb', 'repo_name': 'dacostaortiz/Math-Modelling', 'size': '3515'}