0% found this document useful (0 votes)
594 views4 pages

Matlab For Civil Engineer

This document provides an introduction to Matlab for civil engineers. It outlines many basic Matlab commands for defining matrices, performing matrix operations like multiplication and inverse, plotting data, and writing M-files. Functions covered include commands to assign values, define matrices, find transpose/determinant/inverse of matrices, perform element-wise operations, save and load variables, and solve equations. Examples are given for common civil engineering tasks like the Crammer's rule and quadratic formula solutions.

Uploaded by

Yusuf Trunkwala
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
594 views4 pages

Matlab For Civil Engineer

This document provides an introduction to Matlab for civil engineers. It outlines many basic Matlab commands for defining matrices, performing matrix operations like multiplication and inverse, plotting data, and writing M-files. Functions covered include commands to assign values, define matrices, find transpose/determinant/inverse of matrices, perform element-wise operations, save and load variables, and solve equations. Examples are given for common civil engineering tasks like the Crammer's rule and quadratic formula solutions.

Uploaded by

Yusuf Trunkwala
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Matlab for Civil Engineers

Engr. Faisal ur Rehman

Matlab Tutorial Engr. Faisal ur Rehman http://enggprog.com (Engineering Programs)


Introduction Matlab Basic Commands
Matlab is software for Engineeirng Calculation. The main window is command window with command prompt '>>' The basic and important Matlab command is listed below: Assigning value to a Variable: >>x=5 >>y = x+4 To Define a Row Matrix of size 1x6: >>A = [1 2 3 4 5 6] Defining a Row Matrix without display of answer variable ( use semicolon at the end of command): >>B = [1 3 3 7 5 6]; To Define a Column Matrix of size 6x1: >>C = [1;2;3;4;5;6] To Define a Square Matrix of size 6x6: >>D = [1 2 3 2 7 3;2 8 7 4 3 4;0 1 9 8 6 4;9 6 5 4 3 3;3 4 5 1 2 7;9 8 7 0 5 1] Finding Transpose of Matrix: >>D' Finding the Determinant of Matrix: >>det(D)

enggprog.com (Engineering Programs)

Matlab for Civil Engineers Finding Inverse of Matrix: >>inv(D) Another command of Matrix Inverse is: >>D^-1 Note: Caret (^) symbol is used for taking power. To find the Matrix Multiplication and store result in Matrix E (6x1): >>E=D*C To find the inverse of square matrix D and multiply with Matrix C: >>F=D^-1*C Another way of above calculation is: >>G=inv(D)*C Third method of above calculation is: >>H=D\C To define a Null Matrix 5x4 size: >>I = zeros(5,4) To define a Square Null Matrix of 6x6 size: >>J=zeros(6) To define the Identity Matrix of size 6x6: >>K=eye(6) To define a Row Martrix with elements from 1 to 10 with step size of 0.05: >>L = [1:0.05:10] To clear the display of command window: >>clc To save only variable C,F and G to Workspace file named myvar1.mat: >> save('myvar1.mat','C','F','G') To save all variables to workspace named myvar2.mat: >>save myvar2.mat To remove variable A, B, and D from Workspace: >>clear('A', 'B','D')

Engr. Faisal ur Rehman

enggprog.com (Engineering Programs)

Matlab for Civil Engineers To clear all variables from Matlab Workspace: >>clear all To load only variable H and I from myvar2.mat file: >>load('myvar2.mat','H','I') To load all variable from myvar2.mat file: >>load myvar2.mat To find the sine of given matrix: >>M = 2*sin(L); Note: Angle Input is taken as radian. To perform scalar multiplication of matrix A and B: >>N = A.*B Note: dot (.) symbol is used for element wize operation. To plot to arrays: >>plot(L,M) To plot with dot marker: >>plot(L,M,'.') To plot with asterisk (*) marker and line of red color: >>plot(L,M,'*-r') To perform complex number calculation on a and b: >> a = 2 +5i; >>b = 9 + 6j; >>a+b >>a-b >>a*b >>a/b To open M file Editor: Desktop>Editor Save a new file by the name cmr.m and write the following: % Crammer Rule Calc A=input('Enter a Square Matrix of Size mxm'); B=input('Enter a Column Matrix of Size mx1'); X=A\B; disp('X (mx1) is :') disp(X) To execute above m file, write: cmr in command window. enggprog.com (Engineering Programs)

Engr. Faisal ur Rehman

Matlab for Civil Engineers Following is the code of qdr.m file for Quadratic Equation: %quadratic root calc using quadratic formula: a=input('Enter the coefficient of quadratic equation - a = '); b=input('Enter the coefficient of quadratic equation - b = '); c=input('Enter the coefficient of quadratic equation - c = '); x1=(-b+sqrt(b^2-4*a*c))/(2*a) x2=(-b-sqrt(b^2-4*a*c))/(2*a) To find help of given command: >>help det

Engr. Faisal ur Rehman

enggprog.com (Engineering Programs)

You might also like