Graphics
data = xlsread('water.xlsx','Sheet1','A2:E18'); % Allocate imported array to column variable names Temperature = data(:,1); Production = data(:,2); Days = data(:,3); Persons = data(:,4); Water = data(:,5); % Clear temporary variables clearvars data;
% Simple: Plot Water (y) against Production (x) using function |scatter(x, y)| scatter(Production, Water) % Scatter plot with title, x-y-labels and different markers figure; scatter(Production, Water, 25, 'rs', 'filled') grid on xlabel('Production (M pounds)') ylabel('Water (gallons)') title('Water Usage of Production Plant')
Plot each month's (x) Days(Y1) Temperature(Y2)
month = 1:length(Days); figure; plot(month, Days, 'k-', month, Temperature, 'r:o') xlabel('Month') legend('Days', 'Temperature (F)', 'Location', 'northeastoutside') title('Days and Temperature of each Month')
Create a histogram for 10000 normally distributed random number
x = randn(10000,1); figure; h = histogram(x, 'Normalization', 'count')
h = Histogram with properties: Data: [10000x1 double] Values: [1x38 double] NumBins: 38 BinEdges: [1x39 double] BinWidth: 0.2000 BinLimits: [-4 3.6000] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0] Use GET to show all properties
Overlap underlying probability distirbution
% Generate 5000 normally distributed random numbers with mean of 5 and a% standard deviation of 2 x = 2*randn(5000,1) + 5; figure; histogram(x,'Normalization','pdf') % Underlying normal distribution hold on y = -5:0.1:15; mu = 5; sigma = 2; f = exp(-(y-mu).^2./(2*sigma^2))./(sigma*sqrt(2*pi)); plot(y, f, 'LineWidth', 1.5) hold off
3-D Scatter plot: x=Production, y=Persons, z=Water
figure; scatter3(Production, Persons, Water, 'filled') xlabel('Productin') ylabel('Persons') zlabel('Water')
t = 0:pi/50:10*pi; st = sin(t); ct = cos(t); figure; plot3(st,ct,t)
Cobb-Douglas Production Function
ll=0:0.02:1; kk=ll; [L,K]=meshgrid(ll,kk); Y = 2*L.^0.4 .* K.^0.6; figure; mesh(L,K,Y) xlabel('L') ylabel('K') zlabel('Y')
figure; [X,Y,Z] = peaks(25); surf(X,Y,Z);
x = linspace(-2, 0 ,40); y = linspace(0, 3, 40); [X, Y] = meshgrid(x,y); Z = 2 + X - Y + 2*X.^2 + 2.*X.*Y + Y.^2; figure; contour(X, Y, Z); xlabel('X'); ylabel('Y'); grid; figure; surfc(X,Y,Z); xlabel('X') ylabel('Y') zlabel('Z')
x = 0:0.1:10; y1 = sin(2*x); y2 = cos(2*x); figure subplot(2,1,1) % add first plot in 2 x 1 grid plot(x,y1) title('Subplot 1') subplot(2,1,2) % add second plot in 2 x 1 grid plot(x,y2,'+') % plot using + markers title('Subplot 2')
clc;
a = 1.03; fprintf('%5.2f can be round to the integer %d \n',a, round(a));
1.03 can be round to the integer 1
x = 0:0.2:1; exp_x = exp(x); fprintf('%-6s %-12s \n', 'x', 'exp(x)'); fprintf('%-6.2f %-10.5f \n', [x; exp_x]);
x exp(x) 0.00 1.00000 0.20 1.22140 0.40 1.49182 0.60 1.82212 0.80 2.22554 1.00 2.71828