• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Feb 5th, 2018 245 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # -*- coding: utf-8 -*-
2. """
3. Created on Fri Apr  4 02:53:30 2014
4.
5. @author: user
6. """
7.
8. from numpy import dot, array
9.
10. """
11. a1=array(
12. [[2.,3.,1.,5.],
13.  [6.,13.,5.,19.],
14.  [2.,19.,10.,23.],
15.  [4.,10.,11.,31.]])
16.
17. b1=array([1.,1.,1.,1.])
18.
19. a1=array(
20. [[2.,-1.,0.],
21.  [-1.,2.,-1.],
22.  [0.,-1.,1.]])
23.
24. b1=array([1.,0.,0.])
25. """
26.
27. a1=array(
28. [[0.,-1.,1.],
29.  [-1.,2.,-1.],
30.  [2.,-1.,0.]])
31.
32. b1=array([0.,0., 1.])
33.
34.
35. def GaussElimin(a,b):
36.     n = len(b)
37.   # Faza eliminacji
38.   # niejsca "wyzerowane" pozostawiane są bez zmian
39.     for k in range(0,n-1):
40.         for i in range(k+1,n):
41.            if a[i,k] != 0.0:
42.                alfa = a[i,k]/a[k,k]
43.                a[i,k+1:n] = a[i,k+1:n] - alfa*a[k,k+1:n]
44.                b[i] = b[i] - alfa*b[k]
45.   #Faza podstawianie wsteczne
46.     for k in range(n-1,-1,-1):
47.         b[k] = (b[k] - dot(a[k,k+1:n],b[k+1:n]))/a[k,k]
48.     return b
49.
50. print('wynik:',GaussElimin(a1,b1))
51. print('tablica a1 po elimonacji:')
52. print(a1)
53.
54. """
55. print('sprawdzenie dla wiersza [2.,-1.,0.]:', dot(array([2.,-1., 0.]),array([1.,1.,1.])))
56. print('sprawdzenie dla wiersza [-1.,2.,-1.]:', dot(array([-1.,2.,-1.]),array([1.,1.,1.])))
57. print('sprawdzenie dla wiersza [0.,-1.,1.]:', dot(array([0.,-1.,1.]),array([1.,1.,1.])))
58. """
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top