Upload
hoangquynh
View
222
Download
0
Embed Size (px)
Citation preview
Penggunaan Gugus Data
Penggunaan Gugus Data SAS
• Pernyataan USE untuk membuka gugus data SAS
USE SAS-data-set <VAR operand > <WHERE(expression) > ;
• Using the READ Statement with the VAR and INTO Clauses
• Pernyataan CREATE membuka gugus data baru baik sebagai
gugus data input maupun output
Latihan 1
– Bangkitkanlah variabel berikut ini pada tahapan data dengan nama data1 • x = 1,2,3…,50
• y = x(1/x)
• z = x/y
– Gunakan pada proc IML dengan semua variabel tersebut menjadi satu variabel A, kemudian carilah rataan untuk setiap variabel (misalkan M).
– Buatlah data “hasil” dari proc IML tersebut yang berisi M
Jawaban 1 data data1;
do x = 1 to 50;
y =x**(1/x);
z =x/y;
output;
end;
run;
proc iml;
use data1;
read all var {x y z} into A;
M = A[:,];
create hasil var{M};
append;
quit;
proc print data=hasil;
run;
Iterative and Conditional Processing
• Do
do;
IML statements
end;
• If-then/else
if <expression> then <statement1>;
else <statement2>;
Latihan 2
proc iml;
reset print;
y = 8;
do while(y < 11);
y = y + 2;
end;
y = 8;
do until(y > 12);
y = y + 2;
end;
proc iml; x=9; if x>6 then x=1; else if x<=6 & x>2 then x=2; else x=3; print x;
Iterative Modules
• Using DO statement clauses :
DO scalar=start TO stop <BY increment>;
DO <scalar=start TO stop <BY increment>>
WHILE(expression);
DO <scalar=start TO stop <BY increment>>
UNTIL(expression);
Application 1
• Forecasting the sum of infinity sequent
Assume we have infinity sequent 𝑧
so 𝑧 = 𝑧1, 𝑧2, 𝑧3…
We need to forecast the number of sum from 𝑧
𝑠𝑢𝑚 𝑧 = 𝑧𝑖
∞
𝑖=1
Latihan 3
• Suppose an infinity sequent 𝑦 where
𝑦𝑖 =2𝑖 + 1
𝑖2 + 2
We need to forecast sum of 𝑦𝑖, let
𝑧 = 𝑦𝑖 = 2𝑖 + 1
𝑖2 + 2
∞
𝑖=1
∞
𝑖=1
Jawaban 3 proc iml;
start ss;
y0 = 0;
i = 1;
e = 10;
do while(e>0.00001);
y1 = y0 + (2*i +1)/(i**2 + 2);
e = abs(y1-y0);
y0 = y1;
i = i+1;
end;
finish;
run ss;
print y0 y1 i;
Latihan 4
• Make an IML program for calculating the forecasting of sum from
𝑧 = 2 −6
5+8
10−10
17+12
26−⋯
Jawaban 4
𝑧 = −1 𝑛+12𝑛 + 2
𝑛2 + 1
∞
𝑛=1
proc iml;
start ss1;
y0 = 0;i = 1;e = 10;
do while(e>0.00001);
y1 = y0 + (((-1)**(i+1))*((2*i)+2)/((i**2)+1));
e = abs(y1-y0);
y0 = y1;
i = i+1;
end;
finish;
run ss1;
print y0 y1 i;
Latihan 5
• Find the forcasting of sum from this sequent below: 2
5+3
40+6
135+11
320+18
625+27
1080+⋯
Jawaban 5
𝑛2 − 2𝑛 + 3
5𝑛3
∞
𝑛=1
proc iml;
start ss2;
y0 = 0; i = 1; e = 10;
do while(e>0.00001);
y1 = y0 + ((i-1)**2+2)/(5*i**3);
e = abs(y1-y0);
y0 = y1;
i = i+1;
end;
finish;
run ss2;
print y0 y1 i;
Application 2
• Numerical Methods for finding solution from equation 𝑓 𝑥 = 0
→ Newton Raphson
𝑥𝑛+1 = 𝑥𝑛 −𝑓(𝑥𝑛)
𝑓′(𝑥𝑛)
Latihan 6
• Let the equation 𝑥3 − 𝑥 − 1 = 0
Using Newton Raphson method, find the real
root from the equation above !
Jawaban 6
• 𝑓 𝑥 = 𝑥3 − 𝑥 − 1
• 𝑓′ 𝑥 = 3𝑥2 − 1
• Since 𝑓 1 = −1 and 𝑓 2 = 5, the function has a root in the interval [1,2]
• Let’s make an initial guess 𝑥0 = 1.5
𝑥𝑛+1 = 𝑥𝑛 −𝑥𝑛3 − 𝑥𝑛 − 1
3𝑥𝑛2 − 1
Jawaban 6
proc iml;
*evaluasi selisih x;
start nr(x0) global(i);
e = 10;
i = 1;
do while(e>0.00001);
x1 = x0 - (x0**3-x0-1)/(3*x0**2-1);
e = abs(x1-x0);
x0 = x1;
i = i+1;
end;
return(x1);
finish;
x0 = 1.5;
hasil = nr(x0);
print hasil i;
Jawaban 6
*evaluasi nilai f(x) menuju 0;
start nr1(x0) global(i);
e = 10;
i = 1;
do while(e>0.00001);
x1 = x0 - (x0**3-x0-1)/(3*x0**2-1);
f1 = x1**3-x1-1;
e = abs(f1-0);
x0 = x1;
i = i+1;
end;
return(x1);
finish;
x0 = 1.5;
hasil = nr1(x0);
print hasil i;
Plot latihan 6
*PLOT;
data plotnr;
do x = -10 to 10 by 0.1;
y = x**3-x-1;
output;
end;
run;
proc plot;
plot y*x;
run;