0% found this document useful (0 votes)
18K views

Ujian Mid Semester

The document discusses a mid-semester exam for computational physics. It describes using the false position method and Gauss-Seidel iteration method to solve non-linear and linear equations respectively in MATLAB. It provides the code and output for an example problem solved using both methods up to a certain number of iterations. It also notes some inconsistencies found between the m-files used and the MATLAB version.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18K views

Ujian Mid Semester

The document discusses a mid-semester exam for computational physics. It describes using the false position method and Gauss-Seidel iteration method to solve non-linear and linear equations respectively in MATLAB. It provides the code and output for an example problem solved using both methods up to a certain number of iterations. It also notes some inconsistencies found between the m-files used and the MATLAB version.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

UJIAN MID SEMESTER

FISIKA KOMPUTASI

Oleh :

AKHMAD FAUZUL ALBAB ( 080210102032 )

PROGRAM STUDI PENDIDIKAN FISIKA

JURUSAN PENDIDIKAN MATEMATIKA DAN ILMU PENGETAHUAN ALAM

FAKULTAS KEGURUAN DAN ILMU PENDIDIKAN

UNIVERSITAS JEMBER

2010
% Metode Titik Palsu
[i,a,b,x,fx]=tpalsu('fungsi',0.5,1,0.000001)

y =

-0.3776

y =

0.4597

y =

-0.0227

y =

-0.22269975597064

y =

-0.30882768139645

y =

-0.34680225681176

y =

-0.36374798015987

y =

-0.37135309985582

y =

-0.37477522324788

y =

-0.37631694611429

y =

-0.37701189523381
y =

-0.37732522840335

y =

-0.37746651725082

y =

-0.37753023069978

y =

-0.37755896258649

y =

-0.37757191950103

y =

-0.37757776257032

y =

-0.37758039757491

y =

-0.37758158586403

y =

-0.37758212173848

i =

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

a =

0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000
0.50000000000000

b =

1.00000000000000
0.72548158706393
0.60168389220974
0.54585569078858
0.52067922786984
0.50932557023870
0.50420548875540
0.50189652055789
0.50085526093059
0.50038569118396
0.50017393252055
0.50007843716155
0.50003537227134
0.50001595159176
0.50000719358045
0.50000324403987
0.50000146294252
0.50000065973320

x =

0.72548158706393
0.60168389220974
0.54585569078858
0.52067922786984
0.50932557023870
0.50420548875540
0.50189652055789
0.50085526093059
0.50038569118396
0.50017393252055
0.50007843716155
0.50003537227134
0.50001595159176
0.50000719358045
0.50000324403987
0.50000146294252
0.50000065973320
0.50000029751538

fx =

-0.02269839066549
-0.22269975597064
-0.30882768139645
-0.34680225681176
-0.36374798015987
-0.37135309985582
-0.37477522324788
-0.37631694611429
-0.37701189523381
-0.37732522840335
-0.37746651725082
-0.37753023069978
-0.37755896258649
-0.37757191950103
-0.37757776257032
-0.37758039757491
-0.37758158586403
-0.37758212173848

% dari perhitungan sebuah fungsi persamaan tak linier F(x)= x-cos(x)


menggunakan metode regular falsi atau titik palsu diperoleh iterasi
hingga iterasi ke-18.

% Metode Gauss Seidel


A=[3 -3 3;-3 5 1;-3 1 5]

A =

3 -3 3
-3 5 1
-3 1 5

b=[9;-7;12]

b =

9
-7
12
x0=[0 0 0]'

x0 =

0
0
0

x=gauss_seidel(A,b,x0,10e-6,10)
??? Undefined function or variable 'gauss_seidel'.

x=gauss_seidel(A,b,x0,10e-6,10)
??? Undefined function or variable 'gauss_seidel'.

x=gaussd(A,b,x0,10e-6,10)
??? Error using ==> gaussd
Too many input arguments.

x=gaussd(A,b,x0,10e-6,10)
??? Error using ==> gaussd
Too many input arguments.

gasd

xlama =

0
0
0

n =

itermaks =

10

sc =

0.00100000000000

??? Index exceeds matrix dimensions.

Error in ==> C:\MATLAB6p1\work\gasd.m


On line 14 ==> xbaru(2,1)=(1/11)*xbaru(1,1)+(1/11)*xlama(3,1)-
(3/11)*xlama(4,1)+(25/11);

gasd

xlama =

0
0
0

n =

itermaks =

10

sc =

1.000000000000000e-006

??? Index exceeds matrix dimensions.

Error in ==> C:\MATLAB6p1\work\gasd.m


On line 14 ==> xbaru(2,1)=(1/11)*xbaru(1,1)+(1/11)*xlama(3,1)-
(3/11)*xlama(4,1)+(25/11);

x=GS(A,b,x0,10e-6,20)
??? Error: File: C:\MATLAB6p1\work\GS.m Line: 17 Column: 17
")" expected, "]" found.

x=gaussd(A,b,x0,10e-6,20)
??? Error using ==> gaussd
Too many input arguments.

x=gaussd(A,b,x0,10e-6,20)
??? Error: File: C:\MATLAB6p1\work\gaussd.m Line: 17 Column: 17
")" expected, "]" found.

[x]=gaussd(A,b,x0,10e-6,20)
??? Error: File: C:\MATLAB6p1\work\gaussd.m Line: 17 Column: 17
")" expected, "]" found.

[x]=gaussd(A,b,x0,10e-6,20)
??? Error: File: C:\MATLAB6p1\work\gaussd.m Line: 18 Column: 5
Illegal use of reserved keyword "for".

[x]=gaussd(A,b,x0,10e-6,20)
??? Undefined function or variable 'xo'.

Error in ==> C:\MATLAB6p1\work\gaussd.m


On line 4 ==> [n,m]=size(A); x=xo; C=-A;maks=100;

A=[3 -3 3;-3 5 1;-3 1 5]

A =

3 -3 3
-3 5 1
-3 1 5

b=[9;-7;12]
b =

9
-7
12

x0=[0 0 0]';
hasil=gaussd(A,b,x0,0.000001)
??? Error using ==> eye
Unknown command option.

Error in ==> C:\MATLAB6p1\work\gaussd.m


On line 3 ==> D=eye(A).*A;

cd ..
cd('C:\MATLAB6p1\work')
SEidel
??? Input argument 'n' is undefined.

Error in ==> C:\MATLAB6p1\work\SEIDEL.m


On line 9 ==> vb = 1:n;

SEIDEL
??? Input argument 'n' is undefined.

Error in ==> C:\MATLAB6p1\work\SEIDEL.m


On line 9 ==> vb = 1:n;

SPL

SPL - sistem persamaan linear

Masukkan matriks A : [3 -3 3;-3 5 1;-3 1 5]


Vektor kolom b : [9;-7;12]
iterasi ke-1
x =

3.00000000000000 0.40000000000000 4.12000000000000

iterasi ke-2
x =

-0.72000000000000 -2.65600000000000 2.49920000000000

iterasi ke-3
x =

-2.15520000000000 -3.19296000000000 1.74547200000000

iterasi ke-4
x =

-1.93843200000000 -2.91215360000000 1.81937152000000

iterasi ke-5
x =
-1.73152512000000 -2.80278937600000 1.92164280320000

iterasi ke-6
x =

-1.72443217920000 -2.81898786816000 1.92913826611200

iterasi ke-7
x =

-1.74812613427200 -2.83470333378560 1.91806498619392

iterasi ke-8
x =

-1.75276831997952 -2.83527398922650 1.91539380585759

iterasi ke-9
x =

-1.75066779508408 -2.83347943822197 1.91629521059394

iterasi ke-10
x =

-1.74977464881591 -2.83312383140834 1.91675997699212

iterasi ke-11
x =

-1.74988380840046 -2.83328228043870 1.91672617104747

iterasi ke-12
x =

-1.75000845148616 -2.83335030510119 1.91666499012854

iterasi ke-13
x =

-1.75001529522973 -2.83334217516355 1.91665925789487

x =

-1.75001529522973 -2.83334217516355 1.91665925789487

clear seidel
SPL

SPL - sistem persamaan linear

Masukkan matriks A : [3 -3 3;-3 5 1;-3 1 5]


Vektor kolom b : [9;-7;12]
iterasi ke-1
x =

3.00000000000000 0.40000000000000 4.12000000000000


iterasi ke-2
x =

-0.72000000000000 -2.65600000000000 2.49920000000000

iterasi ke-3
x =

-2.15520000000000 -3.19296000000000 1.74547200000000

iterasi ke-4
x =

-1.93843200000000 -2.91215360000000 1.81937152000000

iterasi ke-5
x =

-1.73152512000000 -2.80278937600000 1.92164280320000

iterasi ke-6
x =

-1.72443217920000 -2.81898786816000 1.92913826611200

iterasi ke-7
x =

-1.74812613427200 -2.83470333378560 1.91806498619392

iterasi ke-8
x =

-1.75276831997952 -2.83527398922650 1.91539380585759

iterasi ke-9
x =

-1.75066779508408 -2.83347943822197 1.91629521059394

iterasi ke-10
x =

-1.74977464881591 -2.83312383140834 1.91675997699212

iterasi ke-11
x =

-1.74988380840046 -2.83328228043870 1.91672617104747

iterasi ke-12
x =

-1.75000845148616 -2.83335030510119 1.91666499012854

iterasi ke-13
x =
-1.75001529522973 -2.83334217516355 1.91665925789487

x =

-1.75001529522973 -2.83334217516355 1.91665925789487

% Pada pengerjaan secara komputasi dengan menggunakan matlab,ditemukan


beberapa ketidakcocokan pada penginputan m-file yang dikarenakan
kekompatiblean atau kecocokan dari versi matlab yang digunakan.Oleh
karena itu,kami ikut menyertakan beberapa alternatif jenis m-file yang
dapat digunakan untuk menyelesaikan persamaan linear dengan metode
iterasi gauss-seidel.
% Namun m-file yang kami gunakan yakni : untuk metode gaus-seidel
bernama”SPL” dan untuk metode titik palsu bernama”tpalsu” & “fungsi”.
% Dari hasil perhitungan dengan iterasi Gauss-seidel didapatkan hingga
iterasi ke-13 dimana nilai dari X1 = -1.75001529522973 dan X2 =
-2.83334217516355 serta X3 = 1.91665925789487.
diary off

You might also like