Anda di halaman 1dari 6

Contoh Program 3 Dimensi M-file

1.
>> t=[0:pi/30:6*pi];
>> x=t.*cos(t);
>> y=t.*sin(t);
>> z=t;
>> plot3(x,y,z)

2.

h1=surf(Xi,Yi,U(:,:,1),'erasemode','normal');

shading interp;
%colormap(gray);
colorbar;
axis([0 3 0 3 -1 1]);
caxis([-.25 .25]);

for ii = 2:M
set(h1,'zdata',U(:,:,ii));
refreshdata;
drawnow;
% pause(0.01);
% pause(0.3);
end

3.
x=linspace(-5,5,21)
y=x.^2
plot(x,y,'linewidth',4)
set(gcf, 'color','black')
set(gcf,'menubar','none')
set(gcf,'numbertitle','off')
set(gcf,'name','My Nice Graph')

Contoh Program 2 Dimensi M-file

1.

>> y1 = inline(‘ x^2 ’); % simbol “^” menandakan pangkat

>> ezplot(y1)

2.

>> y = [ 1 5 -6 8 9 19];
>> plot(y,’-.’)   –> {Mengubah style garis menjadi Dash-dot line}

>> plot(y,’-.’,’LineWidth’,1)   –> {Mengubah style garis menjadi Dash-dot line


dengan tebal garis menjadi 1 points}

>> plot(y,’r-.’),grid  –> {Mengubah style garis menjadi Dash-dot line dengan warna
garis merah menambahkan grid}

>> hold on   –> {Menggabungkan}

>> plot(y,’o’)   –> {Menggambarkan mark titik data}

>> hold off   –> {Proses panggabungan selesai}

>> title(‘y = [ 1 5 -6 8 9 19]’)   –> {Memberikan judul y = [ 1 5 -6 8 9 19]}

>> xlabel(‘Nilai x’)   –> {Memberi label pada sumbu x dengan nama Nilai x}

>> ylabel(‘Sumbu y’)   –> {Memberi label pada sumbu y dengan nama Nilai y}

>> text(3.7,2,’\leftarrow y = [1 5 -6 8 9 19]‘,’FontSize’,12)   –> {Memberikan


keterangan y = [1 5 -6 8 9 19] dengan font size 12 pada koordinat (3.7,2)}

3.

>> y = [ 1 5 -6 8 9 19];

>> plot(y)

Menggunakan For

1.
For n =10 : 100
X(n)=cos(n*pi/10);
End
X
Menggunakan If else

1.
#include
#include

main()
{
int b, t;
printf("Jumlah Hari dalam Sebulan \n");
printf("Silakan masukkan bulan ke 1 - 12= \n");
scanf("%i", &b);

printf("masukkan tahun = (bebas) \n");


scanf("%i", &t);

if (b==1)
{
printf("Januari \n");
printf("jumlah hari = 31 \n");
}

else if (b==2&&t%4==0)
{
printf("Februari \n");
printf("jumlah hari = 29 \n");
}
else if (b==2&&t%4!=0)
{
printf("Februari \n");
printf("jumlah hari = 28 \n");
}

else if (b==3)
{
printf("Maret \n");
printf("jumlah hari = 31 \n");
}

else if (b==4)
{
printf("April \n");
printf("jumlah hari = 30 \n");
}

else if (b==5)
{
printf("Mei \n");
printf("jumlah hari = 31 \n");
}

else if (b==6)
{
printf("Juni \n");
printf("jumlah hari = 30 \n");
}

else if (b==7)
{
printf("Juli \n");
printf("jumlah hari = 31 \n");
}

else if (b==8)
{
printf("Agustus \n");
printf("jumlah hari = 31 \n");
}

else if (b==9)
{
printf("September \n");
printf("jumlah hari = 30 \n");
}

else if (b==10)
{
printf("Oktober \n");
printf("jumlah hari = 31 \n");

else if (b==11)
{
printf("Nopember \n");
printf("jumlah hari = 30 \n");
}

else if (b==12)
{
printf("Desember \n");
printf("jumlah hari = 31 \n");
}

else
{
printf("Error,,,, \n");
printf("Baca ketentuan di atas!\n");
}

getch();
}

Menggunkan While

1. #include
#include
#include
#include

#define orde 16

void delay(s16 period);


int fir(int data);

HANDLE hHandset;
s16 data;
float output;
int i, count=0;
int buf[orde+1]={0};
float coeff[orde+1]={
-0.002273,
0.000166,
0.009495,
0.008448,
-0.031839,
-0.056286,
0.060089,
0.297753,
0.426758,
0.297753,
0.060089,
-0.056286,
-0.031839,
0.008448,
0.009495,
0.000166,
-0.002273
};

void main()
{
s16 cnt=2;

if (brd_init(100))
return;

/* blink the leds a couple times */


while ( cnt-- )
{
brd_led_toggle(BRD_LED0);
delay(1000);
brd_led_toggle(BRD_LED1);
delay(1000);
brd_led_toggle(BRD_LED2);
delay(1000);
}

/* Open Handset Codec */


hHandset = codec_open(HANDSET_CODEC); /* Acquire handle to codec */

/* Set codec parameters */

codec_dac_mode(hHandset, CODEC_DAC_15BIT); /* DAC in 15-bit mode */


codec_adc_mode(hHandset, CODEC_ADC_15BIT); /* ADC in 15-bit mode */
codec_ain_gain(hHandset, CODEC_AIN_0dB); /* 0dB gain on analog input
to ADC */
codec_aout_gain(hHandset, CODEC_AOUT_MINUS_0dB); /* 0dB gain on
analog output from DAC */
codec_sample_rate(hHandset,SR_16000); /* 16KHz sampling rate */

/* Polling and digital loopback */


while (1)
{
/* Wait for sample from handset */
while (!MCBSP_RRDY(HANDSET_CODEC)) {};

/* Read sample from and write back to handset codec */


data = *(volatile u16*) DRR1_ADDR(HANDSET_CODEC);
*(volatile u16*)DXR1_ADDR(HANDSET_CODEC) = fir(data);
}
}

int fir(int data)


{
output = 0;

// geser buffer
for(i=orde+1;i>0;i--)
{
buf[i] = buf[i-1];
}
buf[0] = data;

// hitung output
for(i=0;i>1; j++);
}
}

Anda mungkin juga menyukai