0 / 0 / 0
Регистрация: 23.12.2012
Сообщений: 5
|
|
1
|
Решение системы уравнений
03.06.2013, 21:03. Показов 3281. Ответов 0
Попытался из кусков кода собрать программу решающую систему уравнений (сам на jave не умею), то что получилось вроде исправно компилируется, но нифига запускается на эмуляторе. Помогите разобраться ну.
Java | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
| package com.example.gaus;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity implements View.OnClickListener {
EditText VT1; // окна ввода для коэффициентов
EditText VT2;
EditText VT3;
EditText VT4;
EditText VT5;
EditText VT6;
EditText VT7;
EditText VT8;
EditText VT9;
EditText WT1; //окна ввода для ответов в уравнениях
EditText WT2;
EditText WT3;
Button button1;
TextView result1;
TextView result2;
TextView result3;
double a1;
double a2;
double a3;
double b1;
double b2;
double b3;
double c1;
double c2;
double c3;
double h1;
double h2;
double h3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText1 = (EditText) findViewById(R.id.editText1);
a1 = Double.parseDouble(editText1.getText().toString());
WT1 = (EditText) findViewById(R.id.WT1);
h1 = Double.parseDouble(WT1.getText().toString());
WT2 = (EditText) findViewById(R.id.WT2);
h2 = Double.parseDouble(WT2.getText().toString());
WT3 = (EditText) findViewById(R.id.WT3);
h3 = Double.parseDouble(WT3.getText().toString());
editText2 = (EditText) findViewById(R.id. editText2);
a2 = Double.parseDouble(editText2.getText().toString());
VT3 = (EditText) findViewById(R.id. VT3);
a3 = Double.parseDouble(VT3.getText().toString());
VT4 = (EditText) findViewById(R.id.VT4);
b1 = Double.parseDouble(VT4.getText().toString());
VT5 = (EditText) findViewById(R.id.VT5);
b2 = Double.parseDouble(VT5.getText().toString());
VT6 = (EditText) findViewById(R.id.VT6);
b3 = Double.parseDouble(VT6.getText().toString());
VT7 = (EditText) findViewById(R.id.VT7 );
c1 = Double.parseDouble(VT7.getText().toString());
VT8 = (EditText) findViewById(R.id.VT8);
c2 = Double.parseDouble(VT8.getText().toString());
VT9 = (EditText) findViewById(R.id.VT9);
c3 = Double.parseDouble(VT9.getText().toString());
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public class Gauss {
public double[] gauss(double[][] a, double[] b) {
int n = a.length;
for (int row = 0; row < n; row++) {
int best = row;
for (int i = row + 1; i < n; i++)
if (Math.abs(a[best][row]) < Math.abs(a[i][row]))
best = i;
double[] tt = a[row];
a[row] = a[best];
a[best] = tt;
double t = b[row];
b[row] = b[best];
b[best] = t;
for (int i = row + 1; i < n; i++)
a[row][i] /= a[row][row];
b[row] /= a[row][row];
for (int i = 0; i < n; i++) {
double x = a[i][row];
if (i != row && x != 0) {
for (int j = row + 1; j < n; j++)
a[i][j] -= a[row][j] * x;
b[i] -= b[row] * x;
}
}
}
return b;
}
public void onClick(View v) {
// Usage example
public void main (String[] args) {
double[][] a = { { a1, a2, a3 }, { b1, b2, b3 }, { c1, c2, c3 } };
double[] b = { h1, h3, h3 };
double[][] a1 = a.clone();
for (int i = 0; i < a.length; i++)
a1[i] = a[i].clone();
double[] b1 = b.clone();
double[] x = gauss(a, b);
for (int i = 0; i < a.length; i++) {
double y = 0;
for (int j = 0; j < a[i].length; j++)
y += a1[i][j] * x[j];
if (Math.abs(b1[i] - y) > 1e-9) {
System.err.println("error");
return;
}
}
}
}
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
} |
|
0
|