Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //algoritmo jacobi:
- // Implementa o metodo de Jacobi
- // A: matriz de coeficientes
- // b : termos independentes
- function [ x , it ] = jacobi( A , b , x0, erro_aceit , niteracoes )
- sol = x0; // solucao inicial
- erro_rel = 1;
- it = 0;
- while( (erro_aceit < erro_rel) & it < niteracoes ),
- for i=1:size(A,'r'),
- x(i) = (-1)*( (A(i,:)*sol-( A(i,i)*sol(i)+b(i) ) )/ A(i,i));
- end
- erro_rel = (norm(sol-x,'inf')) / norm(x,'inf');
- sol = x;
- it = it + 1;
- if( it == niteracoes ),
- x = string("O metodo nao convergiu para ")+string(it)+string(" iteracoes.");
- return;
- end
- disp(sol')
- end
- x = sol;
- endfunction
- //códigos do scilab
- -->A=[1 2 -1; 4 -1 5; -1 7 -3]
- A =
- 1. 2. - 1.
- 4. - 1. 5.
- - 1. 7. - 3.
- -->b=[3 0 -3]'
- b =
- 3.
- 0.
- - 3.
- -->b=[3 0 -10]'
- b =
- 3.
- 0.
- - 10.
- -->x0=[0 0 0;]'
- x0 =
- 0.
- 0.
- 0.
- -->erro_aceit=10.^-3
- erro_aceit =
- 0.0010000000000000000208
- -->niteracoes=50
- niteracoes =
- 50.
- -->exec('C:\Users\aluno\Documents\calc numerico\jacobi.sci', -1)
- -->exec('C:\Users\aluno\Documents\calc numerico\jacobi.sci', -1)
- Aviso: redefinindo a função: jacobi . Utilize funcprot(0) para evitar esta mensagem
- -->exec('C:\Users\aluno\Documents\calc numerico\jacobi.sci', -1)
- -->jacobi( A , b , x0, erro_aceit , niteracoes )
- 3. 0. 3.3333333333333334813631
- 6.3333333333333339254523 28.666666666666667850905 2.3333333333333334813631
- - 52. 37. 68.11111111111111426908
- - 2.8888888888888857309212 132.55555555555554292368 107.
- - 155.11111111111105742566 523.44444444444445707632 313.59259259259255259167
- - 730.29629629629630471754 947.51851851851859009912 1276.4074074074071631912
- - 615.62962962963001700700 3460.8518518518503697123 2457.6419753086424861976
- - 4461.0617283950587079744 9825.6913580246928177075 8283.864197530861929408
- - 11364.51851851852188702 23575.07407407407299615 24416.967078189303720137
- - 22730.181069958838634193 76626.76131687243469059 58800.012345679009740707
- - 94450.51028806585236453 203079.33744855970144272 186375.83676268861745484
- - 219779.83813443075632676 554077.14266117964871228 505338.62414266122505069
- - 602812.66117969807237387 1647573.7681755830999464 1366109.9455875628627837
- - 1929034.5907636033371091 4419299.0832190215587616 4045279.6794695928692818
- - 4793315.4869684502482414 12510260.034293550997972 10954712.724432250484824
- - 14065804.344154851511121 35600301.6742874532938 30788381.909007769078016
- - 40412218.439567141234875 97678692.168419435620308 87755975.3547223508358
- - 107601405.98211652040482 277131003.0153431892395 241387691.20616769790649
- - 312874311.82451868057251 776532832.10237240791321 682506145.69650626182556
- - 870559515.50823855400085 2161033481.1844568252563 1916201382.1803753376007
- - 2405865577.1885380744934 6098768848.8689222335815 5332597964.5998125076294
- - 6864939730.138032913208 17039527514.244911193848 15032415843.09033203125
- - 19046639182.399490356445 47702320294.899528503418 42047210779.950805664063
- - 53357429806.848251342773 134049497170.15606689453 117654293752.23205566406
- - 150444700585.080078125 374841749533.76727294922 330567970002.64691162109
- - 419115529061.88763427734 1051061047672.9143066406 924778982443.81701660156
- - 1177343112899.0114746094 2947432795971.5341796875 2592180954260.7626953125
- - 3302684637679.3056640625 8251532319707.7666015625 7269790894903.25
- - 9233273744509.28125 23138215923799.02734375 20354470291881.22265625
- - 25921961555713.83203125 64839256481368.984375 57066928403704.15625
- - 72611584559030.8125 181646795795665.4375 159932252308435.59375
- - 203361339282892.28125 509214923306054.75 448046385042899.5625
- - 570383461569207. 1426786568082928.5 1255955267475095.25
- - 1597617868690758.75 3998242491098648. 3519296479383239.5
- - 4477188502814053. 11206010922153162. 9861771768793768.
- - 12550250075512554. 31400104832712624. 27639754985962060.
- - 35160454679463188. 87997774627760080. 77450327968166976.
- - 98545221287353184. 246609821122982144. 217048292357927904.
- - 276171349888036352. 691060576640226816. 608271323049409408.
- - 773849830231044224. 1936671215694901760. 1704531795456541440.
- - 2168810635933262336. 5427259656358531072. 4776849446698451968.
- - 6077669866018611200. 15209004689759209472. 13386542743480993792.
- - 17031466636037425152. 42622034253330522112. 37513567564777693184.
- - 47730500941883351040. 119441971279738765312. 105128568803117039616.
- - 133755373756360491008. 334720840248051761152. 294608099966684921856.
- - 374833580529418633216. 938019004807982612480. 825600418497574207488.
- - 1050437591118390886400. 2628667770370197028864. 2313655538061765509120.
- - 2943680002678628286464. 7366527325835264786432. 6483703994569923231744.
- - 8249350657100605292544. 20643799962135103012864. 18169790427841827962880.
- ans =
- O metodo nao convergiu para 50 iteracoes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement