Lecture 3 Creating M - files
Số trang: 17
Loại file: ppt
Dung lượng: 241.50 KB
Lượt xem: 18
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Programming tools:Input/output (assign/graph-&-display)Repetition (for)Decision (if)ArraysList of numbers in bracketsA comma or space separates numbers (columns)A semicolon separates rowZeros and ones Matrices: zeros() ones()Indexing(row,column)Colon Operator: Range of Data first:last or first:increment:lastManipulating Arrays & MatricesTranspose
Nội dung trích xuất từ tài liệu:
Lecture 3 Creating M - files Lecture3 Lecture3 CreatingMfiles Programmingtools: Input/output (assign/graph&display) Repetition(for) Decision(if)© 2007 Daniel Valentine. All rights reserved. Published byElsevier. Review Review Arrays – Listofnumbersinbrackets Acommaorspaceseparatesnumbers(columns) Asemicolonseparatesrow – ZerosandonesMatrices: zeros() ones() – Indexing (row,column) – ColonOperator: RangeofDatafirst:lastorfirst:increment:last – ManipulatingArrays&Matrices Transpose Input Input Examples of input to arrays: – Single number array & scalar: 1×1 >> a = 2 >> – Row array & row vector: 1×n >> b = [1 3 2 5] >> [1 – Column array & column vector: nx1 >> b = b’ % This an application of the transpose. >> This – Array of n rows x m columns & Matrix: n × m >> c = [1 2 3; 4 5 6; 7 6 9] % This example is 3 x 3. >> This Basicelementsofaprogram Basicelementsofaprogram Input – Initialize,defineorassignnumericalvaluesto variables. Setofcommandexpressions – Operationsappliedtoinputvariablesthatlead tothedesiredresult. Output – Display(graphicallyornumerically)result. Anexampleoftechnicalcomputing Anexampleoftechnicalcomputing Letusconsiderusingthehyperbolictangent tomodeladownhillsectionofasnowboard orsnowskifacility. Letusfirstexaminethehyperbolictangent functionbyexecutingthecommand: >>ezplot(‘tanh(x)’) Wegetthefollowinggraph:Ezplot(‘tanh(x)’)Ezplot(‘tanh(x)’) Hyperbolictangent:tanh(X) Hyperbolictangent:tanh(X) Properties(asillustratedinthefigure): – AsXapproaches–Inf,tanh(X)approaches1. – AsXapproachesInf,tanh(X)approaches+1. – X=0,tanh(X)=0. – Transitionfrom1to1issmoothandmost rapid(roughlyspeaking)intherange 2 Problembackground Problembackground Letusconsiderthedesignofaslopethat istobemodeledbytanh(X).Considerthe range3FormulaforsnowhillshapeFormulaforsnowhillshape Problemstatement Problemstatement Findthealtitudeofthehillat0.5meter intervalsfrom5metersto5metersusing theshapedescribedandillustratedinthe previoustwoslides. Tabulatetheresults. Structureplan Structureplan Structureplan – InitializetherangeofXin0.5meterintervals. – Computey,thealtitude,withtheformula: y=1–tanh(3*X/5). – Displaytheresultsinatable. Implementationofthestructureplan – Opentheeditorbytypingeditinthecommand window. – TranslateplanintotheMfilelanguage. SOLUTION TO IN-CLASS EXERCISE C o m m a n d w i n d o w OUTPUT Thisisfromeditor:Itis XY lec3.m 5.00001.9951% 4.50001.9910%Skislopeoffsetsforthe 4.00001.9837%HYPERBOLICTANGENTDESIGN 3.50001.9705%byD.T.Valentine...January2007 3.00001.9468% 2.50001.9051%Pointsatwhichthefunction 2.00001.8337%istobeevaluated: 1.50001.7163 1.00001.5370%Step1:Inputx 0.50001.2913x=5:0.5:5; 01.0000%Step2:Computetheyoffset, 0.50000.7087%thatis,thealtitude: 1.00000.4630y=1tanh(3.*x./5); 1.50000.2837% 2.00000.1663%Step3:Displayresultsinatable 2.50000.0949% 3.00000.0532 3.50000.0295disp()%Skipsaline 4.00000.0163disp(XY) 4.50000.0090disp([xy]) 5.00000.0049 Useofrepetition(‘for’) Useofrepetition(‘for’) Repetition:Inthepreviousexample,the fastestwaytocomputeywasused.An alternativewayisasfollows: Replace:y=1tanh(3.*x./5);%Thisis“vectorized”approach. With: forn=1:21 y(n)=1tanh(3*x(n)/5); end Remark:Ofcourse,theoutputisthesame. SOLUTION TO IN-CLASS EXERCISE C o m m a n d w i n d o w OUTPUT Thisisfromeditor:Itis X ...
Nội dung trích xuất từ tài liệu:
Lecture 3 Creating M - files Lecture3 Lecture3 CreatingMfiles Programmingtools: Input/output (assign/graph&display) Repetition(for) Decision(if)© 2007 Daniel Valentine. All rights reserved. Published byElsevier. Review Review Arrays – Listofnumbersinbrackets Acommaorspaceseparatesnumbers(columns) Asemicolonseparatesrow – ZerosandonesMatrices: zeros() ones() – Indexing (row,column) – ColonOperator: RangeofDatafirst:lastorfirst:increment:last – ManipulatingArrays&Matrices Transpose Input Input Examples of input to arrays: – Single number array & scalar: 1×1 >> a = 2 >> – Row array & row vector: 1×n >> b = [1 3 2 5] >> [1 – Column array & column vector: nx1 >> b = b’ % This an application of the transpose. >> This – Array of n rows x m columns & Matrix: n × m >> c = [1 2 3; 4 5 6; 7 6 9] % This example is 3 x 3. >> This Basicelementsofaprogram Basicelementsofaprogram Input – Initialize,defineorassignnumericalvaluesto variables. Setofcommandexpressions – Operationsappliedtoinputvariablesthatlead tothedesiredresult. Output – Display(graphicallyornumerically)result. Anexampleoftechnicalcomputing Anexampleoftechnicalcomputing Letusconsiderusingthehyperbolictangent tomodeladownhillsectionofasnowboard orsnowskifacility. Letusfirstexaminethehyperbolictangent functionbyexecutingthecommand: >>ezplot(‘tanh(x)’) Wegetthefollowinggraph:Ezplot(‘tanh(x)’)Ezplot(‘tanh(x)’) Hyperbolictangent:tanh(X) Hyperbolictangent:tanh(X) Properties(asillustratedinthefigure): – AsXapproaches–Inf,tanh(X)approaches1. – AsXapproachesInf,tanh(X)approaches+1. – X=0,tanh(X)=0. – Transitionfrom1to1issmoothandmost rapid(roughlyspeaking)intherange 2 Problembackground Problembackground Letusconsiderthedesignofaslopethat istobemodeledbytanh(X).Considerthe range3FormulaforsnowhillshapeFormulaforsnowhillshape Problemstatement Problemstatement Findthealtitudeofthehillat0.5meter intervalsfrom5metersto5metersusing theshapedescribedandillustratedinthe previoustwoslides. Tabulatetheresults. Structureplan Structureplan Structureplan – InitializetherangeofXin0.5meterintervals. – Computey,thealtitude,withtheformula: y=1–tanh(3*X/5). – Displaytheresultsinatable. Implementationofthestructureplan – Opentheeditorbytypingeditinthecommand window. – TranslateplanintotheMfilelanguage. SOLUTION TO IN-CLASS EXERCISE C o m m a n d w i n d o w OUTPUT Thisisfromeditor:Itis XY lec3.m 5.00001.9951% 4.50001.9910%Skislopeoffsetsforthe 4.00001.9837%HYPERBOLICTANGENTDESIGN 3.50001.9705%byD.T.Valentine...January2007 3.00001.9468% 2.50001.9051%Pointsatwhichthefunction 2.00001.8337%istobeevaluated: 1.50001.7163 1.00001.5370%Step1:Inputx 0.50001.2913x=5:0.5:5; 01.0000%Step2:Computetheyoffset, 0.50000.7087%thatis,thealtitude: 1.00000.4630y=1tanh(3.*x./5); 1.50000.2837% 2.00000.1663%Step3:Displayresultsinatable 2.50000.0949% 3.00000.0532 3.50000.0295disp()%Skipsaline 4.00000.0163disp(XY) 4.50000.0090disp([xy]) 5.00000.0049 Useofrepetition(‘for’) Useofrepetition(‘for’) Repetition:Inthepreviousexample,the fastestwaytocomputeywasused.An alternativewayisasfollows: Replace:y=1tanh(3.*x./5);%Thisis“vectorized”approach. With: forn=1:21 y(n)=1tanh(3*x(n)/5); end Remark:Ofcourse,theoutputisthesame. SOLUTION TO IN-CLASS EXERCISE C o m m a n d w i n d o w OUTPUT Thisisfromeditor:Itis X ...
Tìm kiếm theo từ khóa liên quan:
Programming tools Basic elements of a program environment for numerical computation control systems Creating M-files in matlab language of technical computingGợi ý tài liệu liên quan:
-
Accounting and Finance for Your Small Business
310 trang 19 0 0 -
905 trang 18 0 0
-
Accounting and Finance for Your Small Business - STEVEN M. BRAGG AND E. JAMES BURTON
315 trang 17 0 0 -
107 trang 15 0 0
-
129 trang 13 0 0
-
Ebook Wiley acing the gate: Electrical engineering - Part 1
643 trang 12 0 0 -
Leaderless - and leader-follower matrix-weighted consensus with uncertainties
9 trang 11 0 0 -
Master's thesis of Engineering: Evaluation of SLAM algorithms in realistic sensor test conditions
99 trang 10 0 0 -
Lecture Software Engineering - Chapter 15: Real-time software design
54 trang 8 0 0 -
Nonlinear stability control of inverted pendulum on a cart using LQR-based T-S fuzzy control
15 trang 4 0 0