Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "math.h" 00003 00004 00005 DigitalOut myled1(LED1); 00006 DigitalOut myled2(LED2); 00007 DigitalOut myled3(LED3); 00008 DigitalOut myled4(LED4); 00009 00010 LocalFileSystem name("local"); 00011 00012 int main() { 00013 00014 00015 int i; 00016 00017 FILE *fp1; 00018 FILE *fp2; 00019 00020 double x1[24]; 00021 double y; 00022 00023 int k; 00024 double xp1[24]; 00025 static const double b[24] = { 59.242, 5.1613, 63.473, -11.876, -3.8628, 54.359, 00026 -0.62134, 69.155, -4.2458, -14.506, -197.51, -234.04, -218.15, -178.37, 00027 -79.8, -211.83, -623.8, -282.56, -179.0, -85.632, 0.057132, 0.071264, 00028 0.057132, 0.071264 }; 00029 00030 double av[24]; 00031 static const double b_b[24] = { 0.0222697309816497, 0.0198730706974554, 00032 0.0186346399321699, 0.315512155105775, 0.22853747443237, 0.0109372692919759, 00033 0.00767190808869984, 0.0125223053564161, 0.155402570358514, 00034 0.0259094206653539, 0.0150074662144417, 0.0119628672600249, 00035 0.00972710604004649, 0.0143260318324427, 0.0337410375369043, 00036 0.0118734527406897, 0.00354405705931866, 0.00738214406992367, 00037 0.0142176725670008, 0.0314218381775334, 0.0600657094835466, 00038 0.060507532340671, 0.0600657094835466, 0.060507532340671 }; 00039 00040 double d0; 00041 double d1; 00042 int i0; 00043 static const double a[10] = { 0.36444699787527712, -0.40103227312965839, 00044 -0.061856443911952, -0.13161520537398866, -0.38421571124091469, 00045 -0.3244803116427783, -0.34804747906508021, 0.13353040532482696, 00046 0.41797408173062545, 0.24113319880040548 }; 00047 00048 static const double b_a[10] = { -0.10018222304920145, 0.11495178233580637, 00049 0.013498785921607482, 0.030540649798823018, 0.1070193103286755, 00050 0.087367567333305265, 0.094727740107540925, -0.031045937441075207, 00051 -0.11574288162935432, -0.062068183358996727 }; 00052 00053 static const double c_a[240] = { 0.0018081444747809223, -0.0025249808730199406, 00054 -0.0020803645204989737, -0.0035465674542671873, -0.0019956186228820569, 00055 -0.001306310790117131, -0.0015672564120252253, 0.0035651090440350368, 00056 0.00054082426975135046, 0.0024198892504174946, 0.028714454676996928, 00057 -0.031017339565412829, -0.0046330413196114788, -0.010213144461208809, 00058 -0.029814241342887959, -0.026338310528158188, -0.027757623524519895, 00059 0.010374158376189047, 0.030360988142012286, 0.019913495351160198, 00060 0.085000060562910748, -0.093398985848435992, -0.01470612423557467, 00061 -0.031275229956527123, -0.089431103901583042, -0.075913698473557265, 00062 -0.081286524502978907, 0.031728631207540922, 0.094995449089777667, 00063 0.056841941251804834, -0.0064048853430847394, 0.0086612513397343223, 00064 -0.0015753544505049785, -0.0024762319412570595, 0.0075397937319654773, 00065 0.0036176871374643234, 0.0052704387090874759, 0.0024815232056378893, 00066 -0.007276420473214423, 0.00081310745373297175, 0.0011589216778881662, 00067 -0.0017076031948080684, 0.0031641199927871389, 0.0049928356010829717, 00068 -0.001014715733672879, -0.0003385517239666003, -0.00087291427998232706, 00069 -0.0050055047360875243, -0.0039607029160636711, -0.0027729535046173955, 00070 -0.05753889470976116, 0.067848929607381633, 0.0055937703809895668, 00071 0.01273854662848717, 0.063288308228040477, 0.046520464464030166, 00072 0.052941059296597773, -0.012955573557348879, -0.07542111010601342, 00073 -0.028082584079798644, 0.019805428800836609, -0.025667617361111918, 00074 0.00048566153679348024, -3.5136005073696682E-5, -0.022677150798710778, 00075 -0.013716807069647346, -0.017259056800834789, 7.2572257862501611E-5, 00076 0.024952571619834402, 0.0046587630403999783, 0.0050054091777026345, 00077 -0.0071092705662086468, -0.0012397750607656092, -0.0026678990054748515, 00078 -0.0054943303179862488, -0.004263016163475665, -0.0045990158874952437, 00079 0.0027050921332278503, 0.0037232937754260557, 0.0040190239503676726, 00080 0.034329505721475986, -0.03599033469180192, -0.0055915955817757556, 00081 -0.012416863519400972, -0.035224647589328612, -0.03204316466990597, 00082 -0.033473553975528453, 0.012615371623192397, 0.03576517879889881, 00083 0.024407093401506784, -0.10655985775595592, 0.12180261285627766, 00084 0.01569665086693119, 0.03337961342735847, 0.11529171574206508, 00085 0.090650059213695719, 0.099891416431144728, -0.033868195164765566, 00086 -0.13627408879669906, -0.062801273397934954, 0.043823961981777827, 00087 -0.051414741895819932, -0.0061307750078207733, -0.013024856393718849, 00088 -0.048044551904979915, -0.0364082501706166, -0.040668120482747212, 00089 0.013215038398889207, 0.058399394544661677, 0.024555148136527559, 00090 0.017085795435832975, -0.018919359464873331, -0.0021685267740616022, 00091 -0.0044253245349437382, -0.018716994766325667, -0.014089947315287224, 00092 -0.015891113360788692, 0.00448599539165072, 0.02481602416980306, 00093 0.0086390549234530711, -0.027766833985911073, 0.025122123833030623, 00094 0.0080392844308002018, 0.01623320769035063, 0.026920585512805222, 00095 0.028819318083389722, 0.028378315396469966, -0.016439363106983056, 00096 -0.026218289791117032, -0.026064569529744491, -0.18560437818371361, 00097 0.19804966811701283, 0.036039750163344764, 0.075425841687022654, 00098 0.19319375123399524, 0.16966507203512327, 0.17928556675122606, 00099 -0.076477294035193641, -0.20671615076549291, -0.13209504504051531, 00100 0.015445736625295322, -0.024082858760116073, 0.00460049671681875, 00101 0.0078098602237691985, -0.019763378669624618, -0.0068602181296030665, 00102 -0.011799721743549534, -0.0078523325919705785, 0.025708083902173343, 00103 -0.0050248596008164031, 0.069366955339736663, -0.081711884467332019, 00104 -0.01039663287645427, -0.021831382902815478, -0.0761022100135641, 00105 -0.057489277872262018, -0.064290118530694662, 0.022139309358911598, 00106 0.092067391237060189, 0.039489374651140427, 0.02248696353935762, 00107 -0.027810273119083989, -0.0033047224528575279, -0.006754820732458572, 00108 -0.025413390758757235, -0.01805588447524048, -0.020517715082313072, 00109 0.006845068491100577, 0.034335628312408009, 0.012067916011660247, 00110 -0.080713140320817542, 0.089389870013277584, 0.015474815966535058, 00111 0.03218667077672422, 0.085497391559876526, 0.072276817184491207, 00112 0.0771609561697267, -0.032628813171139484, -0.096827007354432476, 00113 -0.055822301302134267, -0.13119468432811476, 0.13800825421198326, 00114 0.027101348853612692, 0.056521058587071675, 0.13544550233025288, 00115 0.12207045053032073, 0.12763485415838297, -0.057301453875150593, 00116 -0.14232699159533385, -0.097718436558504346, 0.012366784263312754, 00117 -0.016544830875690072, 0.0025141271019102941, 0.0040968311515123994, 00118 -0.014734417844673732, -0.0068164447953293385, -0.010121457838997363, 00119 -0.0041117074718717977, 0.016924595127583833, -0.0016558143575156983, 00120 0.045071847551022094, -0.053840432854943054, -0.0048372672852461255, 00121 -0.01164800014009044, -0.048853992418547182, -0.038087512024803594, 00122 -0.042028983820978728, 0.011862324590365125, 0.052475390397368794, 00123 0.025759986586134431, -0.087579642741851413, 0.09368863250278836, 00124 0.015446573686887803, 0.032169046859171685, 0.092070805046949852, 00125 0.078094455943480953, 0.083869342316687939, -0.03261578266387398, 00126 -0.10303393854890278, -0.057499790945129324, 0.0450718475510221, 00127 -0.053840432854943047, -0.0048372672852461263, -0.011648000140090443, 00128 -0.048853992418547175, -0.038087512024803594, -0.042028983820978728, 00129 0.011862324590365125, 0.052475390397368794, 0.025759986586134431, 00130 -0.087579642741851413, 0.09368863250278836, 0.015446573686887803, 00131 0.032169046859171685, 0.092070805046949852, 0.078094455943480953, 00132 0.083869342316687939, -0.03261578266387398, -0.10303393854890278, 00133 -0.057499790945129324 }; 00134 00135 00136 fp1=fopen("/local/InputEt.csv","r"); 00137 fp2=fopen("/local/OutputEt.csv","w"); 00138 00139 00140 myled1 = 1; 00141 wait(0.2); 00142 00143 00144 for(i=0;i<20;++i){ 00145 00146 myled2 = 1; 00147 wait(0.2); 00148 00149 00150 fscanf(fp1,"%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf\n",&x1[0],&x1[1],&x1[2],&x1[3],&x1[4],&x1[5],&x1[6],&x1[7],&x1[8],&x1[9],&x1[10],&x1[11],&x1[12],&x1[13],&x1[14],&x1[15],&x1[16],&x1[17],&x1[18],&x1[19],&x1[20],&x1[21],&x1[22],&x1[23]); 00151 00152 00153 for (k = 0; k < 24; k++) { 00154 xp1[k] = x1[k] - b[k]; 00155 } 00156 00157 for (k = 0; k < 24; k++) { 00158 av[k] = xp1[k] * b_b[k]; 00159 } 00160 00161 memcpy(&xp1[0], &av[0], 24U * sizeof(double)); 00162 for (k = 0; k < 24; k++) { 00163 av[k] = xp1[k] + -1.0; 00164 } 00165 00166 memcpy(&xp1[0], &av[0], 24U * sizeof(double)); 00167 00168 d0 = 0.0; 00169 for (k = 0; k < 10; k++) { 00170 d1 = 0.0; 00171 for (i0 = 0; i0 < 24; i0++) { 00172 d1 += c_a[k + 10 * i0] * xp1[i0]; 00173 } 00174 00175 d0 += a[k] * (2.0 / (1.0 + exp(-2.0 * (b_a[k] + d1))) - 1.0); 00176 } 00177 00178 00179 y= ((-0.24115491097968358 + d0) - -1.0) / 0.0222222222222222 + 10.0; 00180 00181 fprintf(fp2,"%lf\n",y); 00182 00183 myled2 = 0; 00184 wait(0.1); 00185 00186 00187 } 00188 myled2 = 1; 00189 myled3 = 1; 00190 wait(0.2); 00191 00192 fclose(fp1); 00193 fclose(fp2); 00194 00195 myled4 = 1; 00196 wait(0.2); 00197 }
Generated on Fri Jul 15 2022 16:11:54 by
