0% found this document useful (0 votes)
525 views

Contoh Program Matlab

This document provides examples of basic MATLAB implementations and functions, including: 1. Creating simple graphs of varying data points. 2. Modeling the output voltage of a three-phase induction motor. 3. Graphing three-phase waveforms with varying phase shifts to illustrate differences in phase. It also includes examples of using MATLAB to solve equations, perform calculations related to electrical circuits and power systems, and provide visualizations using functions like subplot.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
525 views

Contoh Program Matlab

This document provides examples of basic MATLAB implementations and functions, including: 1. Creating simple graphs of varying data points. 2. Modeling the output voltage of a three-phase induction motor. 3. Graphing three-phase waveforms with varying phase shifts to illustrate differences in phase. It also includes examples of using MATLAB to solve equations, perform calculations related to electrical circuits and power systems, and provide visualizations using functions like subplot.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Contoh-Contoh Dasar dan Implementasi

Penggunaan Program MatLab


% 1. Latihan membuat grafik
clear all;
format short;
x=[0 1 2 3 4 5];
y=[0 20 60 68 77 110];
plot(x,y,'b');
title('Latihan Membuat Grafik');
xlabel('bilangan cacah');
ylabel('bilangan puluhan');
grid;

% 2. Program grafik putaran motor induksi


format short;
clear all;
x=[0, 5, 10, 15, 20, 25, 30, 35, 40,...
45, 50, 55, 60];
y=[0, 0.46, 0.91, 1.39, 1.88, 2.36, 2.89, 3.38,...
3.87, 4.36, 4.86, 5.35,5.86];
axis([0,60,0,6]);
plot(x,y,'r-');
title('Grafik Frekuensi vs Tegangan tacho');
xlabel('Frekuensi (Hz)');
ylabel('Tegangan tacho (volt)');
x:frekuensi
y:tegangan
grid;

% 3. Gelombang beda fasa


format short;
clear all;
wt=0:0.05:3*pi;
v1=10*sin(wt);
v2=10*sin(wt-120);
v3=10*sin(wt+240);
plot(wt,v1,'r',wt,v2,'y',wt,v3,'b');
title('Grafik Beda Fasa');
xlabel('Sudut (derajat)');
ylabel('Tegangan (volt)');
grid;

% 4. Grafik gelombang tiga fasa


format short;
clear all;
wt=(0:0.05:3*pi);
v1=10*sin(wt);
v2=10*sin(wt-180);
v3=10*sin(wt-90);
plot(wt,v1,'r',wt,v2,'g',wt,v3,'b');
title('Grafik Output Gelombang Tiga Fasa');
xlabel('wt (drajat)');
ylabel('Tegangan (volt)');
text(1.2,8.5,'V1');
text(6.4,8.5,'V2');
text(4.3,8.5,'V3');
grid;

1
% 5. Gelombang Sistem Tiga Fasa
format short;
clear all;
V=12;
Vmag=abs(V);
theta=linspace(0,6*pi);
Va=12*sin(theta+120);
Vb=12*sin(theta+240);
Vc=12*sin(theta+0);
% Buat grafik gelombang
sdt=theta*180/pi;
plot(sdt,Va,'r',sdt,Vb,'g',sdt,Vc,'b');
title('Tegangan Line');
xlabel('Sudut (derajat)');
ylabel('Tegangan (kV)');
text(30,12.5,'Va');
text(395,12.5,'Vb');
text(810,12.5,'Vc');
grid;

% 6. Grafik gelombang beda fasa


format short;
clear all;
wt=(0:0.05:2*pi);
v1=1*sin(wt);
v2=1*-cos(wt);
plot(wt,v1,'r',wt,v2,'b');
title('Grafik penggeser fasa');
xlabel('wt (radian)');
ylabel('Tegangan (volt)');
grid;

% 7. matriks e dan y
clear all;
format short;
A=[8 10.3426 27.5197
10.3426 27.5197 96.1149
27.5197 96.1149140 375.5433];
b=[9.4; 12.4276; 31.2741];
x=inv(A)*b

% 8. Latihan Membuat Program Bilangan Kompleks


format short;
clear all;

% 9. Dari Polar ke Rectagular


z=5*(cos(53.13*pi/180)+sin(53.13*pi/180*j))

% 10. Cara Pembagian Bilangan Kompleks


i=(1+0j)/(0.5j+0.2j)

% 11. Dari Rectagular ke Polar


zmag=abs(3+4j),angle(3+4j)*180/pi

% 12. Perkalian Bilangan Polar


z1=abs(5);
z2=abs(2);
z=z1*z2
z=z1*z2,(angle(4+3j)*180/pi+angle(8+6j)*180/pi)

2
% 13. Latihan membuat grafik
clear all;
format short;
x=[0 1 2 3 4 5];
y=[0 20 60 68 77 110];
plot(x,y,'b');
title('Latihan Membuat Grafik');
xlabel('bilangan cacah');
ylabel('bilangan puluhan');
grid;

% 14. Pengisian Kapasitor


format short;
clear all;
disp(' ')
disp('_____________________________________________')
disp(' ')
disp(' MENGHITUNG ARUS PERALIHAN ')
disp(' DENGAN CARA PENYELESAIAN ')
disp(' DARI PERSAMAAN DIFFERENSIAL ')
disp(' ORDE PERTAMA ')
disp('_____________________________________________')
disp(' ')
epsilon=0.0001;
x=1;
i=input ('Arus awal = ');
t=input ('Waktu mulai = ');
h=input('Harga h = ');
disp('_____________________________________________')
disp(' ')
disp(['Iter t i abs(i1 -i) '])
disp('_____________________________________________')
disp(' ')
format short g
iter=0;
while x >= epsilon
iter=iter + 1;
i1=2*(1-exp(-5*t));
x=abs(i1-i);
i=i1;
t=t+h;
fprintf('%i',iter),disp([t, i, x])
end
disp('_____________________________________________')

3
% 15. Perbandingan
format short
clear all
num=[4.5];
den1=[0.35 1];
t=0:0.05:2.5;
%y1=Respon plant;y2=Respon Model
[yp,x1,t]=step(num,den1,t);
den2=[0.1 1];
[ym,x2,t]=step(num,den2,t);
n=50;
ys=4.5;
e(1)=ys;de(1)=0;u(1)=1;
for i=2:51
e(i)=ys-ym(i); %ym atau yp
de(i)=e(i)-e(i-1);
u(i)=ym(i)/yp(i)*4.5;
end;
[(1:51)' t' e' de' u']
plot(t,yp,'r.-',t,yp,'b-',t,ym,'.',t,ym,'r-')
%text(0.25,2.4,'Respon Model'),text(0.8,2.1,'Respon Plant')
xlabel('Time (second)')
ylabel('Sinyal Kontrol (output)')
title('Perbandingan Respon Model dengan Respon Plant')
%yp:plant
%ym:model
grid;

% 16. Tegangan Kerja Dioda


format short;
clear all;
disp(' ')
disp('_____________________________________________')
disp(' ')
disp(' MENGHITUNG TEGANGAN KERJA DIODA ')
disp(' DENGAN METODE LANGSUNG ')
disp('_____________________________________________')
disp(' ')
epsilon=0.0001;
x=1;
Is=input ('Is= ');
R=input ('R= ');
Vb=input('Vb= ');
v=input ('Tegangan Awal Tegangan v= ');
disp('_____________________________________________')
disp(' ')
disp('Iterasi Tegangan f(v) abs(v1 - v) ')
disp(' ke : Kerja Dioda ')
disp(' (volt) ')
disp('_____________________________________________')
disp(' ')
format short g
iter=0;
while x >= epsilon
iter=iter + 1;
fv=R*Is*(exp(40*v)-1)+v-Vb;
v1=(log(((Vb-v)/(R*Is))+1))/40;
x=abs(v1-v);
v=v1;
fprintf('%i',iter),disp([v1, fv, x])

4
end
disp('_____________________________________________')

% 17. Penyelesaian dengan Matlab;


format short;
clear all;
Xs=1.15; %reaktansi sinkron
Xe=0.15; %rektansi ekivalen
Pm=1.2; %daya output
V=1.0; %tegangan bus
%Reaktansi total
Xt=Xs+Xe;
%A. Hitung tegangan eksitasi
%Dari persamaan Pm=E*V/Xt
E=Pm*Xt/V
%B. Jika daya output berkurang 0.7 pu
P=0.7;
%Hiutung arus dan pergeseran sudut yang baru
%Dari persamaan P=Pm*sin(theta)
theta=asin(P/Pm);
theta_deg=theta*180/pi
E_kompleks=E*(cos(theta)+i*sin(theta));
I=(E_kompleks-V)/Xt*i;
mutlak_arus_I=abs(I),['A']
eta=atan(imag(I)/real(I));
argumen_I=eta*180/pi
Pergeseran_sudut_I=eta*180/pi

% 18. Contoh soal


%Dua buah resistor R1 = 10 ohm, R2 = 20 ohm terhubung seri pada sumber 24
%volt. Hitunglah :
%a. Tahanan total (Rt)
%b. Arus rangkaian (I)
%a. Daya yang diserap (P)
%Penyelesaian
format short;
clear all;
R1=10;
R2=20;
Vs=24;
Rt=R1+R2
I=Vs/Rt
P=Vs*I
P=I^2*Rt

% 19. Contoh Subplot


format short;
clear all;
x=linspace (0,2*pi,30);
y=sin(x);
z=cos(x);
a=2*sin(x).*cos(x);
b=sin(x)./(cos(x)+eps);
subplot(2,2,1) %Meletekkan subplot kiri atas dari array subplot 2x2
plot(x,y), axis([0 2*pi -1 1]), title('sin(x)')
grid;
subplot(2,2,2) %Meletekkan subplot kanan atas dari 4 subplot
plot(x,z), axis([0 2*pi -1 1]), title('cos(x)')
grid;

5
subplot(2,2,3) %Meletekkan subplot kiri bawah dari 4 subplot
plot(x,a), axis([0 2*pi -1 1]), title('2sin(x)cos(x)')
grid;
subplot(2,2,4) %Meletekkan subplot kanan bawah dari 4 subplot
plot(x,b), axis([0 2*pi -1 1]), title('sin(x)/cos(x)')
grid;

Saluran Transmisi

% 20. Contoh Saluran Pendek


format short;
clear all;
% ==============================================================
%
% TRANSMISI LISTRIK SALURAN PENDEK
%
% ==============================================================
Vrll= 23000;
f= 60;
Z= 2.48+6.57i;
magZ= abs(Z);
sudutZ= angle(Z)*180/pi;
Load= 9000000;
kospi= 0.85;
acospi= acos(kospi)*180/pi;
sinpi= sin(acospi*pi/180)

%Penyelesaian
%Tegangan line to netral
disp('Tegangan Line To Netral :')
Vrln= Vrll/sqrt(3);
magVrln= abs(Vrln);
sudutVrln= angle(Vrln)*180/pi;
disp(['Vrln = ',num2str(Vrln),' volt']);
fprintf('Tegangan Ln = %g<%g \n', magVrln,sudutVrln);
%Arus line
disp('Arus Line :')
Iln=(Load/(sqrt(3)*Vrll*kospi))*(kospi-sinpi*i);
magIln= abs(Iln);
sudutIln=angle(Iln)*180/pi;
disp(['Iln = ',num2str(Iln),' A']);
fprintf('Arus Ln = %g<%g \n', magIln,sudutIln);
%Drop tegangan
disp('Drop Tegangan :')
Vdrop= Iln*Z;
magVdrop= abs(Vdrop);
sudutVdrop= angle(Vdrop)*180/pi;
disp(['Vdrop = ',num2str(Vdrop),' volt']);
fprintf('Drop Tegangan = %g<%g \n', magVdrop,sudutVdrop);
%Tegangan sisi kirim
%Tegangan line to netral
disp('Tegangan Sisi Kirim :')
disp('Tegangan Line To Netral :')
Vsln= Vrln+Vdrop;
%Bentuk rectangular
magVsln= abs(Vsln);
sudutVsln= angle(Vsln)*180/pi;
disp('Tegangan sisi kirim')
disp(['Vsln = ',num2str(Vsln),' volt']);

6
fprintf('Tegangan Ln = %g<%g \n', magVsln,sudutVsln);
%Tegangan line to line
disp('Tegangan Line to Line:')
Vsll= sqrt(3)*Vsln;
%bentuk rectangular
magVsll= abs(Vsll);
sudutVsll=angle(Vsll)*180/pi;
disp(['Vsll = ',num2str(Vsll),' volt']);
fprintf('Tegangan ll = %g<%g\n', magVsll,sudutVsll);
%Sudut fasa
disp('Sudut Fasa:')
teta=sudutVsll;
disp(['teta = ',num2str(teta), '']);

Selamat Bekerja

You might also like