1 / 17

Introduction to Matlab

Explore the fundamentals of Matlab – a high-level scientific language for efficient coding and data visualization. Learn about data types, arrays, strings, operators, flow control, loops, functions, and more. Enhance your Matlab skills with examples and tips.

rworthy
Download Presentation

Introduction to Matlab

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. Introduction to Matlab

  2. What is Matlab • Matlab is a high-level scientific language and data visualization. • Advantage over traditional programming languages is the ability for a much cleaner and shorter code and easy de-bugging. • Disadvantage is that the code is generally slower than compiled programs. • Very fast when code is written in terms of matrix operations.

  3. Fortran and Matlab Matlab Fortran Can be solved using simple command

  4. Data-types and variables • Data-types: int, double, char, logical, function-handle (@function) • Matlab has several in-built characters and variables

  5. Arrays Matlab differentiates between row and column vectors Defines an Array

  6. Strings

  7. Operators

  8. Comparison Operators Numbers are of the logical type Logical Operators

  9. if, else, elseif Flow Control 1: Conditionals switch

  10. To calculate cos(x) from 0 to 5 To calculate cos(x) from 0 to 5 Flow Control 2: Loops while for To calculate cos(x) from 0 to 5 break, to terminate a loop for loop should be avoided if calculation can be done by vectorized expression.

  11. continue, the control is passed to the next iteration Loops: Contd.. return, function can be forced to exit with this command error, execution of program is forced with a printed message

  12. Functions It has to be saved under the function_name.m Sub functions: Function in the same .m file as the main function Nested function: Function called in the main function. Function to solve the following equation using Newton-Raphson

  13. Functions-Contd.. The second function has to be store in file myfunc.m Will work only when myfunc.m is the file where the function is stored Generally not a good idea to tinker with a de-bugged code. Any change in the name of myfunc.m will make the code to fail. Good idea is to send the function through arguments so that it can be used for any function.

  14. Functions-Contd.. Inline functions Anonymous Functions

  15. Reading Printing Output Input/Output

  16. 1. Creating Arrays 5. Ones Array Manipulation 6. Rand 2. Colon Operator 7. Identity 3. Linspace 4. Zeros

  17. Length Array Functions Size Reshape dot prod sum cross

More Related