SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Matlab
Matlab is a tool for doing numerical computations with matrices and vectors. It can also
display information graphically. The best way to learn what Matlab can do is to work
through some examples at the computer. After reading the " getting started " section, you
can use the tutorial below for this.
Getting started
Tutorial
Matrices
Vectors
Systems of equations
Loops: a bit of programming
Graphing
Functions of one variable
Functions of two variables
Getting started
Here is a sample session with Matlab. Text in bold is what you type, ordinary text is what
the computer "types." You should read this example, then imitate it at the computer.
% matlab
>> a = [ 1 2; 2 1 ]
a=
1
2

2
1

>> a*a
ans =
5
4

4
5

>> quit
16 flops.
%
In this example you started Matlab by (you guessed it) typing matlab. Then you defined
matrix a and computed its square ("a times a"). Finally (having done enough work for one
day) you quit Matlab.
The tutorial below gives more examples of how to use Matlab. For best results, work
them out using a computer: learn by doing!
Matlab Tutorial
Matrices
To enter the matrix
12
34
and store it in a variable a, do this:
>> a = [ 1 2; 3 4 ]
Do this now: define the matrix a. Do the same with the examples below: work out each of
them with matlab. Learn by doing!
To redisplay the matrix, just type its name:
>> a
Once you know how to enter and display matrices, it is easy to compute with them. First
we will square the matrix a :
>> a * a
Wasn't that easy? Now we'll try something a little harder. First we define a matrix b:
>> b = [ 1 2; 0 1 ]
Then we compute the product ab:
>> a*b
Finally, we compute the product in the other order:
>> b*a
Notice that the two products are different: matrix multiplication is noncommmutative.
Of course, we can also add matrices:
>> a + b
Now let's store the result of this addition so that we can use it later:
>> s = a + b
Matrices can sometimes be inverted:
>> inv(s)
To check that this is correct, we compute the product of s and its inverse:
>> s * inv(s)
The result is the unit, or identity matrix. We can also write the computation as
>> s/s
We can also write
>> ss
which is the same as
>> inv(s) * s
To see that these operations, left and right division, are really different, we do the
following:
>> a/b
>> ab
Not all matrices can be inverted, or used as the denominator in matrix division:
>> c = [ 1 1; 1 1 ]
>> inv(c);
A matrix can be inverted if and only if its determinant is nonzero:
>> det(a)
>> det(c)
Vectors
Systems of equations
Now consider a linear equation
ax + by = p
cx + dy = q
We can write this more compactly as
AX = B
where the coefficient matrix A is
ab
cd
the vector of unknowns is
x
y
and the vector on the right-hand side is
p
q
If A is invertible, X = (1/A)B, or, using Matlab notation, X = AB. Lets try this out by
solving ax = b with a as before and b = [ 1; 0 ]. Note that b is a column vector.
>> b = [ 1; 0 ]
>> ab
Loops
Finally, we will do a little piece of programming. Let a be the matrix
0.8 0.1
0.2 0.9
and let x be the column vector
1
0
We regard x as representing (for example) the population state of an island. The first
entry (1) gives the fraction of the population in the west half of the island, the second
entry (0) give the fraction in the east half. The state of the population T units of time later
is given by the rule y = ax. This expresses the fact that an individual in the west half stays
put with probability 0.8 and moves east with probability 0.2 (note 0.8 + 0.2 = 1), and the
fact that in individual in the east stays put with probability 0.9 and moves west with
probability 0.1. Thus, successive population states can be predicted/computed by
repeated matrix multiplication. This can be done by the following Matlab program:
>> a = [ 0.8 0.1; 0.2 0.9 ]
>> x = [ 1; 0 ]
>> for i = 1:20, x = a*x, end
What do you notice? Is there an explanation? Is there a lesson to be learned?
Remark: you have just learned to write a kind of loop, a so-called for loop. This is an
easy way to command the machine, in just a few words, to do much repetitive work.
Graphing
Functions of one variable
To make a graph of y = sin(t) on the interval t = 0 to t = 10 we do the following:
>> t = 0:.3:10;
>> y = sin(t);
>> plot(t,y)
Here is the result:
The command t = 0:.3:10; defines a vector with components ranging from 0 to 10 in steps
of 0.3. The y = sin(t); defines a vector whose components are sin(0), sin(0.3), sin(0.6),
etc. Finally, plot(t,y) use the vector of t and y values to construct the graph.
Functions of two variables
Here is how we graph the fuction z(x,y) = x exp( - x^2 - y^2):
>> [x,y] = meshdom(-2:.2:2, -2:.2:2);
>> z = x .* exp(-x.^2 - y.^2);
>> mesh(z)

The first command creates a matrix whose entries are the points of a grid in the square -2
<= x <= 2, -2 <= y <= 2. The small squares which make up the grid are 0.2 units wide
and 0.2 unit tall. The second command creates a matrix whose entries are the values of
the function z(x,y) at the grid points. The third command uses this information to
construct the graph.
Back to Department of Mathematics, University of Utah
Functions of one variable
To make a graph of y = sin(t) on the interval t = 0 to t = 10 we do the following:
>> t = 0:.3:10;
>> y = sin(t);
>> plot(t,y)
Here is the result:
The command t = 0:.3:10; defines a vector with components ranging from 0 to 10 in steps
of 0.3. The y = sin(t); defines a vector whose components are sin(0), sin(0.3), sin(0.6),
etc. Finally, plot(t,y) use the vector of t and y values to construct the graph.
Functions of two variables
Here is how we graph the fuction z(x,y) = x exp( - x^2 - y^2):
>> [x,y] = meshdom(-2:.2:2, -2:.2:2);
>> z = x .* exp(-x.^2 - y.^2);
>> mesh(z)

The first command creates a matrix whose entries are the points of a grid in the square -2
<= x <= 2, -2 <= y <= 2. The small squares which make up the grid are 0.2 units wide
and 0.2 unit tall. The second command creates a matrix whose entries are the values of
the function z(x,y) at the grid points. The third command uses this information to
construct the graph.
Back to Department of Mathematics, University of Utah

Weitere ähnliche Inhalte

Was ist angesagt?

Gauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingGauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingSM. Aurnob
 
Jacobi iteration method
Jacobi iteration methodJacobi iteration method
Jacobi iteration methodMONIRUL ISLAM
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesShameer Ahmed Koya
 
Matlab practice
Matlab practiceMatlab practice
Matlab practiceZunAib Ali
 
Solution of matlab chapter 6
Solution of matlab chapter 6Solution of matlab chapter 6
Solution of matlab chapter 6AhsanIrshad8
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlabMohammad Alauddin
 
Matlab Sample Assignment Solution
Matlab Sample Assignment SolutionMatlab Sample Assignment Solution
Matlab Sample Assignment SolutionAll Assignment Experts
 
Non linear curve fitting
Non linear curve fitting Non linear curve fitting
Non linear curve fitting Anumita Mondal
 
Solution of matlab chapter 2
Solution of matlab chapter 2Solution of matlab chapter 2
Solution of matlab chapter 2AhsanIrshad8
 
5 octave tutorial
5 octave tutorial5 octave tutorial
5 octave tutorialTanmayVijay1
 
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsMATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsShameer Ahmed Koya
 
Maths4ml linearalgebra-formula
Maths4ml linearalgebra-formulaMaths4ml linearalgebra-formula
Maths4ml linearalgebra-formulaNishant Upadhyay
 

Was ist angesagt? (20)

Gauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial PivotingGauss Elimination Method With Partial Pivoting
Gauss Elimination Method With Partial Pivoting
 
Es272 ch3b
Es272 ch3bEs272 ch3b
Es272 ch3b
 
Jacobi iteration method
Jacobi iteration methodJacobi iteration method
Jacobi iteration method
 
Lecture one
Lecture oneLecture one
Lecture one
 
Es272 ch1
Es272 ch1Es272 ch1
Es272 ch1
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Matlab practice
Matlab practiceMatlab practice
Matlab practice
 
Solution of matlab chapter 6
Solution of matlab chapter 6Solution of matlab chapter 6
Solution of matlab chapter 6
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
 
Mbd2
Mbd2Mbd2
Mbd2
 
Lecture three
Lecture threeLecture three
Lecture three
 
Matlab Sample Assignment Solution
Matlab Sample Assignment SolutionMatlab Sample Assignment Solution
Matlab Sample Assignment Solution
 
Non linear curve fitting
Non linear curve fitting Non linear curve fitting
Non linear curve fitting
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
 
Solution of matlab chapter 2
Solution of matlab chapter 2Solution of matlab chapter 2
Solution of matlab chapter 2
 
5 octave tutorial
5 octave tutorial5 octave tutorial
5 octave tutorial
 
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsMATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
 
Maths4ml linearalgebra-formula
Maths4ml linearalgebra-formulaMaths4ml linearalgebra-formula
Maths4ml linearalgebra-formula
 

Ă„hnlich wie Matlabtut1

MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxandreecapon
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxagnesdcarey33086
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptxSungaleliYuen
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.pptkebeAman
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxanhlodge
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptnaveen_setty
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.pptaboma2hawi
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabDnyanesh Patil
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsMukesh Kumar
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptximman gwu
 
A MATLAB project on LCR circuits
A MATLAB project on LCR circuitsA MATLAB project on LCR circuits
A MATLAB project on LCR circuitssvrohith 9
 
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docxLab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docxsmile790243
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabBilawalBaloch1
 

Ă„hnlich wie Matlabtut1 (20)

MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
matlab_tutorial.ppt
matlab_tutorial.pptmatlab_tutorial.ppt
matlab_tutorial.ppt
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
bobok
bobokbobok
bobok
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Matlab
MatlabMatlab
Matlab
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
A MATLAB project on LCR circuits
A MATLAB project on LCR circuitsA MATLAB project on LCR circuits
A MATLAB project on LCR circuits
 
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docxLab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 

Mehr von Vinnu Vinay

Mehr von Vinnu Vinay (10)

Matlab tut3
Matlab tut3Matlab tut3
Matlab tut3
 
Matlab tut2
Matlab tut2Matlab tut2
Matlab tut2
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
Lesson 8
Lesson 8Lesson 8
Lesson 8
 
Lesson 7
Lesson 7Lesson 7
Lesson 7
 
Lesson 6
Lesson 6Lesson 6
Lesson 6
 
Lesson 5
Lesson 5Lesson 5
Lesson 5
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Lesson 2
Lesson 2Lesson 2
Lesson 2
 
matlab Lesson 1
matlab Lesson 1matlab Lesson 1
matlab Lesson 1
 

KĂĽrzlich hochgeladen

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

KĂĽrzlich hochgeladen (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

Matlabtut1

  • 1. Matlab Matlab is a tool for doing numerical computations with matrices and vectors. It can also display information graphically. The best way to learn what Matlab can do is to work through some examples at the computer. After reading the " getting started " section, you can use the tutorial below for this. Getting started Tutorial Matrices Vectors Systems of equations Loops: a bit of programming Graphing Functions of one variable Functions of two variables Getting started Here is a sample session with Matlab. Text in bold is what you type, ordinary text is what the computer "types." You should read this example, then imitate it at the computer. % matlab >> a = [ 1 2; 2 1 ] a= 1 2 2 1 >> a*a ans = 5 4 4 5 >> quit 16 flops. % In this example you started Matlab by (you guessed it) typing matlab. Then you defined matrix a and computed its square ("a times a"). Finally (having done enough work for one day) you quit Matlab. The tutorial below gives more examples of how to use Matlab. For best results, work them out using a computer: learn by doing! Matlab Tutorial
  • 2. Matrices To enter the matrix 12 34 and store it in a variable a, do this: >> a = [ 1 2; 3 4 ] Do this now: define the matrix a. Do the same with the examples below: work out each of them with matlab. Learn by doing! To redisplay the matrix, just type its name: >> a Once you know how to enter and display matrices, it is easy to compute with them. First we will square the matrix a : >> a * a Wasn't that easy? Now we'll try something a little harder. First we define a matrix b: >> b = [ 1 2; 0 1 ] Then we compute the product ab: >> a*b Finally, we compute the product in the other order: >> b*a Notice that the two products are different: matrix multiplication is noncommmutative. Of course, we can also add matrices: >> a + b Now let's store the result of this addition so that we can use it later: >> s = a + b Matrices can sometimes be inverted: >> inv(s) To check that this is correct, we compute the product of s and its inverse:
  • 3. >> s * inv(s) The result is the unit, or identity matrix. We can also write the computation as >> s/s We can also write >> ss which is the same as >> inv(s) * s To see that these operations, left and right division, are really different, we do the following: >> a/b >> ab Not all matrices can be inverted, or used as the denominator in matrix division: >> c = [ 1 1; 1 1 ] >> inv(c); A matrix can be inverted if and only if its determinant is nonzero: >> det(a) >> det(c) Vectors Systems of equations Now consider a linear equation ax + by = p cx + dy = q We can write this more compactly as AX = B where the coefficient matrix A is ab cd
  • 4. the vector of unknowns is x y and the vector on the right-hand side is p q If A is invertible, X = (1/A)B, or, using Matlab notation, X = AB. Lets try this out by solving ax = b with a as before and b = [ 1; 0 ]. Note that b is a column vector. >> b = [ 1; 0 ] >> ab Loops Finally, we will do a little piece of programming. Let a be the matrix 0.8 0.1 0.2 0.9 and let x be the column vector 1 0 We regard x as representing (for example) the population state of an island. The first entry (1) gives the fraction of the population in the west half of the island, the second entry (0) give the fraction in the east half. The state of the population T units of time later is given by the rule y = ax. This expresses the fact that an individual in the west half stays put with probability 0.8 and moves east with probability 0.2 (note 0.8 + 0.2 = 1), and the fact that in individual in the east stays put with probability 0.9 and moves west with probability 0.1. Thus, successive population states can be predicted/computed by repeated matrix multiplication. This can be done by the following Matlab program: >> a = [ 0.8 0.1; 0.2 0.9 ] >> x = [ 1; 0 ] >> for i = 1:20, x = a*x, end What do you notice? Is there an explanation? Is there a lesson to be learned? Remark: you have just learned to write a kind of loop, a so-called for loop. This is an easy way to command the machine, in just a few words, to do much repetitive work. Graphing
  • 5. Functions of one variable To make a graph of y = sin(t) on the interval t = 0 to t = 10 we do the following: >> t = 0:.3:10; >> y = sin(t); >> plot(t,y) Here is the result: The command t = 0:.3:10; defines a vector with components ranging from 0 to 10 in steps of 0.3. The y = sin(t); defines a vector whose components are sin(0), sin(0.3), sin(0.6), etc. Finally, plot(t,y) use the vector of t and y values to construct the graph. Functions of two variables Here is how we graph the fuction z(x,y) = x exp( - x^2 - y^2): >> [x,y] = meshdom(-2:.2:2, -2:.2:2); >> z = x .* exp(-x.^2 - y.^2); >> mesh(z) The first command creates a matrix whose entries are the points of a grid in the square -2 <= x <= 2, -2 <= y <= 2. The small squares which make up the grid are 0.2 units wide and 0.2 unit tall. The second command creates a matrix whose entries are the values of the function z(x,y) at the grid points. The third command uses this information to construct the graph. Back to Department of Mathematics, University of Utah
  • 6. Functions of one variable To make a graph of y = sin(t) on the interval t = 0 to t = 10 we do the following: >> t = 0:.3:10; >> y = sin(t); >> plot(t,y) Here is the result: The command t = 0:.3:10; defines a vector with components ranging from 0 to 10 in steps of 0.3. The y = sin(t); defines a vector whose components are sin(0), sin(0.3), sin(0.6), etc. Finally, plot(t,y) use the vector of t and y values to construct the graph. Functions of two variables Here is how we graph the fuction z(x,y) = x exp( - x^2 - y^2): >> [x,y] = meshdom(-2:.2:2, -2:.2:2); >> z = x .* exp(-x.^2 - y.^2); >> mesh(z) The first command creates a matrix whose entries are the points of a grid in the square -2 <= x <= 2, -2 <= y <= 2. The small squares which make up the grid are 0.2 units wide and 0.2 unit tall. The second command creates a matrix whose entries are the values of the function z(x,y) at the grid points. The third command uses this information to construct the graph. Back to Department of Mathematics, University of Utah