Advertisement
Guest User

scilab4

a guest
Sep 1st, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.59 KB | None | 0 0
  1. //algoritmo jacobi:
  2. // Implementa o metodo de Jacobi
  3. // A: matriz de coeficientes
  4. // b : termos independentes
  5. function [ x , it ] = jacobi( A , b , x0, erro_aceit , niteracoes )
  6.        sol = x0; // solucao inicial
  7.        erro_rel = 1;
  8.        it = 0;
  9.        while( (erro_aceit < erro_rel) & it < niteracoes ),
  10.  
  11.            for i=1:size(A,'r'),
  12.                 x(i) = (-1)*( (A(i,:)*sol-( A(i,i)*sol(i)+b(i) ) )/ A(i,i));
  13.            end
  14.            erro_rel = (norm(sol-x,'inf')) / norm(x,'inf');
  15.            sol = x;
  16.            it = it + 1;
  17.        if( it == niteracoes ),
  18.            x = string("O metodo nao convergiu para ")+string(it)+string(" iteracoes.");
  19.            return;
  20.        end
  21. disp(sol')
  22.       end
  23.       x = sol;
  24. endfunction
  25.  
  26.  
  27. //códigos do scilab
  28.  
  29.  
  30.  
  31. -->A=[1 2 -1; 4 -1 5; -1 7 -3]
  32. A  =
  33.  
  34.    1.    2.  - 1.  
  35.    4.  - 1.    5.  
  36.  - 1.    7.  - 3.  
  37.  
  38. -->b=[3 0 -3]'
  39.  b  =
  40.  
  41.     3.  
  42.     0.  
  43.   - 3.  
  44.  
  45. -->b=[3 0 -10]'
  46. b  =
  47.  
  48.    3.  
  49.    0.  
  50.  - 10.  
  51.  
  52. -->x0=[0 0 0;]'
  53.  x0  =
  54.  
  55.     0.  
  56.     0.  
  57.     0.  
  58.  
  59. -->erro_aceit=10.^-3
  60.  erro_aceit  =
  61.  
  62.     0.0010000000000000000208  
  63.  
  64. -->niteracoes=50
  65.  niteracoes  =
  66.  
  67.     50.  
  68.  
  69. -->exec('C:\Users\aluno\Documents\calc numerico\jacobi.sci', -1)
  70.  
  71. -->exec('C:\Users\aluno\Documents\calc numerico\jacobi.sci', -1)
  72. Aviso: redefinindo a função: jacobi                  . Utilize funcprot(0) para evitar esta mensagem
  73.  
  74.  
  75. -->exec('C:\Users\aluno\Documents\calc numerico\jacobi.sci', -1)
  76.  
  77. -->jacobi( A , b , x0, erro_aceit , niteracoes )
  78.  
  79.     3.    0.    3.3333333333333334813631  
  80.  
  81.     6.3333333333333339254523    28.666666666666667850905    2.3333333333333334813631  
  82.  
  83.   - 52.    37.    68.11111111111111426908  
  84.  
  85.   - 2.8888888888888857309212    132.55555555555554292368    107.  
  86.  
  87.   - 155.11111111111105742566    523.44444444444445707632    313.59259259259255259167  
  88.  
  89.   - 730.29629629629630471754    947.51851851851859009912    1276.4074074074071631912  
  90.  
  91.   - 615.62962962963001700700    3460.8518518518503697123    2457.6419753086424861976  
  92.  
  93.   - 4461.0617283950587079744    9825.6913580246928177075    8283.864197530861929408  
  94.  
  95.   - 11364.51851851852188702    23575.07407407407299615    24416.967078189303720137  
  96.  
  97.   - 22730.181069958838634193    76626.76131687243469059    58800.012345679009740707  
  98.  
  99.   - 94450.51028806585236453    203079.33744855970144272    186375.83676268861745484  
  100.  
  101.   - 219779.83813443075632676    554077.14266117964871228    505338.62414266122505069  
  102.  
  103.   - 602812.66117969807237387    1647573.7681755830999464    1366109.9455875628627837  
  104.  
  105.   - 1929034.5907636033371091    4419299.0832190215587616    4045279.6794695928692818  
  106.  
  107.   - 4793315.4869684502482414    12510260.034293550997972    10954712.724432250484824  
  108.  
  109.   - 14065804.344154851511121    35600301.6742874532938    30788381.909007769078016  
  110.  
  111.   - 40412218.439567141234875    97678692.168419435620308    87755975.3547223508358  
  112.  
  113.   - 107601405.98211652040482    277131003.0153431892395    241387691.20616769790649  
  114.  
  115.   - 312874311.82451868057251    776532832.10237240791321    682506145.69650626182556  
  116.  
  117.   - 870559515.50823855400085    2161033481.1844568252563    1916201382.1803753376007  
  118.  
  119.   - 2405865577.1885380744934    6098768848.8689222335815    5332597964.5998125076294  
  120.  
  121.   - 6864939730.138032913208    17039527514.244911193848    15032415843.09033203125  
  122.  
  123.   - 19046639182.399490356445    47702320294.899528503418    42047210779.950805664063  
  124.  
  125.   - 53357429806.848251342773    134049497170.15606689453    117654293752.23205566406  
  126.  
  127.   - 150444700585.080078125    374841749533.76727294922    330567970002.64691162109  
  128.  
  129.   - 419115529061.88763427734    1051061047672.9143066406    924778982443.81701660156  
  130.  
  131.   - 1177343112899.0114746094    2947432795971.5341796875    2592180954260.7626953125  
  132.  
  133.   - 3302684637679.3056640625    8251532319707.7666015625    7269790894903.25  
  134.  
  135.   - 9233273744509.28125    23138215923799.02734375    20354470291881.22265625  
  136.  
  137.   - 25921961555713.83203125    64839256481368.984375    57066928403704.15625  
  138.  
  139.   - 72611584559030.8125    181646795795665.4375    159932252308435.59375  
  140.  
  141.   - 203361339282892.28125    509214923306054.75    448046385042899.5625  
  142.  
  143.   - 570383461569207.    1426786568082928.5    1255955267475095.25  
  144.  
  145.   - 1597617868690758.75    3998242491098648.    3519296479383239.5  
  146.  
  147.   - 4477188502814053.    11206010922153162.    9861771768793768.  
  148.  
  149.   - 12550250075512554.    31400104832712624.    27639754985962060.  
  150.  
  151.   - 35160454679463188.    87997774627760080.    77450327968166976.  
  152.  
  153.   - 98545221287353184.    246609821122982144.    217048292357927904.  
  154.  
  155.   - 276171349888036352.    691060576640226816.    608271323049409408.  
  156.  
  157.   - 773849830231044224.    1936671215694901760.    1704531795456541440.  
  158.  
  159.   - 2168810635933262336.    5427259656358531072.    4776849446698451968.  
  160.  
  161.   - 6077669866018611200.    15209004689759209472.    13386542743480993792.  
  162.  
  163.   - 17031466636037425152.    42622034253330522112.    37513567564777693184.  
  164.  
  165.   - 47730500941883351040.    119441971279738765312.    105128568803117039616.  
  166.  
  167.   - 133755373756360491008.    334720840248051761152.    294608099966684921856.  
  168.  
  169.   - 374833580529418633216.    938019004807982612480.    825600418497574207488.  
  170.  
  171.   - 1050437591118390886400.    2628667770370197028864.    2313655538061765509120.  
  172.  
  173.   - 2943680002678628286464.    7366527325835264786432.    6483703994569923231744.  
  174.  
  175.   - 8249350657100605292544.    20643799962135103012864.    18169790427841827962880.  
  176.  ans  =
  177.  
  178.  O metodo nao convergiu para 50 iteracoes.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement