Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.96 KB | None | 0 0
  1. /*
  2. *The main of 3x3matrix calc.
  3. */
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using System.Management;
  14.  
  15. namespace macierzekalk
  16. {
  17. public partial class Kalkulator_Macierzy : Form
  18. {
  19. float det = 0;
  20. float d11, d12, d13, d21, d22, d23, d31, d32, d33, //do wczytywania z m. pierwotnej
  21. w11, w12, w13, w21, w22, w23, w31, w32, w33, //do obliczania det
  22. o11, o12, o13, o21, o22, o23, o31, o32, o33, //do obliczania odwrotnej
  23. t11, t12, t13, t21, t22, t23, t31, t32, t33; //transponowanie
  24. string s11, s12, s13, s21, s22, s23, s31, s32, s33;
  25.  
  26. private void W11_TextChanged(object sender, EventArgs e)
  27. {
  28.  
  29. }
  30.  
  31. public Kalkulator_Macierzy()
  32. {
  33. InitializeComponent();
  34. }
  35.  
  36. private void D11M1(object sender, EventArgs e)
  37. {
  38.  
  39. }
  40.  
  41. private void textBox9_TextChanged(object sender, EventArgs e)
  42. {
  43.  
  44. }
  45.  
  46. #region buttons
  47.  
  48. private void Obliczdet_btt_Click(object sender, EventArgs e)
  49. {
  50. calc_det();
  51. }
  52.  
  53. private void imatrix_btt_Click(object sender, EventArgs e)
  54. {
  55.  
  56. calc_imatrix();
  57. }
  58.  
  59. private void transpo_btt_Click(object sender, EventArgs e)
  60. {
  61. transpo();
  62. }
  63.  
  64. #endregion
  65.  
  66. #region result boxes
  67. private void detwynik_TextChanged()
  68. {
  69. detwynik.Text = Convert.ToString(Math.Round(det,2));
  70. }
  71.  
  72. private void detwynik_TextChanged(object sender, EventArgs e)
  73. {
  74.  
  75. }
  76.  
  77. private void textBox10_TextChanged(object sender, EventArgs e)
  78. {
  79. //textbox wynik:
  80. }
  81. #region macierz wynikowa
  82.  
  83. private void W11_TextChanged()
  84. {
  85.  
  86. }
  87.  
  88. private void W12_TextChanged()
  89. {
  90.  
  91. }
  92.  
  93. private void W13_TextChanged()
  94. {
  95.  
  96. }
  97.  
  98. private void W21_TextChanged()
  99. {
  100.  
  101. }
  102.  
  103. private void W22_TextChanged()
  104. {
  105.  
  106. }
  107.  
  108. private void W23_TextChanged()
  109. {
  110.  
  111. }
  112.  
  113. private void W31_TextChanged()
  114. {
  115.  
  116. }
  117.  
  118. private void W32_TextChanged()
  119. {
  120.  
  121. }
  122.  
  123. private void W33_TextChanged()
  124. {
  125.  
  126. }
  127. #endregion
  128.  
  129. #endregion
  130.  
  131. #region calculations
  132.  
  133. private void calc_imatrix()
  134. {
  135. calc_det();
  136. if(det != 0)
  137. {
  138. o11 = (d22 * d33 - d32 * d23); o12 = (-(d12 * d33 - d31 * d23)); o13 = (d21 * d32 - d31 * d22);
  139. o21 = (-(d12 * d33 - d32 * d13)); o22 = (d11 * d33 - d31 * d13); o23 = (-(d11 * d32 - d31 * d12));
  140. o31 = (d12 * d23 - d22 * d13); o32 = (-(d11 * d23 - d21 * d13)); o33 = (d11 * d22 - d21 * d12);
  141.  
  142. t11 = o11 / det; t12 = o21 / det; t13 = o31 / det;
  143. t21 = o12 / det; t22 = o22 / det; t23 = o32 / det;
  144. t31 = o13 / det; t32 = o23 / det; t33 = o33 / det;
  145.  
  146. W11.Text = Convert.ToString(Math.Round(t11, 3)); W12.Text = Convert.ToString(Math.Round(t12, 3)); W13.Text = Convert.ToString(Math.Round(t13, 3));
  147. W21.Text = Convert.ToString(Math.Round(t21, 3)); W22.Text = Convert.ToString(Math.Round(t22, 3)); W23.Text = Convert.ToString(Math.Round(t23, 3));
  148. W31.Text = Convert.ToString(Math.Round(t31, 3)); W32.Text = Convert.ToString(Math.Round(t32, 3)); W33.Text = Convert.ToString(Math.Round(t33, 3));
  149.  
  150. }
  151. else
  152. {
  153. System.Windows.Forms.MessageBox.Show("Wyznacznik musi być różny od zera.");
  154. }
  155. }
  156.  
  157.  
  158. private void calc_det()
  159. {
  160. kon();
  161. det = (d11 * d22 * d33) + (d12 * d23 * d31) + (d13 * d21 * d32) - (d31 * d22 * d13) - (d32 * d23 * d11) - (d33 * d21 * d12);
  162. detwynik_TextChanged();
  163. }
  164.  
  165. private void transpo()
  166. {
  167. w11 = d11; w12 = d21; w13 = d31;
  168. w21 = d12; w22 = d22; w23 = d32;
  169. w31 = d13; w32 = d23; w33 = d33;
  170. // W11_TextChanged();W12_TextChanged();W13_TextChanged();W21_TextChanged();W22_TextChanged();W23_TextChanged();W31_TextChanged();W32_TextChanged();W33_TextChanged();
  171. W11.Text = Convert.ToString(w11); W21.Text = Convert.ToString(w21); W31.Text = Convert.ToString(w31);
  172. W12.Text = Convert.ToString(w12); W22.Text = Convert.ToString(w22); W32.Text = Convert.ToString(w32);
  173. W13.Text = Convert.ToString(w13); W23.Text = Convert.ToString(w23); W33.Text = Convert.ToString(w33);
  174. }
  175.  
  176. private void kon()
  177. {
  178. if (string.IsNullOrWhiteSpace(s11) || string.IsNullOrWhiteSpace(s12) || string.IsNullOrWhiteSpace(s13)
  179. || string.IsNullOrWhiteSpace(s21) || string.IsNullOrWhiteSpace(s22) || string.IsNullOrWhiteSpace(s23)
  180. || string.IsNullOrWhiteSpace(s31) || string.IsNullOrWhiteSpace(s32) || string.IsNullOrWhiteSpace(s33))
  181. {
  182. System.Windows.Forms.MessageBox.Show("Uzupełnij wszystkie pola macierzy!");
  183. }
  184. else
  185. {
  186. d11 = float.Parse(s11);
  187. d12 = float.Parse(s12);
  188. d13 = float.Parse(s13);
  189. d21 = float.Parse(s21);
  190. d22 = float.Parse(s22);
  191. d23 = float.Parse(s23);
  192. d31 = float.Parse(s31);
  193. d32 = float.Parse(s32);
  194. d33 = float.Parse(s33);
  195. }
  196. }
  197. #endregion
  198.  
  199. #region matrix 1
  200.  
  201. #region keypressy
  202.  
  203. private void D11_KeyPress(object sender, KeyPressEventArgs e)
  204. {
  205. if(char.IsNumber(e.KeyChar) || e.KeyChar=='.' || e.KeyChar == '-')
  206. {
  207. }
  208. else
  209. {
  210. e.Handled = e.KeyChar != (char)Keys.Back;
  211. }
  212. }
  213.  
  214. private void D12_KeyPress(object sender, KeyPressEventArgs e)
  215. {
  216. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  217. {
  218. }
  219. else
  220. {
  221. e.Handled = e.KeyChar != (char)Keys.Back;
  222. }
  223. }
  224.  
  225. private void D13_KeyPress(object sender, KeyPressEventArgs e)
  226. {
  227. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  228. {
  229. }
  230. else
  231. {
  232. e.Handled = e.KeyChar != (char)Keys.Back;
  233. }
  234. }
  235.  
  236. private void D21_KeyPress(object sender, KeyPressEventArgs e)
  237. {
  238. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  239. {
  240. }
  241. else
  242. {
  243. e.Handled = e.KeyChar != (char)Keys.Back;
  244. }
  245. }
  246.  
  247. private void D22_KeyPress(object sender, KeyPressEventArgs e)
  248. {
  249. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  250. {
  251. }
  252. else
  253. {
  254. e.Handled = e.KeyChar != (char)Keys.Back;
  255. }
  256. }
  257.  
  258. private void D23_KeyPress(object sender, KeyPressEventArgs e)
  259. {
  260. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  261. {
  262. }
  263. else
  264. {
  265. e.Handled = e.KeyChar != (char)Keys.Back;
  266. }
  267. }
  268.  
  269. private void D31_KeyPress(object sender, KeyPressEventArgs e)
  270. {
  271. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  272. {
  273. }
  274. else
  275. {
  276. e.Handled = e.KeyChar != (char)Keys.Back;
  277. }
  278. }
  279.  
  280. private void D32_KeyPress(object sender, KeyPressEventArgs e)
  281. {
  282. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  283. {
  284. }
  285. else
  286. {
  287. e.Handled = e.KeyChar != (char)Keys.Back;
  288. }
  289. }
  290.  
  291. private void D33_KeyPress(object sender, KeyPressEventArgs e)
  292. {
  293. if (char.IsNumber(e.KeyChar) || e.KeyChar == '.' || e.KeyChar == '-')
  294. {
  295. }
  296. else
  297. {
  298. e.Handled = e.KeyChar != (char)Keys.Back;
  299. }
  300. }
  301.  
  302. #endregion
  303. public void D11_TextChanged(object sender, EventArgs e)
  304. {
  305. TextBox objTextBox11 = (TextBox)sender;
  306. s11 = objTextBox11.Text;
  307. }
  308.  
  309. private void D12_TextChanged(object sender, EventArgs e)
  310. {
  311. TextBox objTextBox12 = (TextBox)sender;
  312. s12 = objTextBox12.Text;
  313. }
  314.  
  315. private void D13_TextChanged(object sender, EventArgs e)
  316. {
  317. TextBox objTextBox13 = (TextBox)sender;
  318. s13 = objTextBox13.Text;
  319. }
  320.  
  321. private void D21_TextChanged(object sender, EventArgs e)
  322. {
  323. TextBox objTextBox21 = (TextBox)sender;
  324. s21 = objTextBox21.Text;
  325. }
  326.  
  327. private void D22_TextChanged(object sender, EventArgs e)
  328. {
  329. TextBox objTextBox22 = (TextBox)sender;
  330. s22 = objTextBox22.Text;
  331. }
  332.  
  333. private void D23_TextChanged(object sender, EventArgs e)
  334. {
  335. TextBox objTextBox23 = (TextBox)sender;
  336. s23 = objTextBox23.Text;
  337. }
  338.  
  339. private void D31_TextChanged(object sender, EventArgs e)
  340. {
  341. TextBox objTextBox31 = (TextBox)sender;
  342. s31 = objTextBox31.Text;
  343. }
  344.  
  345. private void D32_TextChanged(object sender, EventArgs e)
  346. {
  347. TextBox objTextBox32 = (TextBox)sender;
  348. s32 = objTextBox32.Text;
  349. }
  350.  
  351. private void D33_TextChanged(object sender, EventArgs e)
  352. {
  353. TextBox objTextBox33 = (TextBox)sender;
  354. s33 = objTextBox33.Text;
  355. }
  356. #endregion
  357.  
  358. }
  359. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement