1 / 14

Introduction to Matlab

Introduction to Matlab. Can be programmed just like Fortran Adds visualization support Kinda like your graphing calculator Adds Matrix/Array support. Variables & Data Types. Unlike Fortran there are NO data types to be declared

zarek
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 • Can be programmed just like Fortran • Adds visualization support • Kinda like your graphing calculator • Adds Matrix/Array support

  2. Variables & Data Types • Unlike Fortran there are NO data types to be declared • Variables can support Real, Integer, String, and Imaginary numbers • To create a variable, simply use it

  3. Simple Examples %Example1.m X=5; Y=3; Z=3X^2+5; Z % character denotes the start of a comment lines that end with a “;” are simply run lines that do not end with a “;” are run and results displayed on command window

  4. .m Files • Once your program has been saved as a .m file it can be run by either pressing F5 in the editor or by typing the file name in the command window • Other .m files maybe be run from within different .m files

  5. Working with Matrices/Arrays • Matlab is made to deal with Matrices and Arrays much simpler than Fortran • Variable(X,Y,Z) can be used to access each element • Just as in Fortran Loops can be used to perform functions

  6. Loop Example %Example2.m - Loop for i=1:40 x(i)=i; y(i)=i^2; end plot(x,y); plot(x,y) creates a 2D plot and displays it

  7. Results

  8. An Easier Way • When dealing with large amounts of data, loops in Matlab can be very inefficient • Matlab allows mathematical operations to be performed directly on a entire array or matrix (This is called a vector operation as opposed to a scalar operation)

  9. Modified Loop Example %Example3.m - Loop x=linspace(1,40,40); %Linspace creates an array 1 to 40 of 40 elements y=x.^2; plot(x,y); In Matlab matrix/array math .^ .* and ./ performs those operations on a element by element basis While ^ * / when performed on a matrix will attempt to perform matrix math

  10. Matrix vs Element Math Element Math Matrix Math

  11. Circuit Example 10 Ohms + 10V - 3uF 0.01 H I=V/R=10 /

  12. RLC Series .m File %Example4.m - RLC w=linspace(1,40000,1000); i=10./(10+(1./(j.*w.*3.*10^-6))+(j.*w.*0.01)); plot(w,abs(v)); j is intrinsically unless its redefined

  13. RLC series result

  14. 10 Ohms 1A 9uF 0.08 H Assignment #1 1. Write a matlab program to determine the frequency response of the voltage across this RLC circuit 2. Provide Magnitude and Phase plots of this circuit (Remember to label graphs) 3. Bonus: Explore usage of subplot commands to do multiple plots on the same graph

More Related