Advertisement
SilLAwNeD

Scilab, rich function

Oct 16th, 2018
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.67 KB | None | 0 0
  1. function [x] = rich(a, b, c, u)
  2.     n = size(b, 1)
  3.     e = zeros(n, 1)
  4.     f = zeros(n, 1)
  5.     x = zeros(n, 1)
  6.  
  7.     tol = 1e-12
  8.  
  9.     if b(1) < tol then
  10.         msg = sprintf("b(%d) = %f", i , b);            
  11.         error(msg)
  12.     end
  13.     e(1) = -c(1)/b(1)
  14.     f(1) =  u(1)/b(1)
  15.  
  16.     for i = 2:n
  17.         DD = a(i) * e(i-1) + b(i)
  18.         if (abs(DD) < tol) then
  19.             msg = sprintf("DD(%d) = %f", i , DD);            
  20.             error(msg)
  21.         end
  22.         e(i) = - c(i) / DD; // e(n) pas utilise
  23.         f(i) = (u(i) - a(i) * f(i-1)) / DD
  24.     end
  25.  
  26.     x(n) = f(n)
  27.  
  28.     for j = n-1:-1:1
  29.         x(j) = e(j) * x(j+1) + f(j)
  30.     end
  31.  
  32. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement