Download presentation

Presentation is loading. Please wait.

Published byHeidi Hopkinson Modified over 2 years ago

2
1 Using Octave to Introduce Programming to Technical Science Students Nuno C. Marques nmm@di.fct.unl.pt Francisco Azevedo fa@di.fct.unl.pt CENTRIA, DI- FCT/UNL Monte de Caparica, 29 June 2005 Carmen Morgado cpm@di.fct.unl.pt Jorge Custódio jfc@di.fct.unl.pt CITI, DI- FCT/UNL

3
2 Course Background A computer science introductory course offered to non computer science Engineering students. Academic goals –basic digital computer architecture Computer basic instructions can be executed in an algorithmic way. –basic algorithmic notions for building a program Simple assignment instructions to program control flow instructions and functions. –All instructions are presented with practical examples. Simple calculation illustrates the assignment of values to variables. The calculation of the solutions of a second degree polynomial are used to introduce basic control instructions. Iteration on tables presents the need for using cycles. More complex problems as calculation of approximate solutions by iterative algorithms Recursive function calls.

4
3 Octave as a valuable tool students have fairly heterogeneous set of interests. Non computer science students tend to think that programming a computer is a very specific, difficult and unnecessary task. Learning to construct an algorithm is fundamental for structured thinking. Learning to program a computer is an essential tool for any Engineer. Why Octave? traditional computer languages have become too distant for the current GUI PC user. Octave provides a language with a higher abstraction level directly related to linear algebra. A powerful algebra calculator Enables more challenging problems, while still keeping the clear illustration of the basic concepts in programming. Octave reduces the effort needed to solve real problems. Related language MatLab has an huge number of toolboxes available. To develop small algorithmic solutions that would adapt different toolboxes for specific needs.

5
4 Some examples for Octave octave:60> A=[1,2,3;4,5,6;7,8,9] A = 1 2 3 4 5 6 7 8 9 octave:61> L=log10(A) L = 0.00000 0.30103 0.47712 0.60206 0.69897 0.77815 0.84510 0.90309 0.95424 octave:62> (10*ones(size(A))).^L-A ans = 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 8.8818e-16 0.0000e+00 0.0000e+00 -8.8818e-16 0.0000e+00 octave:60> A=[1,2,3;4,5,6;7,8,9] A = 1 2 3 4 5 6 7 8 9 octave:61> L=log10(A) L = 0.00000 0.30103 0.47712 0.60206 0.69897 0.77815 0.84510 0.90309 0.95424 octave:62> (10*ones(size(A))).^L-A ans = 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 8.8818e-16 0.0000e+00 0.0000e+00 -8.8818e-16 0.0000e+00 octave:71> A=[1, 2, 3; 2, 3, 4; 4, 2, 5] A = 1 2 3 2 3 4 4 2 5 octave:72> B=[4;5;1] B = 4 5 1 octave:89> X =A \ B X = -1.40000 1.80000 0.60000 octave:71> A=[1, 2, 3; 2, 3, 4; 4, 2, 5] A = 1 2 3 2 3 4 4 2 5 octave:72> B=[4;5;1] B = 4 5 1 octave:89> X =A \ B X = -1.40000 1.80000 0.60000 Linear Algebra Basic Operation Solving linear equations

6
5 The Iterative Fibonacci Example fib = ones(1,10); for i = 3:10 fib(i)=fib(i-1)+fib(i-2); endfor octave:3> fib fib = 1 1 2 3 5 8 13 21 34 55 fib = ones(1,10); for i = 3:10 fib(i)=fib(i-1)+fib(i-2); endfor octave:3> fib fib = 1 1 2 3 5 8 13 21 34 55 Introduces: Initialization of vectors. Sequences FOR loops, with interaction among vector components. The traditional notion of vector array is related with linear algebra notion of vector.

7
6 Another example with OCTAVE A function for calculating an approximation to the square root. The squared root verifies:: N=R*R R =N/R Being E an estimator for R and T the tried approximation: T=N/E IF E>R then T

8
7 Octave solution to approximate square root example N=input('Please insert the number: '); P=input(‘What is the precision: '); E=1; T=N; while (abs(T-E)>=P) E = (E + T) / 2; T=N/E; end printf('%f is the squared roof of %f with a precision of %f.\n', E, N, P); N=input('Please insert the number: '); P=input(‘What is the precision: '); E=1; T=N; while (abs(T-E)>=P) E = (E + T) / 2; T=N/E; end printf('%f is the squared roof of %f with a precision of %f.\n', E, N, P);

9
8 E.x. 2D Graphic Transform A real example done by students. Basic transforms were given: Students implemented solution. –One group created a snowman… d11=[12;9;1]; d12=[7;9;1]; d13=[8;10;1]; d14=[7;10;1]; d15=[9;10;1]; d16=[8;11;1]; d17=[6;13;1]; d18=[4;11;1]; d19=[4;10;1]; d20=[5;9;1]; d1=[5;0;1]; d2=[7;0;1]; d3=[9;2;1]; d4=[9;3;1]; d5=[7;5;1]; d6=[8;6;1]; d7=[8;8;1]; d8=[11;8;1]; d9=[12;7;1]; d10=[12;8;1]; d21=[4;8;1]; d22=[1;8;1]; d23=[0;9;1]; d24=[0;8;1]; d25=[0;7;1]; d26=[4;6;1]; d27=[5;5;1]; d28=[3;3;1]; d29=[3;2;1]; snowman=[d1,d2,d3,d4,d5,d6,d7,d8,d9,d8,d10,d8,d11,d8,d7,d12,d13,d14,d15,d13,d16,d 17,d18,d16,d18,d19,d20,d21, d22,d23,d22,d24,d22,d25,d22,d21,d26,d27,d28,d29,d1];

10
9 E.x. 2D Graphic Transform GNU Octave, version 2.1.35 (i386-pc-linux-gnu). Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. *** This is a development version of Octave. Development releases *** are provided for people who want to help test, debug, and improve *** Octave. *** *** If you want a stable, well-tested version of Octave, you should be *** using one of the stable releases (when this development release *** was made, the latest stable version was 2.0.16). octave:1> _ GNU Octave, version 2.1.35 (i386-pc-linux-gnu). Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. *** This is a development version of Octave. Development releases *** are provided for people who want to help test, debug, and improve *** Octave. *** *** If you want a stable, well-tested version of Octave, you should be *** using one of the stable releases (when this development release *** was made, the latest stable version was 2.0.16). octave:1> _ objectos_

11
10 E.x. 2D Graphic Transform GNU Octave, version 2.1.35 (i386-pc-linux-gnu). Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. *** This is a development version of Octave. Development releases *** are provided for people who want to help test, debug, and improve *** Octave. *** *** If you want a stable, well-tested version of Octave, you should be *** using one of the stable releases (when this development release *** was made, the latest stable version was 2.0.16). octave:1> _objectos ===> SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! <=== Qual o objecto que vai escolher? Quadrado (obj1), Rectângulo (obj2), Triângulo(obj3) ou Laço (obj4)? GNU Octave, version 2.1.35 (i386-pc-linux-gnu). Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001 John W. Eaton. This is free software with ABSOLUTELY NO WARRANTY. For details, type `warranty'. *** This is a development version of Octave. Development releases *** are provided for people who want to help test, debug, and improve *** Octave. *** *** If you want a stable, well-tested version of Octave, you should be *** using one of the stable releases (when this development release *** was made, the latest stable version was 2.0.16). octave:1> _objectos ===> SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! <=== Qual o objecto que vai escolher? Quadrado (obj1), Rectângulo (obj2), Triângulo(obj3) ou Laço (obj4)? snowman_

12
11 E.x. 2D Graphic Transform octave:1> _objectos ===> SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! <=== Qual o objecto que vai escolher? Quadrado (obj1), Rectângulo (obj2), Triângulo(obj3) ou Laço (obj4)? snowman Deseja fazer uma operação de translacção? sim (prima 1)/não (prima 2)? 1 Tx? -10 Ty? -10 Deseja fazer uma operação de rotação? sim (prima 1)/não (prima 2)? 1 Qual e o ângulo (em graus)? 45 Deseja fazer uma operação de escala? sim (prima 1)/não (prima 2)? 1 Sx? (Sx>0) Sx? (Sx>0) 1.5 Sy? (Sy>0) Sy? (Sy>0) 1.5 octave:1> _objectos ===> SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! SEJA BEM VINDO AO PROGRAMA OBJECTOS!!! <=== Qual o objecto que vai escolher? Quadrado (obj1), Rectângulo (obj2), Triângulo(obj3) ou Laço (obj4)? snowman Deseja fazer uma operação de translacção? sim (prima 1)/não (prima 2)? 1 Tx? -10 Ty? -10 Deseja fazer uma operação de rotação? sim (prima 1)/não (prima 2)? 1 Qual e o ângulo (em graus)? 45 Deseja fazer uma operação de escala? sim (prima 1)/não (prima 2)? 1 Sx? (Sx>0) Sx? (Sx>0) 1.5 Sy? (Sy>0) Sy? (Sy>0) 1.5 ===> Veja o resultado! :) Veja o resultado! :) <===

13
12 Student Evaluation: Questions in Final Exams (1/2) General algorithm questions: In GNU-Octave a FOR instruction: is necessary to repeat the execution of several instructions; is used to take decisions in an algorithm; is necessary to implement recursive problems, such as a recursive function to calculate the factorial of an integer. is used to repeat the execution of several instructions for a precomputed range (or set) of values. None of the above options is correct Excel lookup questions: The first 50 lines in an Excel Worksheet have student grades in a given course. Column A contains the student number. Column B contains student's name and column C student's grade. The students are sorted by number. If there is a student with number 1335 what is the formula to get this student's grade? =hlookup(1335,A1:C50,1,TRUE); =hlookup(1335,A1:C50,3,FALSE); =vlookup(1335,C1:C50,3,FALSE); Simple algebra in Octave: If a = [1, 2, 3] then: a.*a' returns ans=14. a * a' returns ans=14. a * a returns ans=14. =vlookup(1335,A1:C50,3,FALSE); =vlookup(1335,C1:C50,1,TRUE); a + a returns ans=0. None of the above options is correct.

14
13 Student Evaluation: Questions in Final Exams (2/2) Programming: Programming: Given the following Octave function (defined in file gera.m): Given the following Octave function (defined in file gera.m): What are the values of variables m and n after executing the commands: What are the values of variables m and n after executing the commands: m=gera(5,3); n=gera(2,3); m=gera(5,3); n=gera(2,3); function v=gera(a,b) if (a>0 && a<=5) for i=1:a for j=1:b if (a>b) v(i,j)=0; else v(i,j)=1; endif endfor else v=0; endif endfunction

15
14 Assignments presented to students over the semesters

16
15 Analysis of student evaluation The evolution in learning how to program. Better results when knowledge evaluation was divided into two assignments. even greater improvement by replacing first assignment by Octave written exam (begins spring semester of 2002-03). S01/02W01/02S02/03W02/03 -correct/Accepted -No Reply -wRong

17
16 Analysis of student evaluation Relation between general Octave matrix manipulation and Octave programming. There is a strong relation between the success rate in replies to Octave matrix calculus and the success rate in the programming questions. Excel LOOKUP questions are correlated to simple programming questions. 37% accuracy in programming pass to 51% accuracy for students that reply to Excel LOOKUP question.

18
17 Conclusions GNU Octave is an excellent way to present computer programming to students. can replace and extend MS-Excel in numerical analysis studies. students easily start to use Octave command line for issuing basic algebra and numeric manipulation commands. Octave programming environment: It is just a simple prompt in the command line. Students tend to adapt relatively fast to the command line interface. More complex graphical interfaces: Are more suitable to user dispersion. Try to hide the algorithmic and command oriented computer. But it would be useful to show the state of a running program (as in a debugger). Graphically oriented problems are more attractive. Most students finished course with the main concepts regarding algorithmic knowledge and with a tool to apply in real life situations.

19
18 Thank you for your attention For additional information please contact the authors at Departamento de Informática FCT/ UNL Tel: (+351) 21 294 8536 Fax: 21 294 8541 EMAIL: nmm@di.fct.unl.pt (Please add subject: ICP ) Web-Page: http://ssdi.di.fct.unl.pt/~nmm/ICP For additional information please contact the authors at Departamento de Informática FCT/ UNL Tel: (+351) 21 294 8536 Fax: 21 294 8541 EMAIL: nmm@di.fct.unl.pt (Please add subject: ICP ) Web-Page: http://ssdi.di.fct.unl.pt/~nmm/ICP An algorithm? [ Pavão Martins 94]

Similar presentations

OK

Teaching Teaching Discrete Mathematics and Algorithms & Data Structures Online G.MirkowskaPJIIT.

Teaching Teaching Discrete Mathematics and Algorithms & Data Structures Online G.MirkowskaPJIIT.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on project tiger in india Ppt on waxes chemical structure Ppt on 5 star chocolate pie Ppt on non ferrous metals Ppt on national parks of india Ppt on agriculture system in india Ppt on question tags example Ppt on sanskritization and westernization Ppt on bluetooth communication Ppt on standing orders