Presentation is loading. Please wait.

Presentation is loading. Please wait.

Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.

Similar presentations


Presentation on theme: "Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne."— Presentation transcript:

1 Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne

2 206_M32 Elementary Math Functions abs(x) sqrt(x) sign(x) round(x), fix(x) ceil(x), floor(x) rem(x,y) exp(x) log(x), log2(x), log10(x)

3 206_M33 Trigonometric Functions  Angle in radians(180 degrees = pi radians) sin(x), cos(x), tan(x) asin(x), acos(x), atan(x)  Angle in degrees sind(x), cosd(x), tand(x) asind(x), acosd(x), atand(x) angle_deg = angle_rad*(180/pi); angle_rad = angle_deg*(pi/180);

4 206_M34 Data Analysis Functions  Minimum and Maximum max(x), [a,b]=max(x), max(x,y) min(x), [a,b]=min(x), min(x,y)  Averages median(x), mean(x), std(x)  Sums and Products sum(x), prod(x) cumsum(x), cumprod(x)

5 206_M35 Data Analysis Functions  Sorting sort(x)  Size size(x), [a,b]=size(x) length(x)

6 206_M36 Random Numbers  Uniform Random Numbers rand('seed',n), rand(n), rand(m,n) Interval 0 to 1 Interval a to b x = (b - a)*r + a;  Gaussian Random numbers randn('seed',n), randn(n), randn(m,n) Normal Distribution Mean = 0, Standard Deviation = 1.0 Modified Distribution Mean = b, Standard Deviation = a x = a*r + b;

7 206_M37 Problem Solving Applied  Weather Data Problem Statement Using the data in the file Weather_Data.xls, find the total monthly precipitation, the total precipitation for the year, and the day on which it rained the most. Input/Output Description Total Monthly Precipitation Total Precipitation Weather_Data.xls Day of Most Rain

8 206_M38 Problem Solving Applied Hand Example 12x31 Matrix  Rows = Months  Columns = Days  Hundreths of inches  Invalid = -99999 tot_jan = 2.72 in tot_feb = 1.66 in tot_jan+feb = 4.38 in max = Jan 3 002720 6110302 201727 260100 47000 003042 0000 04500 0000 00014 116350 0000

9 206_M39 Problem Solving Applied Algorithm Development Import spreadsheet into matrix Change -99999 values to 0 Interchange rows and columns Monthly Totals (inches) = sum columns/100 Yearly Total = sum Monthly Totals Find max and location

10 206_M310 MATLAB Solution

11 206_M311 MATLAB Solution clc % Example 3.3 - Weather Data % Find the total precipitation for each month, and % for the entire year, using a data file % wd=Weather_Data; wd(2,29)=0; % Change -99999 values to 0 wd(2,30)=0; wd(2,31)=0; wd(4,31)=0; wd(6,31)=0; wd(9,31)=0; wd(11,31)=0;

12 206_M312 MATLAB Solution % Use transpose operator to change rows to columns wd = wd'; % Sum of each column is sum for each month monthly_total = sum(wd)/100 % Find the annual total yearly_total = sum(monthly_total) % Find the annual maximum, and month [maximum_precip,month] = max(max(wd)); % Find the annual maximum, and day [maximum_precip,day] = max(max(wd')); % Print max data maximum_precip = maximim_precip/100 month day

13

14 206_M314 Manipulating Matrices  Defining Matrices A = [1 2 3; 4 5 6]; (2x3) A = [1 2 3; 4 5 6]; B = [1 2 3] (1x3) B = [1 2... 3]; C = [A; B] = [1 2 3; 4 5 6; 1 2 3]; (3x3)

15 206_M315 Manipulating Matrices  Changing Matrices D = [3 4 5]; D(2) = 8; D = 3 8 5 D(5) = 7; D = 3 8 5 0 7

16 206_M316 Manipulating Matrices  Defining Matrices with the Colon Operator E = 1:4 E = 1 2 3 4 F = 0.0:0.5:2.0 F = 0.0 0.5 1.0 1.5 2.0

17 206_M317 Manipulating Matrices  Extracting Data with the Colon Operator G = [1 2 3; 2 3 4; 3 4 5; 4 5 6]; x = G(3, :) x = 3 4 5 y = G(:, 2:3) y = 2 3 3 4 4 5 5 6

18 206_M318 Manipulating Matrices  Extracting Data with the Colon Operator G = [1 2 3; 2 3 4; 3 4 5; 4 5 6]; G(3,2) ans = 4 G(7) ans = 4 G(:) ans = 1 2 3 4 2 3 4 5 3...

19 206_M319 Computational Limitations  Double Range 10 -308 to 10 +308  Exponent Overflow y = 2e200; y^2 ans = Inf  Exponent Underflow x = 2e-200 x/y ans = 0  Double Precision eps ans = 2.2204e-016  Divide by Zero y/0 ans = Inf 0/0 ans = NaN

20 206_M320 Special Values and Functions  Special Values pi i j Inf NaN  Special Functions clock Year Month Day Hour Minute Seconds date dd-Mth-yyyy

21 206_M321 Summary  MATLAB Functions Math, Trig, Data Analysis, Random Numbers  Problem Solving Applied  Manipulating Matrices  Special Values and Functions  End of Chapter Summary MATLAB Summary Characters, Commands and Functions Key Terms


Download ppt "Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne."

Similar presentations


Ads by Google