 # Untitled

a guest
Nov 24th, 2011
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. %% Create Matrices
2.
3. % Create y (solution) vector
4. y(1)        = 80;
5. y(2:6)      = 40;
6. y(7:10)     =  0;
7. y(11)       = 40;
8. y(12:15)    =  0;
9. y(16)       = 40;
10. y(17:20)    =  0;
11. y(21)       = 30;
12. y(22:25)    = 10;
13.
14. % Create diagonal vector for 4
15.
16. for i = 1:25
17.     v(i) = 4;
18. end
19.
20. % Create diagonal vector for -1 dependant on the sizes needed
21.
22. for i = 1:24
23.     w(i) = -1;
24. end
25.
26. for i = 1:20
27.     k(i) = -1;
28. end
29.
30. % Create vector A with the diagonals
31.
32. A = diag(v) + diag(w,1) + diag(w,-1) + diag(k,5) + diag(k,-5);
33.
34. % Remove undependant variables from A (edges of the roster)
35.
36. for i=5:5:19;
37.     j= i+1;
38.     A(j,i) = 0;
39.     i+5;
40. end
41.
42. % Solve for 'x'
43.
44. x = A\y';
45.
46. %% Plot the solution
47.
48. % Create matrix X to correspond to the grid
49. s = 1
50. for i = 1:5
51.     for j = 1:5
52.         X(i,j) = x(s);
53.         s = s+1;
54.     end
55. end
56.
57. % Plot X with surf
58.
59. surf(X);
60.
61.