Professional Documents
Culture Documents
Length = 10 cm
Width = 10 cm
73
Practice 02
Simulate the matrix data
of the angle of inclination
as informed bellow:
X = [0:10:180]
Problem:
1. Calculate the sine
date of Y1 = sin
��.π
180
2. Analyses the sine of
theta Y1 = cos��.π
180
74
Practice 03
Concerned to previous practice 01.
75
Practice 04
Looping data analysis:
Z = ��2 + (5 × ��)
76
Practice 05
Calculate the a volume of pool and
compare to the volume of bucket. In
fact, it is needed to be known how
many buckets requires to fill the
whole pool if there is still a water
inside.
77
Practice 06
Evaluate the grade of each student
by the classification of point as
illustrated bellows
UTS 1 = 20%
UTS 2 = 30%
UAS = 50%
78
Quiz 1
Evaluate the given matrix A = 1 5 3 which times with
sin(0), -cos(150) and log(2000) × 100, respectively.
79
Practice 07
Evaluate several
simple calculation
as follows:
1. Square area
2. Square volume
3. Cylinder area
4. Cylinder volume
80
Practice 08
Analysis of the conventional iteration
and matrix manipulation.
i = 1 : 100000
a=a+1
x (i) = a
81
Practice 09
- First data 0
- Step data 5
- End data 180
82
Practice 10
Recall data from practice 09. Illustrate
the sin and cos data due to time
consideration.
83
Practice 11
- First data 0
- Step data 2
- End data 90
Y1 = ��2 × sin ��
Y2 = ��2 × sin ��2 × cos ��
EVALUATION
First, the output data should be saved and loaded for the next step.
Further, Plot the problem above and illustrate into the graph. As the information, the
graph should be drawn in one figure with several information of X.
85
Practice 12
Practice 13
3. nama_file_baca='C:\Users\indra\On
eDrive\Documents\MATLAB\dataku
1.txt
88
Practice 14
89
Practice 14
90
Practice 15
Write the content of format file with the
fprintf(foutput,'%30s %8.2f\n','Total Volume
function of fprint, here the syntax command : Kolam = ',vkolam);
fprintf(foutput,'%30s %8.2f\n','Volume Ember
Yang digunakan = ',vember);
fprint (fid, format, var) ; fprintf(foutput,'------------------------\n’);
fname1=input('Nama File Output = ');
foutput=fopen(fname1,'w');
% ------------------------- nember=0; % Practice program
15
% Matlab Programming while vkolam > 0
% By: Indra Komara ST, MT nember=nember+1;
% ------------------------- fprintf(foutput,'%6.0f %8.2f
%8.2f\n',nember,vkolam,vkolam-vember);
clear all; vkolam=vkolam-vember;
clc; end;
disp('--------------------------'); disp('Practice fprintf(foutput,'-----------------------\n');
Program 15'); fprintf(foutput,'%30s %8.2f\n','Jumlah Ember Yang
disp('--------------------------'); disp('Menghitung digunakan =',nember);
kebutuhan ember'); fclose(foutput);
vkolam=input(' Volume kolam (ltr) = '); vember=input(' disp(['Data Output disimpan dalam file -->' fname1]);
Volume ember (ltr) = ');
91
92
Practice 17beam
This practice is made to support the Practice 18. Several m files are used to
make the collaboration. First Practice17beam.m
93
Practice 17cylinder
Second Practice17cylinder.m
function [area, content]=cylinder(radius,height)
% --------------------------------------------
% Practice program 17
% Matlab Programming
% By: Indra Komara ST, MT
% --------------------------------------------
%
% Calculate the area and the content of cylinder
% area = (2(pi))x r x t) + 2(pi x r^2)
% content = pi x r^2 x t;
%
% How to use :
% [area, content]=cylinder(radius,height)
% --------------------------------------------
area=(2*pi*radius*height)+2*(pi*radius^2);
content=pi*radius^2*height;
94
Practice 18
Second Practice17cylinder.m
% --------------------------------- % Practice clear all;
program 18 clc;
% Matlab Programming
% By: Indra Komara ST, MT disp('--------------------------'); disp('Practice
% --------------------------------- Program 18');
disp('--------------------------'); disp('Choice of
calculation formula'); disp('1.Square'); disp(['square area=' num2str(area)]);
disp('2.Cylinder'); disp(['square volume=' num2str(content)]);
disp(' '); case 2
disp('Calculate of area and content of cylinder');
pilih=input('pilihan anda (1-2) ->'); switch pilih disp('-----------------------------------------');
r=input('radius of cylinder=');
case 1 tg=input('height of cylinder=');
[area,content]=Practice17cylinder(r,tg);
disp('Calculate the area and content of square'); disp(['area of cylinder=' num2str(area)]);
disp('----------------------------------------'); disp(['volume of cylinder=' num2str(content)]);
pjg=input('square length='); otherwise
lbr=input('square width='); disp('cinta anda ditolak!!!')
tg=input('square height='); end;
[area,content]=Practice17beam(pjg,lbr,tg);
95
Practice 19
clear all;
clc;
disp('--------------------------');
disp('Practice Program 19');
disp('--------------------------');
sdt=[0:10:180];
y=sin(sdt*pi/180);
plot(sdt,y,'*r');
title('Grafik Sinus');
xlabel('Sudut dalam derajat');
ylabel('Nilai sinus');
96
Practice 19a
% ---------------------------------
% Practice program 19a
% Matlab Programming
% By: Indra Komara ST, MT
% ---------------------------------
clear all;
clc;
disp('--------------------------');
disp('Practice Program 19a');
disp('--------------------------');
sdt=[0:10:180];
y=sin(sdt*pi/180);
plot(sdt,y,'oy');
hold on;
plot(sdt,y,'-w');
grid on;
97
Practice 19b
% --------------------------------
-
% Practice program 19b
% Matlab Programming
% By: Indra Komara ST, MT
% --------------------------------
-
clear all;
clc;
disp('--------------------------
');
disp('Practice Program 19b');
disp('--------------------------
');
sdt=[0:10:180];
y1=sin(sdt*pi/180);
y2=sin(sdt*pi/180);
plot(sdt,y1,'*r',sdt,y2,'+b')
title('Grafic sinus & cosinus')
xlabel('sudut dalam derajat');
ylabel('Nilai Y');
98
Practice 19c
% -------------------------------
--
% Practice program 19c
% Matlab Programming
% By: Indra Komara ST, MT
% -------------------------------
--
clear all;
clc;
disp('--------------------------
');
disp('Practice Program 19c');
disp('--------------------------
');
sdt=[0:10:180];
y1=sin(sdt*pi/180);
y2=cos(sdt*pi/180);
plot(sdt,y1,'*r');
hold on;
plot(sdt,y2,'+b');
title('Grafic sinus & cosinus')
xlabel('sudut dalam derajat');
ylabel('Nilai Y');
99
Practice 20
% ---------------------------------
% Practice program 20
% Matlab Programming plot(sdt,y3,'ok');
% By: Indra Komara ST, MT title('Grafic Y3')
% --------------------------------- ylabel('Nilai Y1');
xlabel('sudut dalam
clear all; derajat'); ylabel('Nilai
clc; Y1+Y2');
disp('--------------------------
'); disp('Practice Program 20');
disp('--------------------------
');
sdt=[0:10:180];
y1=sin(sdt*pi/180);
y2=cos(sdt*pi/180);
y3=y1+y2;
subplot(3,1,1);
plot(sdt,y1,'*b');
title('Grafic sinus')
ylabel('Nilai Y1');
subplot(3,1,2);
plot(sdt,y2,'+r');
title('Grafic cosinus')
ylabel('Nilai Y2');
subplot(3,1,3);
100
Visualization of 2D data
Visualisasi 2D (2 dimensi) artinya adalah menempatkan satu atau lebih titik data
pada media bidang kartesian maupun polar. Memvisualisasikan data pada bidang
pemodelan numerik, terkadang tidak cukup hanya dengan plotting garis atau titik
saja. Dalam banyak kesempatan, misalnya presentasi ilmiah, penelitian dan
sebagainya, plot garis atau titik dirasakan kurang memadai.
Sampai saat practice sebelumnya kita sudah terbiasa dengan penggunaan fungsi
plot. Tapi sebenernya MATLAB menyediakan beberapa fungsi visualisasi yang umum
digunakan, yaitu:
Practice 20a
Bar Function
% ---------------------------------
% Practice program 20a
% Matlab Programming
% By: Indra Komara ST, MT
% ---------------------------------
clear all;
clc;
disp('--------------------------');
disp('Practice Program 20a');
disp('--------------------------');
sdt=[0:5:160];
y=sin(sdt*pi/180);
bar(sdt,y)
title('grafik Sinus');
xlabel('Sudut dalam derajat');
ylabel('Nilai sudut');
102
Practice 20b
Stem Function
% --------------------------------
-
% Practice program 20b
% Matlab Programming
% By: Indra Komara ST, MT
% --------------------------------
-
clear all;
clc;
disp('--------------------------
');
disp('Practice Program 20b');
disp('--------------------------');
x=[-50:2.5:50];
y1=(x.^2).*sin(x);
stem(x,y1);
103
Practice 20c
Stairs Function
% ---------------------------------
% Practice program 20c
% Matlab Programming
% By: Indra Komara ST, MT
% ---------------------------------
clear all;
clc;
disp('--------------------------');
disp('Practice Program 20c');
disp('--------------------------');
x=[-50:5:150];
y1=(x.^2).*cos(x);
stairs(x,y1);
Illustrate another plot by using >> demo
104
Visualization of 3D data
Visualisasi 3D (3 dimensi) artinya adalah menempatkan satu atau lebih titik data
pada media ruang. Teknik visualisasi 3D ini sama berguna dalam bidang permodelan
yang berhubungan dengan ruang (x, y, z), dimana z berarti nilai bobot pada titik (x,y)
yang berupa data ketinggian, temperature, kecepatan dan lain-lain. Beberapa fungsi
yang umum digunakan untuk visualisasi data 3D adalah:
Fungsi plot3
Fungsi mesh
Fungsi Surfl
Fungsi pcolor
Fungsi imagesc
Fungsi contour
Fungsi contour
105
Practice 21
Plot3 Function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
plot3(t(:,1),t(:,2),t(:,3),'ob');
hold on;
plot3(t(:,1),t(:,2),t(:,3),'-r');
grid on;
set (gca,'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
106
Practice 21a
Mesh function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
mesh(t);
hold on;
mesh(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
107
Practice 21a
Mesh function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
mesh(t);
hold on;
mesh(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
108
Practice 21b
Surf function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
surf(t);
hold on;
surf(t);
grid on;
Practice 21c
Surfl function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
surfl(t);
hold on;
surfl(t);
grid on;
Practice 21d
Pcolor function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
pcolor(t);
hold on;
pcolor(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
111
Practice 21e
Imagesc function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
imagesc(t);
hold on;
imagesc(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
112
Practice 21f
Contourf function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
contourf(t);
hold on;
contourf(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
113
Practice 21g
Contour function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
contour(t);
hold on;
contour(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
114
Practice 22
Contour function
% making data of x y and z
% x y z
t = [5 6 12;
2 3 4;
4 2 9;
4 7 9;
11 10 20;
9 7 7;
5 6 12];
contour(t);
hold on;
contour(t);
grid on;
set (gca,'color',[.7 1
0.4],'fontsize',8);
title('Grafik 3D
plot3','fontweight','bold','fontsize',12);
xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
115
Practice 22
% ---------------------------------
% Practice program 22
% Matlab Programming
[XI,YI]=meshgrid(linspace(xmin,xmax,50),linspace(ym
% By: Indra Komara ST, MT
in,y max,50));
% ---------------------------------
X=data(:,1);
clear all;
Y=data(:,2);
clc;
Z=data(:,3);
ZI=griddata(X,Y,Z,XI,YI,'cubic');
disp('--------------------------'); disp('Practice
Program 22'); disp('--------------------------');
disp('Pilihan Visualisasi 3D');
disp('------------------------------');
% X Y Z
disp('1. mesh');
data= [ 1.0000 1.0000 10; 50.0000 50.0000 -15;
disp('2. surf');
30.0000 25.0000 30;
disp('3. surfl');
40.0000 10.0000 -20;
disp('4. pcolor');
1.0000 50.0000 -4;
disp('5. imagesc');
50.0000 1.0000 5];
disp('6. contour');
disp('7. contourf');
xmin=min(data(:,1));
disp(' ')
xmax=min(data(:,1));
pilih=input('pilihan anda (1-7) -> ');
ymin=min(data(:,2));
ymax=min(data(:,2));
116
Practice 22 - Continued
switch pilih
case 1 case 3
mesh(ZI); surfl(ZI);
set(gca,'color',[.7 1 set(gca,'color',[.7 1
0.4],'fontsize',8); title('Grafik 3D 0.4],'fontsize',8); title('Grafik 3D
menggunakan menggunakan
MESH','fontweight','bold','fontsize',12) SURFL','fontweight','bold','fontsize',12)
xlabel('Sumbu-x','fontweight','bold'); xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold'); ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold'); zlabel('Sumbu-z','fontweight','bold');
case 2 case 4
surf(ZI); pcolor(ZI);
set(gca,'color',[.7 1 set(gca,'color',[.7 1
0.4],'fontsize',8); title('Grafik 3D 0.4],'fontsize',8); title('Grafik 3D
menggunakan menggunakan
SURF','fontweight','bold','fontsize',12) PCOLOR','fontweight','bold','fontsize',12)
xlabel('Sumbu-x','fontweight','bold'); xlabel('Sumbu-x','fontweight','bold');
ylabel('Sumbu-y','fontweight','bold'); ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold'); zlabel('Sumbu-z','fontweight','bold');
117
clabel(cc,'fontsize',10,'color','white');
Practice 22 - Continued set(gca,'color',[0 0 0],'fontsize',8);
title('Grafik 3D menggunakan
CONTOUR','fontweight','bold','fontsize',12)
xlabel('Sumbu-x','fontweight','bold');
case 5
ylabel('Sumbu-y','fontweight','bold');
zlabel('Sumbu-z','fontweight','bold');
cc=contourf(ZI);
clabel(cc,'fontsize',10,'color','white');
set(gca,'color',[0 0 0],'fontsize',8);
case 7 title('Grafik 3D menggunakan
imagesc(ZI); CONTOURF','fontweight','bold','fontsize',12)
set(gca,'color',[.7 1 0.4],'fontsize',8); xlabel('Sumbu-x','fontweight','bold');
title('Grafik 3D menggunakan ylabel('Sumbu-y','fontweight','bold');
IMAGESC','fontweight','bold','fontsize',12) zlabel('Sumbu-z','fontweight','bold');
xlabel('Sumbu-x','fontweight','bold'); otherwise
ylabel('Sumbu-y','fontweight','bold'); disp ('pilihan anda ngawuur!!!')
zlabel('Sumbu-z','fontweight','bold'); case 6 end;
cc=contour(ZI);
118
WINDOW PROGRAM
PART 1 (GUI)
By : INDRA KOMARA ST., MT
Civil Engineering Department - ITATS
119