{"id":324987,"date":"2021-06-16T15:00:11","date_gmt":"2021-06-16T15:00:11","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=324987"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2021-06-16T15:00:11","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=324987","title":{"rendered":"\u041b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u0432 \u0432 Matlab, Octave, C"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<h2>\u0410\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u044b (finite state machines, fsm) \u2014 \u0448\u0442\u0443\u043a\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u0441\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u044b \u0432 \u0441\u0440\u0435\u0434\u0430\u0445, \u0433\u0434\u0435 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u0442 \u0440\u0430\u0437\u0432\u0438\u0442\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Octave, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c Matlab) \u0438\u043b\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0434\u043b\u044f \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u0433\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c RTOS. \u0414\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u043e\u0441\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u0445\u043e\u0442\u044f \u0438 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u041b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u0442.\u0435. \u0431\u0435\u0437 \u0432\u043e\u0434\u044b, \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0442.\u0434. \u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0438 \u044f \u0441\u043f\u0435\u0448\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u043a\u043e\u0439. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044f \u0438\u0437\u043e\u0431\u0440\u0451\u043b \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u0435\u043d.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h2>\u041d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u0435\u0434\u0435\u043d\u0438\u044f<\/h2>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442 \u0437\u0430\u0434\u0430\u0451\u0442\u0441\u044f:  <\/p>\n<ul>\n<li>\u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439<\/li>\n<li>\u043d\u0430\u0431\u043e\u0440\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/li>\n<li>\u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 (\u0442.\u0435. \u0432 \u043a\u0430\u043a\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u044e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0438 \u0432 \u043a\u0430\u043a\u043e\u0435 \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0445\u043e\u0434)<\/li>\n<\/ul>\n<h2>\u0426\u0435\u043b\u044c, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u043e\u044f\u043b\u0430 \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439<\/h2>\n<p>  \u0415\u0441\u0442\u044c \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u044f\u0437\u044b\u043a, \u044f \u0431\u0443\u0434\u0443 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c Octave, \u043d\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438 Matlab \u0438 C, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440. \u042d\u0442\u043e\u0442 \u044f\u0437\u044b\u043a \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442:  <\/p>\n<ul>\n<li>\u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/li>\n<li>\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/li>\n<li>\u0442\u043e, \u0447\u0442\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442 \u0438\u043c\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u044f\u0437\u044b\u043a\u0438 (\u0446\u0438\u043a\u043b\u044b, \u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0442.\u0434.)<\/li>\n<\/ul>\n<p>  \u0425\u043e\u0447\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431 \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u044f \u044f\u0437\u044b\u043a\u0430 (\u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u0435\u0449\u0451) \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u0438 \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 FSM. \u041f\u0440\u043e\u0444\u0438\u0442 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e   <\/p>\n<ul>\n<li>\u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0441\u0430\u043c\u043e\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c<\/li>\n<li>Doxygen \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043a\u043e\u0434\u0430 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u043f\u043e \u043a\u043e\u0434\u0443 \u0431\u0443\u0434\u0443\u0442 \u0434\u0430\u0432\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043f\u043e\u043b\u044c\u0437\u0443<\/li>\n<\/ul>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438\u0434\u0435\u0438<\/h2>\n<p>  <\/p>\n<ul>\n<li>\u041f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u2014 \u0445\u043e\u0440\u043e\u0448\u0438\u0439 \u043a\u0430\u043d\u0434\u0438\u0434\u0430\u0442 \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431 \u0435\u0451 \u0438\u043c\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u043b\u043e \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e.<\/li>\n<li>\u0421\u043e\u0431\u044b\u0442\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0434\u0435\u0442\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0442\u043e\u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0434\u043b\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0442\u043e\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438<\/li>\n<li>\u0422\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0432\u0430\u0442\u044c \u0432 \u043b\u0438\u0431\u043e \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043b\u0438\u0431\u043e \u0432 \u0432\u0438\u0434\u0435 switch\/case-\u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439<\/li>\n<\/ul>\n<p>  \u0412 \u0447\u0451\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043e\u0432 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445?   <\/p>\n<ul>\n<li>\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0438 \u0441\u043b\u043e\u0436\u043d\u043e\u0439. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u043d\u0435\u0442 \u0432\u043b\u0435\u0437\u0430\u0442\u044c \u0432 \u044d\u043a\u0440\u0430\u043d \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0442\u0430\u043a\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a\u043e\u0439 \u0443\u0436 \u0438 \u0443\u0434\u043e\u0431\u043d\u043e\u0439.<\/li>\n<li>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438. \u042d\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043d\u0435\u0443\u0434\u043e\u0431\u0441\u0442\u0432\u043e.<\/li>\n<li>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0435\u0451 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u0448\u0430\u0433\u043e\u0432\u043e\u0433\u043e) \u2014 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u043e\u043b\u0435\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439, \u043d\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0439 \u043f\u043e\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0442\u0430\u043a-\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e.<\/li>\n<\/ul>\n<p>  \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0434\u0435\u0441\u044c \u044f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c switch\/case \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e.<\/p>\n<p>  \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0430.<br \/>  \u0421\u0430\u043c\u0438 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u0430\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 (function handlers), \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u043c\u0430\u0448\u0438\u043d\u044b \u0432 \u044d\u0442\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<pre><code class=\"matlab\">function [new_state  data] = state_idle(data)     if data.block_index == 10         new_state = @state_stop;     else         % do something         data.block_index = data.block_index + 1;         printf('block_index = %d\\n', data.block_index);     end end  function [new_state data] = state_stop(data)     % set break flag     data.stop= 1; end fsm_state = @state_idle; data = struct(); data.block_index = 0; data.stop = 0;  while (1)     [fsm_state data] = fsm_state(data)     if data.stop         break;     end end <\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u0434\u0435 \u0432\u0441\u044f \u0438\u0434\u0435\u044f, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0430. \u0412 \u0421\u0438, \u0432\u043c\u0435\u0441\u0442\u043e \u0445\u044d\u043d\u0434\u043b\u0435\u0440\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0432\u0441\u0451 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u0430\u043a \u0436\u0435.<\/p>\n<h2>\u041f\u0440\u0438\u043c\u0435\u0440 \u0438\u0437 \u0436\u0438\u0437\u043d\u0438 \ud83d\ude42<\/h2>\n<p>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u043d\u0430 Octave \u0438\u0433\u0440\u0443 Life, \u0414\u0436\u043e\u043d\u0430 \u041a\u043e\u043d\u0432\u0435\u044f. \u0415\u0441\u043b\u0438 \u0441\u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 100 \u0445 100, \u0442\u043e \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u043c\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 10 000 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u043e\u0432 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u043d\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e. \u0412 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0435\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 (\u0431\u0435\u0437 \u0441\u043e\u0431\u044b\u0442\u0438\u0439), \u043a\u043e\u0434 \u0434\u043b\u044f \u0438\u0433\u0440\u044b \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code class=\"matlab\">function [new_state] = state_alive(neighbours)     alive_count = sum(sum(cellfun(@(x)x == @state_alive, neighbours)));     alive_count -= 1;     if (alive_count == 2) || (alive_count == 3)         new_state = @state_alive;     else         new_state = @state_dead;     end end  function [new_state] = state_dead(neighbours)     alive_count = sum(sum(cellfun(@(x)x == @state_alive, neighbours)));          if (alive_count == 3)         new_state = @state_alive;     else         new_state = @state_dead;     end end  % main script  addpath('fsm_life') debug_on_error(1)  size_x = 30; size_y = 30; init_alive_percentage = 30;  % initialization selection: %init = 'random'; %init = 'cycle'; init = 'glider';  field = cell(size_y, size_x); [field{:}] = deal(@state_dead);  switch (init) case 'random'     init_alive_count = round((size_x * size_y) * init_alive_percentage \/ 100);      for n=(1:init_alive_count)         x = floor((size_x-0.0000001)*rand())+1;         y = floor((size_y-0.0000001)*rand())+1;         field{y,x} = @state_alive;     end case 'cycle'     field{2,1} = @state_alive;     field{2,2} = @state_alive;     field{2,3} = @state_alive; case 'glider'     field{1,3} = @state_alive;     field{2,3} = @state_alive;     field{3,3} = @state_alive;     field{3,2} = @state_alive;     field{2,1} = @state_alive; end  printf(&quot;Initial distribution:\\n&quot;); cellfun(@(x)x == @state_alive, field)  % simulation for step = (1:100)      field_new = cell(size(field));     for x=(1:size_x)         for y=(1:size_y)             x_min = max(x-1, 1);             x_max = min(x+1, size_x);             y_min = max(y-1, 1);             y_max = min(y+1, size_y);             neighbours = field(y_min:y_max, x_min:x_max);             field_new{y,x} = field{y,x}(neighbours);         end     end     field = field_new;      printf('Distribution after step %d\\n', step );     cellfun(@(x)x == @state_alive, field)     figure(1); imagesc(cellfun(@(x)x == @state_alive, field));     pause(0.05); end <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0430\u043c\u043e\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u0438 \u0438 \u044f\u0432\u043d\u043e\u0433\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u043e\u0433\u0434\u0430 \u043a \u0434\u0432\u0443\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u043c \u0437\u0430 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u0441\u044f \u0435\u0449\u0451 3 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0435 \u0437\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u044f:  <\/p>\n<pre><code class=\"matlab\">function event = event_die(neighbours)     alive_count = sum(sum(cellfun(@(x)x == @state_alive, neighbours)));     alive_count -= 1;     if (alive_count == 2) || (alive_count == 3)         event = '';     else         event = 'die';     end end  function event = event_spawn(neighbours)     alive_count = sum(sum(cellfun(@(x)x == @state_alive, neighbours)));     if (alive_count == 3)         event = 'spawn';     else         event = '';     end end  function event = event_survive(neighbours)     alive_count = sum(sum(cellfun(@(x)x == @state_alive, neighbours)));     alive_count -= 1;     if (alive_count == 2) || (alive_count == 3)         event = 'survive';     else         event = '';     end end  function [new_state] = state_alive(neighbours)     event = '';     event = [event, event_die(neighbours)];     event = [event, event_survive(neighbours)];      switch event     case 'die'         new_state = @state_dead;     case 'survive'         new_state = @state_alive;     otherwise         msg = sprintf('Unknown event: %s\\n', event);         error(msg);     end end  function [new_state] = state_dead(neighbours)          event = event_spawn(neighbours);          switch event     case 'spawn'         new_state = @state_alive;     case ''         new_state = @state_dead;     otherwise         msg = sprintf('Unknown event: %s\\n', event);         error(msg);     end end <\/code><\/pre>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0441\u0442\u0430\u043d\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u0441\u0430\u043c\u044b\u043c.<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/563120\/\"> https:\/\/habr.com\/ru\/post\/563120\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\">\n<h2>\u0410\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/h2>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u044b (finite state machines, fsm) \u2014 \u0448\u0442\u0443\u043a\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043e\u043d\u0438 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0432\u043e\u0441\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u044b \u0432 \u0441\u0440\u0435\u0434\u0430\u0445, \u0433\u0434\u0435 \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u043d\u0435\u0442 \u0440\u0430\u0437\u0432\u0438\u0442\u043e\u0439 \u043c\u043d\u043e\u0433\u043e\u0437\u0430\u0434\u0430\u0447\u043d\u043e\u0441\u0442\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 Octave, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0437\u043d\u0430\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u043e\u043c Matlab) \u0438\u043b\u0438 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u0445 \u0434\u043b\u044f \u043c\u0438\u043a\u0440\u043e\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u043e\u0432, \u0433\u0434\u0435 \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e \u043a\u0430\u043a\u0438\u043c-\u0442\u043e \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c RTOS. \u0414\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0443 \u043c\u0435\u043d\u044f \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u043e\u0441\u044c \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0430\u0432\u0442\u043e\u043c\u0430\u0442, \u0445\u043e\u0442\u044f \u0438 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c. \u041b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u043e, \u0442.\u0435. \u0431\u0435\u0437 \u0432\u043e\u0434\u044b, \u0431\u0435\u0437 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043b\u0438\u0448\u043d\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438 \u0442.\u0434. \u0421\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e, \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0438 \u044f \u0441\u043f\u0435\u0448\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0435\u0439 \u043d\u0430\u0445\u043e\u0434\u043a\u043e\u0439. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u044f \u0438\u0437\u043e\u0431\u0440\u0451\u043b \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434, \u043d\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0442\u0430\u043a\u0436\u0435, \u0447\u0442\u043e \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0442\u0430\u043a\u043e\u0439 \u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u043e\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0435\u0437\u0435\u043d.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-324987","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324987","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324987"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/324987\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}