851 views

Original Title: MATLAB
MATLAB lab manual
numerical methods and matlab

Uploaded by Javaria Chiragh

- HSC NUMERICAL METHOD MATHS II WITH SOLUTION
- Numerical Technique Lab Manual
- Numerical Methods in Matlab
- An Introduction to Numerical Methods.a Matlab Approach
- Numerical methods for engineers
- matlab
- Numerical Methods using MATLAB
- Matlab Lab Manual
- Separation Process
- numerical methods-lab-manual
- MATLAB Tutorial 5 - Numerical Integration
- Numerical Methods with MATLAB.pdf
- Matlab
- Res Sedimentation Handbook 1.04
- Matlab Tutorial2
- Numerical Analysis MCQ
- Numerical Methods Using MATLAB 4ed Solution Manual
- Matlab Tutorial
- [Solution Manual] Numerical Methods by Vedamurthy
- Baccarat

You are on page 1of 14

Using MATLAB, we can solve technical computing problems faster than with traditional programming languages.

Numerical Methods:

Working in MATLAB:

Those are the methods by which mathematical problems are formulated so that they can be solved using arithmetic and logical operations. MATLAB provides a very nice tool to implement NUMERICAL METHODS. MATLAB can be employed to compute quantities and illustrate their graphical capabilities.

When we start MATLAB, the desktop appears in its default layout. MATLAB uses three primary windows : 1. Command Window-> Used to enter Commands and Data. 2. Graphics Window-> Used to Display plots and graphs. 3. Edit Window-> Used to create and edit m-files. Desktops default layout contains: Command Window Enter commands at the command line, indicated by the prompt (>>). Workspace The workspace contains variables that we create within or import into MATLAB from data files or other programs. Command History View or rerun commands that you entered at the command line.

Matlab Basics:

Variables and Assignment statements are used. There are many built-in functions in MATLAB Some of built-in functions are: abs( ), cos( ), exp( ), log( ), log10( ), sqrt( ), atan( ), etc. The reserved words or key words or name of built-in functions are NOT to be used. Expressions can be created using values, variables that have already been created, operators, built-in-functions, and parenthesis. Echo printing means to perform operation but not show the results this is done by placing semi colon ; at the end of statement.

M-Files and Script Files are used to execute a set of different commends at a time. If needed, corrections or changes can be made to the commands in the file. The files that are used for this purpose are called script files or scripts for short. A script file is an external file that contains a sequence of MATLAB statements. Script files have a filename extension .m and are often called M-files. M-files can be scripts that simply execute a series of MATLAB statements, or they can be functions that can accept arguments and can produce one or more outputs. Functions are programs (or routines) that accept input arguments and return output arguments. Each M-file function (or function or M-file for short) has its own area of workspace, separated from the MATLAB base workspace.

Clc: Clears the commend window. Clear: remove all the variables from memory. Format short: Format long: %: used for comments.

2

Arrays:

A rectangular arrangement of numbers is called an array. 1-by-1 arrays are also called scalars 1-by-N arrays are also called row vectors

N-by-1 arrays are also called column vectors

Row and Column vectors are also sometimes just called vectors In Matlab, all arrays of numbers are called double arrays. If we say that Array is two or three dimensional it is called Matrix.

c= [1,2; 3,4] It is a 2 x 2 matrix or 2 x 2 array. sum( ) ,mean( ) , length( ) ,max( ) ,min( ) , prod( ) , sign( ) ,fix( ) ,floor( ) ,ceil( ) ,round( ) , sort( ) are some functions that can be used on matrices and arrays. det( ) ,rank( ) ,trace( ) ,inv( ) , x=A\b ,poly( ) ,eig( ) , [v ,x]=eig(A) are the operations that are used on matrices. Matrix Generator:

1. zeros(p,q) Returns a matrix of all zeros of order pxq. 2. ones(p,q) Returns a matrix of all ones of order pxq. 3. eye(p,q) Returns a matrix with ones on the main diagonal and zeros elsewhere of order pxq. 4. rand(n) ,rand(m, n) (chooses random entries from interval 0-1), rands(n), rands(m, n) (chooses random entries from interval (-1,+1)), diag(v). Arithmetic operations can carried out on matrices provided that the operands are compatible with the operations.

Working of Commands:

Linspace:

linspace(x1, x2) generates a row vector of 100 linearly equally spaced points between x1 and x2. linspace(x1, x2, n) generates n points between x1 and x2. For n < 2, linspace returns x2.

Example: x=linspace(0 , 10 , 3) 3

x= 0 5 10

Colon operator:

X= x1: increment :x2 generates a row vector between x1 and x2 with increment. Example: x= 9: -2 : 1 x= 9 7 5 3 1

polynomial:

Polyder: Gives the derivative of polynomial polyder(p). Polyint: Gives the integral of the polynomial polyint(p). Polyval: Evaluates the value of polynomial at any specific value of x Roots: find the roots of the polynomial

Polyval(p , x). f= [ 1 2 3 4] >>f = 1 2 3 >> polyder(f) ans = 3 4 3 >> polyint(f) ans =

1.5000

4.0000

Fprintf:

avg = 8 >> fprintf ('the average is %f/n', avg) the average is 8.000000/n>>

sprintf( 'my name is %s \n' , s1) ans = my name is javaria

Strcmp: compares two strings and returns 1 or 0 . Strmatch: matches two strings returns 1 or []. Findstr : finds one string in other and returns 1 or 0.

s2 = 'javaria roll# 116' s2 = javaria roll# 116 >> s1 = 'javaria' s1 =javaria >> strmatch (s1 , s2) ans = 1 >> findstr( s1 , s2) ans = 1 >> strcmp ( s1 , s2) ans = 0

Disp: simple commend used to display something. Plot: To create two-dimensional line plots, use the plot function. For example, plot

the value of the sine function from 0 to 2: x = 0:pi/100:2*pi; y = sin(x); plot(x,y) xlabel('x') ylabel('sin(x)') title('Plot of the Sine Function')

Subplot: we can display multiple plots in different sub regions of the same window

using the subplot function. Example:

Plots the following functions in interval 0x2 using 100 points .use the subplot command to display these functions on four windows on same graph Sin(x) Cos(x) Sin(x)*cos(x) Sin(x)/cos(x)

x= linspace ( 0 , 2*pi , 100); y=sin (x); subplot (2, 2, 1) plot ( x , y) z= cos (x); subplot ( 2, 2 , 2) plot ( x , z) w = sin (x).* cos(x); subplot ( 2 , 2 , 3) plot ( x , w) v = sin (x)./ cos(x); subplot ( 2, 2, 4) plot (x , v)

block of code to execute. The simplest conditional statement is an if statement.

Example:

Program which inputs marks and tells what grade is yours x=input('Enter the marks') if (x>=90) disp (' your grade is A') else if (x>90) disp ('your grade is B') else if (x>80) disp('your grade is C') else if (x>70) disp ('your grade is D') else if (x>60) disp('your grade is F you are fail ') else disp ('') end end end end 7

end

ans:

Enter the marks77 x= 77 your grade is D

Switch:

Loop control:

For loop:

MATLAB functions that provide control over program loops. The for loop repeats a group of statements a fixed, predetermined number of times. A matching end delineates the statements. Example: Program which gives the average of numbers using for loop:

While loop:

The while loop repeats a group of statements an indefinite number of times under control of a logical condition. A matching end delineates the statements.

and loop starts from begining.

Break:

Dsolve:

We use dsolve to find solution of ordinary differential equations Its syntax is: r = dsolve('eq1,eq2,...', 'cond1,cond2,...', 'v')

Who: it lists all the current variables in use during a session. Whos: it also lists all current variables (long display) in use during a session

Example: We are going to compute the roots of the system of linear equations: X+2y+3z=1 4x+5y+6z=1 7x+8y=1 >> a=[ 1 2 3 ; 4 5 6 ; 7 8 0 ] a= 1 2 3 4 5 6 7 8 0 >> b= [1; 1 ; 1] b= 1 1 1 >> x=a\b x= -1.0000 1.0000 -0.0000 In this way backslash operator can be used.

Fzero: fzero can be used to solve a single variable nonlinear equation of the form f(x)

= 0. The equation must first be programmed as a function (either inline or m-file). Example: x = fzero(fun,x0) fun is the function whose zero is to be computed. >>x = fzero('sin',3) x= 3.1416

10

Realmax is largest positive floating-point number Realmin is smallest positive floating-point number >> realmax ans = 1.7977e+308 >> realmin ans = 2.2251e-308

Eps: eps is also known as Machine epsilon in MATLAB is the distance from 1 to the next

valid floating point number..This value is used in determining the numerical rank of the matrix and in determining the pseudo inverse of a matrix. On an intel based machine

Used to calculate time duration of the process. Place tic before the code and toc after the code

Interpolation:

For one dimensional interpolation interp1 commend is used there are basic five methods for linear interpolation. yi = interp1(x,Y,xi,method) is the basic syntax of the command 1. 'nearest'Nearest neighbor interpolation 2. 'linear'Linear interpolation (default) 3. Sunday, June 24, 2012'spline'Cubic spline interpolation 4. 'pchip'Piecewise cubic Hermite interpolation 5. 'cubic'(Same as 'pchip')'v5cubic'Cubic interpolation used in MATLAB 5 are the five methods used for linear interpolation.

11

12

Secent Method:

13

Bisection Method:

Vectorization:

Vectorization means converting for and while loops to equivalent vector or matrix operations

14

- HSC NUMERICAL METHOD MATHS II WITH SOLUTIONUploaded byAMIN BUHARI ABDUL KHADER
- Numerical Technique Lab ManualUploaded byGurumayum Tangkeshwari
- Numerical Methods in MatlabUploaded byPranav Barve
- An Introduction to Numerical Methods.a Matlab ApproachUploaded byIsmaila Ba
- Numerical methods for engineersUploaded byvignanaraj
- matlabUploaded byMahesh Makwana
- Numerical Methods using MATLABUploaded byPaul Dremyn
- Matlab Lab ManualUploaded byHazrat Hayat Khan
- Separation ProcessUploaded bySafyan Manzoor
- numerical methods-lab-manualUploaded byapi-315485367
- MATLAB Tutorial 5 - Numerical IntegrationUploaded byJayakumar Ramachandran
- Numerical Methods with MATLAB.pdfUploaded byISTIAN
- MatlabUploaded byaniezahid
- Res Sedimentation Handbook 1.04Uploaded byAkhil Sebastian
- Matlab Tutorial2Uploaded byAsterix
- Numerical Analysis MCQUploaded bymansoormani201
- Numerical Methods Using MATLAB 4ed Solution ManualUploaded bynoobispriest23
- Matlab TutorialUploaded bySaurabh Tiwari
- [Solution Manual] Numerical Methods by VedamurthyUploaded byakash kumar
- BaccaratUploaded byJoe Banda
- Chemical Process Control Education and PracticeUploaded byMarcelo Andrade Santiago
- Alkalinity and Acidity experimentUploaded bySaivenkateshBantupalli
- Writing SkillsUploaded byShazia
- BaccaratUploaded byAlbert Ibragimov
- PT3 Form 3Uploaded byHayden Eddy
- Writing SkillsWRITING SKILLSUploaded byWinnie Wen
- Separation Process 1Uploaded byhanisshi
- Analysis Spectra AbioFunctionalGrpsVollIRspectUploaded byKong Vari

- power electronics manualUploaded byJavaria Chiragh
- PIC based thermometerUploaded byJavaria Chiragh
- 3F3 2 Brief Review of Fourier AnalysisUploaded byJavaria Chiragh
- 3F3_2a_More_on_DFTUploaded byJavaria Chiragh
- Research ProposalUploaded byJavaria Chiragh
- Mechatronics 2010Uploaded byWaqar Ul Hassan
- Afifa CV.docxUploaded byJavaria Chiragh
- Shear Stresses & Bending Moment.pptxUploaded byJavaria Chiragh
- MemoUploaded byJavaria Chiragh
- Research Overview CoversheetUploaded byJavaria Chiragh
- AssignmentUploaded byJavaria Chiragh
- Physics PairingUploaded byJavaria Chiragh

- Chapter 11 II Graphs of Functions EnrichmentUploaded byksgan
- official_course_descriptionUploaded byapi-3716660
- Solution of Linear System Theory and Design 3ed for Chi-Tsong ChenUploaded byadambose1990
- General Math DLL for SHS - (More Dll at Depedtambayanph.blogspot.com) Q1, Week 01Uploaded byJester Guballa de Leon
- 1812.07599Uploaded byFarley Knight
- Simplifying Trig ExpressionsUploaded bynishagoyal
- College MathematicsUploaded bymark_59
- 8 Bar MechanismUploaded byorkunu
- Practice 2Uploaded bySenior Alonzo
- Geo Sem1 StudentVersionUploaded byratliffj
- List of Trigonometric Identities - Wikipedia, The Free Encyclopedia2Uploaded byKhelchand Naoria
- On Marginal Allocation KTHUploaded byJohnny Onthespot
- MSc in Mathematics (Budapest - Eotvos University)Uploaded byzhazzu
- solutions1.3Uploaded byPeter Armaos
- Mixing Linear Algebra With Calculus and Probability Theory HayashiUploaded bysilvio de paula
- Optimization Techniques Course Study Outline Tri-2 _2018-2019.pdfUploaded byvhin2218
- the American mathematicsUploaded bypiping1522
- Algebraic GroupsUploaded byHonghao Gao
- sumsetsR.pdfUploaded byTaha
- ALL BIMUploaded bydenkos19
- Credit Plus Calculus - Optimization 2019Uploaded bywelcometotheswamp
- PMAT315 W08 LEC1 Assignment 3 SolutionsUploaded byJeoff Libo-on
- LINEAR PROGRAMMING.pptxUploaded byKwin Hazel Satiada
- AI Lecture 5Uploaded byShahzad Malik
- microsoft word - unit 4 test docxUploaded byapi-376783060
- 5.3 the Optimal Power Flow ProblemUploaded byMohammedSaadaniHassani
- Mathematical Formulae Quick Reference SheetUploaded bymyas100
- 21_vgGray R. - Probability, Random Processes, And Ergodic PropertiesUploaded bydavid
- mathematical.pdfUploaded bymuzaffer_91
- Q1 SolutionUploaded byCan Çamlık