|
|
|
| Пожалуйста выкладывайте скрипты на любом языке программирования. Очень надо. | |
|
|
|
|
|
|
|
для: ZC
(02.03.2006 в 18:03)
| | Можно напомнить что такое линейное уравнение? | |
|
|
|
|
|
|
|
для: codexomega
(02.03.2006 в 19:05)
| |
ЛИНЕЙНОЕ УРАВНЕНИЕ - алгебраическое уравнение, в которое неизвестные входят в 1-й степени и отсутствуют члены, содержащие произведения неизвестных. Линейное уравнение с одним неизвестным имеет вид: ax?b. В случае нескольких неизвестных имеют дело с системами линейных уравнений. Теория линейных уравнений получила развитие после возникновения учения об определителях и матриц. Понятие линейности переносится с алгебраических уравнений на уравнения из других областей математики (напр., линейное дифференциальное уравнение - это дифференциальное уравнение, в которое неизвестная функция и ее производные входят линейно, т. е. в 1-й степени).
|
| |
|
|
|
|
|
|
|
для: ZC
(02.03.2006 в 18:03)
| | Решение по методу Гаусса-Жордана на FORTRAN, например,
SUBROUTINE gaussj(a,n,np,b,m,mp)
INTEGER m,mp,n,np,NMAX
REAL a(np,np),b(np,mp)
PARAMETER (NMAX=50)
INTEGER i,icol,irow,j,k,l,ll,indxc(NMAX),indxr(NMAX),ipiv(NMAX)
REAL big,dum,pivinv
do 11 j=1,n
ipiv(j)=0
11 continue
do 22 i=1,n
big=0.
do 13 j=1,n
if(ipiv(j).ne.1)then
do 12 k=1,n
if (ipiv(k).eq.0) then
if (abs(a(j,k)).ge.big)then
big=abs(a(j,k))
irow=j
icol=k
endif
else if (ipiv(k).gt.1) then
pause 'singular matrix in gaussj'
endif
12 continue
endif
13 continue
ipiv(icol)=ipiv(icol)+1
if (irow.ne.icol) then
do 14 l=1,n
dum=a(irow,l)
a(irow,l)=a(icol,l)
a(icol,l)=dum
14 continue
do 15 l=1,m
dum=b(irow,l)
b(irow,l)=b(icol,l)
b(icol,l)=dum
15 continue
endif
indxr(i)=irow
indxc(i)=icol
if (a(icol,icol).eq.0.) pause 'singular matrix in gaussj'
pivinv=1./a(icol,icol)
a(icol,icol)=1.
do 16 l=1,n
a(icol,l)=a(icol,l)*pivinv
16 continue
do 17 l=1,m
b(icol,l)=b(icol,l)*pivinv
17 continue
do 21 ll=1,n
if(ll.ne.icol)then
dum=a(ll,icol)
a(ll,icol)=0.
do 18 l=1,n
a(ll,l)=a(ll,l)-a(icol,l)*dum
18 continue
do 19 l=1,m
b(ll,l)=b(ll,l)-b(icol,l)*dum
19 continue
endif
21 continue
22 continue
do 24 l=n,1,-1
if(indxr(l).ne.indxc(l))then
do 23 k=1,n
dum=a(k,indxr(l))
a(k,indxr(l))=a(k,indxc(l))
a(k,indxc(l))=dum
23 continue
endif
24 continue
return
END
|
| |
|
|
|
|
|
|
|
для: cheops
(02.03.2006 в 21:56)
| | Паскаль, бисекция, заданная точность (необязательно линейное, но требует задания границ поиска решения):
program equiv;
uses crt;
var
a, a1, b, mid, et, st: real;
i: word;
function f(x: real): real;
begin
f:= 1/(1.2* sin(x)/cos(x) + sqrt(x+1) - x); // собственно, уравнение
end;
procedure main(e: real);
begin
while not ( (b-a) < e ) do
begin
mid:=(a+b)/2;
if (f(a)*f(b))>0 then
begin
writeln('No roots!');
readkey;
halt;
end;
if (f(a)*f(mid))>0 then a:=mid else b:=mid;
end;
mid:=(a+b)/2;
writeln('Answer: ', mid);
end;
begin
clrscr;
writeln;
writeln;
writeln(' Welcome to MathCad v. 0.0.0001 alpha!');
writeln;
writeln('Enter an interval:');
write(' from: '); read(a);
write(' to: '); read(b);
if a>b then begin a1:=a; a:=b; b:=a1; end;
writeln;
writeln;
write('And now, enter the 1st ethalon: '); readln(et);
write('and how much times the next ethalon will be smaller than previous one: '); readln(st);
writeln;
writeln('OK. Pressing ENTER will start 5 calculations with different ethalons.');
writeln;
readln;
for i:=1 to 5 do
begin
main(et);
et:=et*st;
end;
writeln;
readln;
clrscr;
writeln;
writeln(' That's all.');
writeln;
writeln(' Press any key to exit this program.');
readkey;
end.
|
| |
|
|
|
|
|
|
|
для: ZC
(02.03.2006 в 18:03)
| | Что-то на Яваскрипте
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<meta NAME="description"
CONTENT="Java Script Linear Algebra utilizes Java Script to perform solving a system of equations.">
<meta NAME="keywords"
CONTENT="java script linear algebra math mathematics system equations matrix matrices">
<meta name="language" CONTENT="en-us">
<title>Java Script Linear Algebra</title>
<script language="JavaScript">
<!--
function initArray() {
this.length = initArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i]
}
function solve (m) {
var a1 = new initArray(parseFloat(document.matrix.a11.value, 10), parseFloat(document.matrix.a12.value, 10), parseFloat(document.matrix.a13.value, 10), parseFloat(document.matrix.a14.value, 10))
var a2 = new initArray(parseFloat(document.matrix.a21.value, 10), parseFloat(document.matrix.a22.value, 10), parseFloat(document.matrix.a23.value, 10), parseFloat(document.matrix.a24.value, 10))
var a3 = new initArray(parseFloat(document.matrix.a31.value, 10), parseFloat(document.matrix.a32.value, 10), parseFloat(document.matrix.a33.value, 10), parseFloat(document.matrix.a34.value, 10))
var t1 = a1
var t2 = a2
var t3 = a3
// First we need a one in the first spot
if (a1[1] == 0) { alert("\rThere is a 0 in the first entry of the Matrix you entered\r\rI can't handle that at this time\r\rPlease Re-Enter the Matrix\r ") }
if (a1[1] != 0) {
var temp = a1[1]
for (var i=1; i<=4; i++)
{ a1[i] = a1[i] / temp }
}
// Now we should have a 1 in the first entry - Now to zero out the column
var temp = -a2[1]
for ( var i=1; i<=4; i++ ) {
a2[i] = a2[i] + (a1[i] * temp) }
var temp = -a3[1]
for ( var i=1; i<=4; i++ ) {
a3[i] = a3[i] + (a1[i] * temp) }
// Next Column Check if 0 - if not put a 1 there
if (a2[2] == 0 ) { // if = to 0 switch rows
for (var i=2; i<=4; i++) {
var temp = a2[i]
a2[i] = a3[i]
a3[i] = temp }
}
if (a2[2] != 0 ) {
var temp = a2[2]
a2[2] = a2[2] / temp // for statement would have taken longer
a2[3] = a2[3] / temp
a2[4] = a2[4] / temp
// zero out column below
var temp = -a3[2]
for ( var i=2; i<=4; i++ ) {
a3[i] = a3[i] + (a2[i] * temp) }
// zero out column above
var temp = -a1[2]
for ( var i=2; i<=4; i++ ) {
a1[i] = a1[i] + (a2[i] * temp) }
} // ends if != 0
// Final Column
if (a3[3] != 0 ) {
var temp = a3[3]
a3[3] = a3[3] / temp // for statement would have taken longer
a3[4] = a3[4] / temp
// zero out column above
var temp = -a2[3]
a2[3] = a2[3] + (a3[3] * temp)
a2[4] = a2[4] + (a3[4] * temp)
var temp = -a1[3]
a1[3] = a1[3] + (a3[3] * temp)
a1[4] = a1[4] + (a3[4] * temp)
}
// ALWAYS CHECK YOUR WORK
if (t1[1] * a1[4] + t1[2] * a2[4] + t1[3]*a3[4] != t1[4] )
{ alert("\rThe Solution I found does not check out\r\rYou may have entered a system of equations which\r have no solution, or infinite solutions.") }
if (t2[1] * a1[4] + t2[2] * a2[4] + t2[3]*a3[4] != t2[4] )
{ alert("\rThe Solution I found does not check out\r\rYou may have entered a system of equations which\r have no solution, or infinite solutions.") }
if (t3[1] * a1[4] + t3[2] * a2[4] + t3[3]*a3[4] != t3[4] )
{ alert("\rThe Solution I found does not check out\r\rYou may have entered a system of equations which\r have no solution, or infinite solutions.") }
m.x1.value=a1[4]
m.x2.value=a2[4]
m.x3.value=a3[4]
}
//-->
</script>
</head>
<body bgcolor="#C0C0C0">
<p align="CENTER"><font size="5" color="#445071">Java Script Linear Algebra III</font><br />
<blockquote>
<p>Solve a System of Linear Equations </p>
<form name="matrix">
<p><b>Enter your Augmented Matrix to be solved: </b></p>
<table cellspacing="8">
<tr>
<td valign="TOP"><table>
<tr>
<th>x<sub>1</sub></th>
<th>x<sub>2</sub></th>
<th>x<sub>3</sub></th>
<th>Aug.</th>
</tr>
<tr>
<td><br />
</td>
</tr>
<tr>
<td><input type="text" name="a11" size="5"></td>
<td><input type="text" name="a12" size="5"></td>
<td><input type="text" name="a13" size="5"></td>
<td><b>:</b> <input type="text" name="a14" size="5"></td>
</tr>
<tr>
<td><br />
</td>
</tr>
<tr>
<td><input type="text" name="a21" size="5"></td>
<td><input type="text" name="a22" size="5"></td>
<td><input type="text" name="a23" size="5"></td>
<td><b>:</b> <input type="test" name="a24" size="5"></td>
</tr>
<tr>
<td><br />
</td>
</tr>
<tr>
<td><input type="text" name="a31" size="5"></td>
<td><input type="text" name="a32" size="5"></td>
<td><input type="text" name="a33" size="5"></td>
<td><b>:</b> <input type="text" name="a34" size="5"></td>
</tr>
</table>
</td>
<td> </td>
<td valign="BOTTOM" rowspan="2"><table cellspacing="4" cellpadding="4">
<tr>
<td align="LEFT" valign="RIGHT"> <input TYPE="button"
VALUE="Solve" SIZE="10" onClick="solve(matrix)"> </td>
</tr>
<tr>
<td align="CENTER">x1 = <input type="text" name="x1" size="10"></td>
</tr>
<tr>
<td align="CENTER">x2 = <input type="text" name="x2" size="10"></td>
</tr>
<tr>
<td align="CENTER">x3 = <input type="text" name="x3" size="10"></td>
</tr>
</table>
</td>
</tr>
<tr>
<td></td>
<td> </td>
</tr>
</table>
<p><input type="reset" value="Reset"></p>
</form>
</blockquote>
<p> </p>
</body>
</html>
|
| |
|
|
|
|
|
|
|
для: ZC
(02.03.2006 в 18:03)
| | Спасибо. А есть варианты на C++. Если код паскаля засунуть в Delphi, что-нить выйдет? | |
|
|
|
|
|
|
|
для: ZC
(03.03.2006 в 17:33)
| | >Если код паскаля засунуть в
>Delphi, что-нить выйдет?
Не знаю, с Дельфями не дружу, к сожалению. Хотя вроде проблем быть не должно - ввод/вывод поменять, думаю, недолго. | |
|
|
|
|