You are on page 1of 4

COMPUTER APPLICATION IN PETROLEUM INDUSTRY (PE 315)

EXERCISE # 2
MATLAB
1.% Factorial Function.
>> n=12;
>> y=1;
>> for i=1:n;
y=y*i;
end
>> disp(y)
479001600
2.%Sum of squares Function.
>> N=100;
>> S=0;
>> for i=1:N;
S=S+i^2;
end
>> disp(S)
338350

3.% Gaussian function.


x=0:0.01:1;
a1=1;
a2=2;
a3=10;
a4=100;
y=exp(-a1*x.^2);
y2=exp(-a2*x.^2);
y3=exp(-a3*x.^2);
y4=exp(-a4*x.^2);
subplot(2,2,1);
plot(x,y);

subplot(2,2,2);
plot(x,y2);
subplot(2,2,3);
plot(x,y3);
subplot(2,2,4);
plot(x,y4);
output.
1

1
0.8

0.8

0.6

0.6

0.4

0.4
0.2

0.2
0

0.5

0.8

0.8

0.6

0.6

0.4

0.4

0.2

0.2

0.5

0.5

0.5

COMPUTER APPLICATION IN PETROLEUM INDUSTRY (PE 315)


EXERCISE # 3
MATLAB.
1.differential equation
%Function Differential Equation.
N=100;
dx=2*pi/(N-1);
x=0:dx:2*pi;
y=cos(x)
diffy=diff(y)

Output
Columns 66 through 78

0.0539 0.0559 0.0577 0.0593 0.0606


0.0634 0.0634 0.0633 0.0628 0.0621

0.0617

0.0625

0.0631

0.0528

0.0505

0.0480

0.0100

0.0060

0.0020

Columns 79 through 91

0.0612 0.0600 0.0585 0.0569 0.0550


0.0452 0.0423 0.0392 0.0360 0.0326

Columns 92 through 99

0.0291

0.0254

0.0217

>> max(y)

ans =

>> min(y)

ans =

-0.9995

1.differential equation

N=100;
dx=10/(N-1);
x=0:dx:10;
x0=5;
y=exp(-(x-x0).^2)
diffy=diff(y)

0.0179

0.0140

Output
Columns 66 through 78

-0.0240 -0.0182 -0.0135 -0.0098 -0.0069 -0.0048 -0.0032 -0.0021


-0.0014 -0.0009 -0.0005 -0.0003 -0.0002

Columns 79 through 91

-0.0001 -0.0001 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000


-0.0000 -0.0000 -0.0000 -0.0000 -0.0000

Columns 92 through 99

-0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000 -0.0000

>> max(y)

ans =

0.9975

>> min(y)

ans =

1.3888e-011

You might also like