Math and Programming with MATLAB (original) (raw)
Abstract
As already mentioned, Module 3 demonstrates perspectives in learning and exploring mathematics that otherwise might look too abstract and tedious to some students. From another hand, a number of useful programming examples is contained there. Our teaching experience show that the students are usually impressed and inspired when their boring object of, say, Analytical Geometry become rotating or pulsating on computer screen… (see Fig. 4.6) The book ends with optional Module 4 where the students learn how to "dress" their programs into a Graphical User Interface, GUI. Again, the students are usually happy to complete programming in a modern Windows-like form. The latter may be quite difficult to them in other languages but is made very easily in the MATLAB. The new programming skills and knowledge are to be extended in their future programming courses taught in National Aviation University. Authors wish to express their gratitude to the Math Works Inc. for their promotion of this book in a form of granting v. 7.1 of their wonderful software. We thank Mrs. Courtney Esposito for her constant attention to our work. Topographical conventions of this book. To contrast with regular text, MATLAB' commands and programs are typed in a smaller font in italic (except symbols like (, ], : etc.). These, typed after the prompt symbols >>, mean a command that is issued from Command Line. Example: >> sqrt(2+sqrt(3)). Similar text without the prompt may correspond to MATLAB' reply, for example Error: Missing operator, comma, or semicolon. If a line of commands does not fit to page width, its continuation is placed on next line but aligned to the page' right border. Navigation through MATLAB' menu is typed in bold and italic such as ViewCommand Window. Keyboard keys are framed like Enter. New terms introduced are typed italic; their meaning is often self evident but students are advised to inquiry them in dictionaries or in specialized handbooks. The sign (glasses) labels optional materials, or that for advanced students.
Figures (25)
Fig. 1.2. Appearance of the MATLAB with two Windows open: 1 - Commanc Window with the "prompt" 2; 3- Command History Window; 4 — Menu icons
Fig. 1.3. Example of MATLAB's plotting capabilities.
Fig. 1.4. Regular polygon of N sides on computer screen, N=5.
Fig. 1.5. The function and its derivative from the example 1.7.
1.13. How may the commands legend, title, grid, xlabel, ylabel, axis, insert "decorate" your graphs? How could you set or change color of your plot curves? 1.14. For what do one use the command figure? If you need to plot several graphics, how could you plot some of then in one window but other curves in an other? 1.15. Plot the function given parametrically x=sin(3t)cost, y=sin(3t)sint, te[0,x] (1.9) 1.16.” How would it be vossible to plot a discontinuous function like
Micromodule 2.1. m-scripts and m-functions To automate multiple repetitions of the same commands, one writes programs. Actually, all the commands you leamed previously like fplot are the programs written by somebody. Now, let's become programmer, too!
Figure 2.1. Results of a "computer experiment" with numerical differentiation by the program MyDiff: F3 is original, but F1 is its rough and F2 is more precise derivatives.
Fig. 2.2. Relations of scripts and functions with the whole MATLAB environment: solid lines denote direct exchange of data while dotted ones exchange by global variables.
This command block is self evident, so we may explain it by an example.
Most of algorithmic languages do not mix logical and arithmetic operations. In contrast, MATLAB allows mixing of both: a number may multiply logical expression A, and the result is either the same number if A=1 (true),or zero if A=0 (false). This MATLAB' feature lead to simplification of many programs. Recall the programs Step01 for plotting discontinues function. Here is its modification. ~(NO1) are used for doing this. Logical value of complex expressions may often be estimated by intuition; for example, the expression (T(4)>5) | (T(4)<=12) equals true both in 3 and in 7 o'clock. However, computers require rigorous formal rules. The latter, known as logical arithmetic, have been given in tables below.
tig. 2.5. Flow chart of periodical function Step_pi
Fig. 3.4. Figure Window (middle) with exact "experimental" data and their linear (B), cubic (C) fits and that of 8th order (A) found via Fitting Interface (left). Right: two possible straight lines going exactly through two "experimental" points. Let an observation was carried out in time moments t=1:.5:6. Imagine, we know (but nobody else!) the law y=at*+b_ witt coefficients, say a=2, a=0,3 and b=1, the process y(t) i: governed by. If one would sample values of y in given moments, results were certainly different from those theoretical values because of measurement errors. How to get "experimental" data to leam an
Fig. 3.5. Comparison of execution time for two array sorting algorithms: dots are "experimental" results; lines are fitting curves.
Fig. 4.1. Examples of MATLAB 7.1 GUIs: 1 — menus, 2 — text windows, 3— buttons, 4— radio buttons, 5-— check boxes, 6— taskbars
Fig. 4.2. Two graphical objects created by menu command. Colors and dimensions may be changed by set.
Fig. 4.3. Pilot window after calling guide.
Fig. 4.5. Activated GUI shown in the Fig. 4.4. Each type of UI controls has been represented here. However, the UI controls "simulate" rather than execute a real work yet.
Figure 4.6. Graphical program GUlhelicopter that revolves stick of a chosen color N times in clockwise or opposite direction at a given speed.
Loading Preview
Sorry, preview is currently unavailable. You can download the paper by clicking the button above.
References (44)
- 15. Draw flow chart of the program MyOrder developed in section 2.3.3. Generalize the program to make it to "understand" two- dimensional input argument (matrices).
- 16. Learn "bubble" method of sorting [7-9] and realize it in a MATLAB program. Analyze, what of such algorithms already known to you is better.
- 17. Analogically to MyDeriv, develop dialogue program for comparing functions and their primitive (define integral) to be found "analytically", see Micromodule 1.3.2.
- 18. You certainly may solve the problem 1.20 now. Try this! 2.
- A number of exciting and useful programs may be developed by reader now. Some our students made their term papers named "MATLAB Guide to Analytical Geometry", or "Test your Knowledge of Functions by MATLAB", etc. You are advised to follow them! References
- Ануфриев И. Самоучитель MatLab 5.3/6.x. -СПб.: БХВ- Петербург, 2002. -736 с.
- Гаєв Є.О., Нестеренко Б.М. Універсальний математичний пакет MatLab і типові задачі обчислювальної математики. Навчальний посібник. К., 2004. -175 с.
- Гаєв Є.О., Нестеренко Б.М. Типові задачі обчислювальної математики з застосуванням пакету MatLab. Методичні вказівки до виконання лабораторних робіт. К., 2004. -38 с.
- Демидович В.П., Марон И.А. Основы вычислительной математики. -М.: Наука, 1966. -664 с.
- Денисюк В.П., Репета В.К., Гаєва К.А., Клешня Н.О. Вища математика. Навч. посіб., ч. 3. К.: НАУб 2006. -444с.
- Кетков Ю., Кетков А. MatLab 6.х: программирование численных методов. Спб: БХВ, 2004. 672 с.
- Пайтген Х.-О., Рихтер П.Х. Красота фракталов. -Москва: Мир, 1993. 176 с.
- Павловский В.И. Структуры данных. Представление и использование. -Чернигов: ЧГТУ, 2003. -233 с.
- Aho A.V., Hopkroft J.E., Ulman J.D. Data structures and algorithms. (Russian translation: Ахо А.В., Хопкрофт Д.Э., Ульман Д.Д. Структуры данных и алгоритмы. -Москва-Киев: Изд. дом. "Вильямс", 2003. -384 с.)
- Austin M., Chancogne D. Introduction to Engineering Programming: in C, MATLAB, and Java. John Wiley&Sons, Inc., 1999.
- Azemi A., Yaz E. E. Using graphical user interface capabilities of MATLAB in advanced engineering courses, The 38th IEEE Conference on Decision and Control (CDC), IEEE, pp 359-363, Phoenix, December 7-10, 1999.
- Cooper J. A MATLAB companion for multivariable calculus. -San Diego: Harcourt, 2001. -294 pp.
- Depcik Ch., Assanis D.N. Graphical User Interfaces in an Engineering Educational Environment. CAEE2005, v13, №1, pp.48- 59.
- Herniter M. E. Programming in MATLAB. Thomson Engineering, 2001
- Rojan Yu. Learn Programming and Mathematics with MATLAB.
- Tuck M. The Real History of the GUI. http://www.sitepoint.com/ article/ real-history-gui
- Wikipedia, Graphical User Interface. http://en.wikipedia.org/wiki/ Graphical_user_ interface
- Wirt N. (Вирт Н. Алгоритмы и структуры данных. СпБ..: Изд-во "Невский диалект", 2001. -352 с.)
- Gayev Ye.A., Nesterenko B.N. MATLAB for Math and Programming: Textbook. -Zaporozhye: Polygraph, 2006 -102 p.
- Азарсков В.М., Гаєв Є.О. Сучасне програмування. Модулі 1,2: "Програмування та математика із другом MATLABом". К.: НАУ, 2014. -256 с.
- Гаєв Є.О., Рожок О., Овчарчин Н. Звук та музика в курсі програмування. --Інженерія програмного забезпечення, 2014, (у друку).
- Гаев Е.А., Мартич М., Тарак Г. Программы моделирования случайных явлений для изучения программирования и математики. -Інформаційні технології в освіті, 2015, (в печати)
- FiS=[pi/2 pi/2 -pi/64+pi/2 pi/2 pi/64+pi/2 pi/2 pi/2]-(pi/30)*time(6);
- RhoS=[0 1 1 5 1 1 0];
- xS=RhoS.*cos(FiS);
- *sin(FiS);
- fill(xS,yS,'b'), hold off, pause(1);
- WatchArr(:,i) = getframe;
- Module 1: MATLAB, the mathematical environment………….5 Micromodule 1.1. Basics of MATLAB…………………………….5 1.1.1. Getting started……………………………………….6
- 1.2. Matrix arithmetic of the MATLAB …………………8 Micromodule 1.2. Plotting 1d functions……………………………12 Micromodule 1.3. Numeric and symbolic calculations ……………15 1.3.1. Polynomials …………………………………………..16
- 3.2. Symbolic mathematics in MATLAB …………………21 Problems for Module 1 …………………………………………….25 Module 2: Basics of MATLAB programming …………………..27 Micromodule 2.1. m-scripts and m-functions …………………..…27 2.1.1. Scripts, the simplest programs………………………....27 2.1.2. MATLAB' Functions (m-functions) …………………..29
- 1.3. Difference between Scripts and Functions …………….31
- Micromodule 2.2. Structured programming in MATLAB ………….33 2.2.1. Loop operator for … end ………………………………34 2.2.2. Logical operator if … else … end ……………………...35
- 2.3. Logical arithmetic with and, or, not …………………...40
- Micromodule 2.3. More MATLAB' programs ……………………...42 2.3.1. Periodic Step-function …………………………………42 2.3.2. Least element of an array ………………………………45 2.3.3. Re-ordering of a vector …………………………….…..46
- Micromodule 2.4. Supplementary problems ……………………..…48 2.4.1. Dialogue programs ………………………………….…48 2.4.2. Debugging programs ……………………………….…49 Problems for Module 2 ………………………………………….…50 Module 3: MATLAB for learning and investigation …………..53 Micromodule 3.1. The awful "ε -δ language"! ……………………53 Micromodule 3.2. Taylor, Fourier… Who else? ……………………57 Micromodule 3.3. Discovering empirical formulas ………………..60 Micromodule 3.4. Efficiency of programs …………………………65 Micromodule 3.5. Your further discoveries with MATLAB……… Problems for Module 3 ………………………………………….…68 Module 4: Graphical User Interface in MATLAB ………………71 Micromodule 4.1. Graphical User Interface (GUI) standards ………71 Micromodule 4.2. Games with MATLAB GUI elements ………..…72 4.2.1. menu command ………………………………………...72
- 2.2. uicontrol commands ……………………………………74 Micromodule 4.3. guide, MATLAB GUI developer ……………..…76 Micromodule 4.4. An example: GUI for helicopter …………………78 Conclusion ……………………………………………………….…..83 Problems for the Module 4 …………………………………….….…84
- References ……………………………………………………….…..86
- Attachment A1: Listing of "MyDiff.m" ……………………….…...……88 Attachment A2: Listing of "GUIhelicopter.m" …………………...……88 Attachment A3: Listing of "MyClock.m" ………………………...……91 Summary of MATLAB commands …………………….…….……..93