《chapter 1-matlab programming for engineerszyn》由会员分享,可在线阅读,更多相关《chapter 1-matlab programming for engineerszyn(40页珍藏版)》请在金锄头文库上搜索。
1、Matlab Programming for EngineersRoom 414, EE/AC, SYSUEmails: ynzhangieee.org, Yunong Zhang (张雨浓)http:/ is Matlab?Why do we learn Matlab?How do we learn Matlab?IntroductionA Brief History of MatlabnEngineering and scientific applications involve a lot of number crunching.nFor many years, the main lan
2、guage for this was FORTRAN - first high level programming language, and especially designed for numerical computing.nHeres a Fortran code to solve ax2 + b x + c = 0:C Solve a quadratic equation (this is a comment). DESC = B*B - 4*A*C IF ( DESC .LT. 0.0 ) GOTO 10 DESC = SQRT(DESC) X1 = (-B + DESC)/(2
3、.0*A) X2 = (-B - DESC)/(2.0*A) WRITE(6,*) SOLUTIONS ARE ,X1, AND , X2 RETURN 10 WRITE(6,*) EQUATION HAS COMPLEX ROOTS RETURNProblems using FORTRANNumber crunching on a computer can be tricky.Problems that occur are:nloss of precision and inaccurate results:X = 0.1Y = 1.0 - 10*X Y should equal 0, but
4、 probably does not! nunderflow and overflow: X = 1.0E20, X*X - too big!nefficient coding of algorithms not always obvious DO 10 N=1,100000 10 Y(N) = SQRT(2.0)*X(N) which crossC:MATLAB6p5toolboxmatlabspecfuncross.mGetting HelpnGet help in three ways in MatlabnClick Toolbar icon to start the Help Brow
5、sernType help specificfunction in Command Window help sin SIN Sine. SIN(X) is the sine of the elements of X.nType lookfor specificfunction in Command WindowGetting Help (cont.)nHelp Browser: Allow full access to the entire Matlab documentation setnhelp functionname: You must know the name of the fun
6、ction to get help about itnlookfor functionname: Search for a given string in the first comment line of every Matlab function, and display all matches help a a.m not found. lookfor aADDPATH Add directory to search path.BINPATCH Patch binary file.CD Change current working directory.CLEAR Clear variables and functions from memory.DATATIPINFO Produce a short description of a variable.DBCLEAR Remove breakpoint.DBDOWN Change local workspace context.DBSTACK Display function call stack.DBSTATUS List all the breakpoints.