Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Lec2

360 views

Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

Lec2

  1. 1. Matlab 7Lec 2-Fundamentals
  2. 2. Topicsvariables, operators and expressions;arrays (including vectors and matrices);basic input and output;repetition (for);decision (if);
  3. 3. Variablesmust start with a lettercan be alphabets (a-z), digits 0-9,underscore(_)may be as long as you likeMatlab rem only first 31 charactersEg r2d2 dhoni walle nano etcPay – day ,2s , name$ galtiyaaaaaaaannnn????????Official Matlab Documentation refers variables as Arraysscalar or vectorerror message:??? Undefined function or variable ...
  4. 4. Matlab is Case Sensitivecamel Caps method eg. camelCapsCommand and Function names are case sensitive
  5. 5. Workspacevariables you create during a session remain in workspaceuntill you clear them using clearwhos – size of variables who diff dekhoans – function=lastvalue of exp evaluated but not assigned to a variable example socho!double = holds a numeric value = double precision floating pointclear vname1 vname2Workspace Browser
  6. 6. the myconstant.m exampleg=9.8;avo=6.23e23run myconstant at start of session,Workspace is loaded
  7. 7. Arrays : Vectors and MatricesBasic Idea Of a Matrix – Rows and ColumnsVector – Special Type of Matrix,1 Row,1 Column; called list or arrays in some other Prog LangMatlab Handles Vectors and Matrices in a Same Manner
  8. 8. VectorsEnter a statement in command line :x = [1 3 0 -1 5]Now enter disp(x) to see vector kaise dikhta haiAlso try y = [2,3,5]Then whos command or size(y) commandIska o/p kya hoga ? : - x =[130-15] bataaaaaoooooo?????a = [ 1 2 3]b = [4 5]c = [ a –b]Iska o/p bataaaaaooo ab????????
  9. 9. Iske bare me kya khyal hai?? :a = [1 3 7];a = [a 0 -1];Vector can also be initialized asx = 1:10;x = 1:0.5:4;x=1:2:6 try karo! Kya galti hai statement me????x=0:-2:-5This is list method of initializing!make sure1.Elements in list must be enclosed in square bracket2.Shud be separated by either space or commas
  10. 10. Ek aur tarika hai ki ap linspace function use karo!Yeh try karolinspace(0,pi/2,10)Ye 10 equally space points ka vector create karta hai0 and pi include karke
  11. 11. Transposing vectors sanjhte hai ab:::Abhi tak Row vectors me khel rahe the abhi column vectors meate hai!U need to transpose the row vectors to get column vectorsTry thisy=[ 1 4 8 0 -1]’Sign used is the aposthrophe
  12. 12. Ab ati hai vectors ki subscripts:Try thisRow vector of 7 random nosr = rand(1,7)Ab try karor(3)Isme joh no. 3 dale hai who subscript hai!Iske jawab do sochke and karker(2:4)r(1:2:7)r([1 7 2 6])
  13. 13. Conclusion abt subscripts:Subscript is indicated inside () bracketsIt may be a scalar or vectorSubscript always starts at 1Fractional subscripts r always rounded downx(1.9) will be x(1)
  14. 14. MatricesMatrix = rows and columnsTry thisa = [ 1 2 3;4 5 6 ]Ab apna transpose ka knowledge jhalkao!!!!Try a’Hum matrix same length ke vectors se bhi bana sakte hai!x=0:30:180;table = [ x sin(x*pi/180)]
  15. 15. Capturing o/pEither copy pasteYa try thisdiary kp2diary off
  16. 16. DANCE TIME SURPRISE
  17. 17. Problem statement:The equation for vertical motion under gravity is given byS = ut – ½ gt^2We ve to compute the value of s over a period of abt 12.3 secAt intervals of 0.1 secInitial velocity 60 m/sec lijiye g = 9.8M-file banaiyeSabse pahile 4 points ka structure plan sochiye and paper pe likhiye!next silde se match karke dekhiye ki kya ap sahi hai ya ap kitte sahi hai????
  18. 18. Structure Plan1. Assign the data (g, u and t) to MATLAB variables.2. Calculate the value of s according to the formula.3. Plot the graph of s against t.4. Stop.
  19. 19. t wala statement vector initialize karta hai. Operator ko dekho ye vectors ke liye hai!bad hum discuss karenge!Formula for s is evaluated for every element of vector t making another vectorDisp command ka use table display ke liye,,,, and … ka use
  20. 20. OVERRRRRRRRR aj ke liye

×