1 / 13

Fundamentals of Programming 20-ENFD-112 Sections 001 to 007

Fundamentals of Programming 20-ENFD-112 Sections 001 to 007. Instructor: Prof. Dieter Schmidt Lecture: Monday, Wednesday 3:00-3:50 Web page http://www.blackboard.uc.edu. Overview of MATLAB. MATLAB Computer Algebra Program for solving mathematical problems in engineering

dacey
Download Presentation

Fundamentals of Programming 20-ENFD-112 Sections 001 to 007

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamentals of Programming20-ENFD-112 Sections 001 to 007 Instructor: Prof. Dieter Schmidt Lecture: Monday, Wednesday 3:00-3:50 Web page http://www.blackboard.uc.edu

  2. Overview of MATLAB • MATLAB • Computer Algebra Program for solving mathematical problems in engineering • MATLAB like a scientific calculator – but much much more. • Other Computer Algebra Programs • Mathematica, Maple, Magma, and others • Difference to MATLAB: These programs do most of their calculations in “symbolic” form and usually use exact “integer arithmetic” • MATLAB uses “floating point arithmetic”

  3. Availability of Computer Algebra Programs at UC • Mathematica • Site license for entire campus • Available in all labs • Individual copies can be bought in computer store • Used by Department of Mathematics in Computer Lab for calculus • MATLAB • Site license only for College of Engineering • Available only in labs (and classrooms) of College of Engineering under folder Mathematics • Individual student version can be bought for $100 • Used in several courses in CoE

  4. Student version of MATLAB • Same capabilities as full version • Prompt is EDU>> instead of >> • Restriction: no commercial use • Full version of MATLAB is expensive • It has many modules for different fields, the first two come with student version of MATLAB, others have to be bought • Simulink • Mathematics toolbox • Bioinformatics toolbox • Data Acquisition toolbox • Financial toolbox • Statistics toolbox • and others

  5. Starting MATLAB • MATLAB has to be installed • Double click on icon • For student version CD of MATLAB has to be in CD drive. • MATLAB desktop • Command Window • Command History Window • Current Directory Window

  6. Arithmetic Operations • Lowest precedence • + Addition: a+b • - Subtraction: a-b • Next higher precedence • * Multiplication: a*b • / right division: a/b • \ left division: a\b same as b/a • good for matrix operations, avoid otherwise • Highest precedence • ^ exponentiation: a^b • Evaluation from left to right for equal precedence • Use parentheses to change order

  7. Format statements, for display of results • format short displays up to 6 decimal digits 1.6667 • format long displays up to 16 decimal digits 1.666666666666667 • format short e base 10 notation 1.2345e+002 • format long e base 10 notation 16 digits • format bank two decimal digits 123.45 • format + displays only +,-, or blank (of limited use) • format rat displays rational approximation • format compact suppresses some line feeds • format loose undoes format compact • Internal representation: roughly 15-16 decimal digits accuracy • depends on computer • usually 64 bit binary floating point numbers, IEEE format

  8. Predefined values • ans always the result of the previous execution • eps accuracy of floating point numbers, that is, last binary digit (bit) that can not be stored • Inf numbers ≥ 2102410308 • NaN not a number i.e. 0/0 • pi Note with format rat: pi=355/113 • i,j imaginary unit sqrt(-1) • Watch out, these values can be redefined • This may lead to unexpected results • i,j are less of a problem, when correct format for complex numbers are used.

  9. Available Mathematical Functions • exp(x) • sqrt(x) • log(x) natural logarithm, base e • log10(x) base 10 • cos(x) • sin(x) • tan(x) • acos(x) cos -1(x) • asin(x) • atan(x) • and others

  10. Help within Matlab • In command window • help function • helpwin topic • lookfor topic • type filename • doc function • or use menu bar

  11. Plotting of functions • x = [ -10 : 0.1 : 10 ]; • y = sin(x) ; • plot( x, y), xlabel('x'), ylabel('y')

  12. Arrays • x=[-10 : 0.1 : 10] • x is an array of 201 values • -10,-9.9,-9.8,…,9.8,9.9,10.0 • x(1),x(2),x(3),…,x(199),x(200),x(201) • [start : increment : stop] • Note ":" with "," it would only be an array with three elements: • x=[-10 , 0.1 , 10] • gives x(1)=-10, x(2)=0.1, x(3)=10 • x(4) and others are now undefined

  13. Functions of arrays • Most built-in functions produce desired result • y = sin(x) produces array y of same length as x • plot(x,y) requires two arrays of same length • y = x^2 will not work, nor does y=x * x • for Matlab x is a matrix (array) • rules for matrix multiplication are different • to tell Matlab to do element by element operation need to write y = x.^2 or y =x.*x

More Related