(с программой на языке Паскаль) e-mail: bbi-math@narod.ru, site: http://bbi-math.narod.ru/
Двухстадийный метод Розенброка третьего порядка точности Метод применяется для решения систем уравнений, в которых правая часть не зависит от t, т.е. для систем вида:
Схема метода
J - якобиан, I - единичная матрица. Параметры схемы:
a2 = 1 - ||/ 6 /6 = 5.91751709536137e-1; w1 = -0.41315432; w2 = 1.41315432; b1 = c1 = ( - 6 - ||/ 6 + [58 + 20||/ 6 ]1/2 )/( 6 + 2||/ 6 ) = = 1.73786673924946e-1; Метод у нас записан немножко по другому, мы находим k1 и k2 решая системы уравнений [I - ha2 J(yn +c1k1)]k2 = h f ( yn + b1k1) Текст программы на языке Паскаль. Программа несколько корявая, но она работает, я облазил много сайтов, везде или метод криво изложен или в тексте программ ошибки(?), по крайней мере у меня эти программы не работали. Программа писалась под те задачи, которые у нас решаются, поэтому для произвольной системы уравнений может понадобиться некоторая переделка. Например, может понадобиться переписать процедуру jacob, у нас она работает только для {Semi-Implicit forms of Rosenbrock These are suitable for autonomous system of equations of the form dy/dt = f(y), y(t0)=y0 } {$n+}{directiva compilyatora dlya vychisleniy s dvoinoi tochnostyu} TYPE VTAB = array[1..5] of double; ATAB = array[1..5,1..5] of double; var y,ynext:vtab; a,jcb:atab; eps,eps1,h,x,xnext:double; buffer:double; i,j,k:integer; res:text;{TEXTOVYI FAIL, V KOTORYJ VYVODITSYA RESULTAT} {--------------------} procedure dy(var y,f:vtab); {PROCEDURA DLYA NAHOZHDENIYA dy/dt f[i] - proizvodnye dy[i]/dt, SJUDA VCTAVITE SVOI URAVNENIYA SLEDI ZA PEREDACHEI ZNACHENIJ ! ! } begin f[1]:=y[1]; f[2]:=y[2]; f[3]:=y[3]; f[4]:=y[4]; f[5]:=y[5]; end; {VNIMANIE! V PROTSEDURE JACOB Y[i] DOLZHNY BYT' POLOZHITELNY} procedure jacob(var y:vtab;var jcb:atab); {VNIMANIE! V PROTSEDURE JACOB Y[i] DOLZHNY BYT' POLOZHITELNY; PRI NEOBHODIMOSTI SAMI POPRAVITE} var x0,x1,delta:double; y0,y1,f0,f1:vtab; k:integer; begin delta:=1e-7; for k:=1 to 5 do begin y0[k]:=y[k]; y1[k]:=y[k]; end; y0[1]:=y0[1]*(1-delta); y1[1]:=y1[1]*(1+delta); dy(y0,f0); dy(y1,f1); jcb[1,1]:=(f1[1]-f0[1])/(2*delta*y[1]);{d_f1 po d_y1} jcb[2,1]:=(f1[2]-f0[2])/(2*delta*y[1]);{d_f2 po d_y1} jcb[3,1]:=(f1[3]-f0[3])/(2*delta*y[1]);{d_f3 po d_y1} jcb[4,1]:=(f1[4]-f0[4])/(2*delta*y[1]);{d_f4 po d_y1} jcb[5,1]:=(f1[5]-f0[5])/(2*delta*y[1]);{d_f5 po d_y1} y0[1]:=y[1];y1[1]:=y[1];{vozvraschaem znacheniya} y0[2]:=y0[2]*(1-delta); y1[2]:=y1[2]*(1+delta); dy(y0,f0); dy(y1,f1); jcb[1,2]:=(f1[1]-f0[1])/(2*delta*y[2]); {d_f1 po d_y2} jcb[2,2]:=(f1[2]-f0[2])/(2*delta*y[2]); {d_f2 po d_y2} jcb[3,2]:=(f1[3]-f0[3])/(2*delta*y[2]); {d_f3 po d_y2} jcb[4,2]:=(f1[4]-f0[4])/(2*delta*y[2]); {d_f4 po d_y2} jcb[5,2]:=(f1[5]-f0[5])/(2*delta*y[2]); {d_f5 po d_y2} y0[2]:=y[2];y1[2]:=y[2];{vozvraschaem znacheniya} y0[3]:=y0[3]*(1-delta); y1[3]:=y1[3]*(1+delta); dy(y0,f0); dy(y1,f1); jcb[1,3]:=(f1[1]-f0[1])/(2*delta*y[3]); {d_f1 po d_y3} jcb[2,3]:=(f1[2]-f0[2])/(2*delta*y[3]); {d_f2 po d_y3} jcb[3,3]:=(f1[3]-f0[3])/(2*delta*y[3]); {d_f3 po d_y3} jcb[4,3]:=(f1[4]-f0[4])/(2*delta*y[3]); {d_f4 po d_y3} jcb[5,3]:=(f1[5]-f0[5])/(2*delta*y[3]); {d_f5 po d_y3} y0[3]:=y[3];y1[3]:=y[3];{vozvraschaem znacheniya} y0[4]:=y0[4]*(1-delta); y1[4]:=y1[4]*(1+delta); dy(y0,f0); dy(y1,f1); jcb[1,4]:=(f1[1]-f0[1])/(2*delta*y[4]); {d_f1 po d_y4} jcb[2,4]:=(f1[2]-f0[2])/(2*delta*y[4]); {d_f2 po d_y4} jcb[3,4]:=(f1[3]-f0[3])/(2*delta*y[4]); {d_f3 po d_y4} jcb[4,4]:=(f1[4]-f0[4])/(2*delta*y[4]); {d_f4 po d_y4} jcb[5,4]:=(f1[5]-f0[5])/(2*delta*y[4]); {d_f5 po d_y4} y0[4]:=y[4];y1[4]:=y[4];{vozvraschaem znacheniya} y0[5]:=y0[5]*(1-delta); y1[5]:=y1[5]*(1+delta); dy(y0,f0); dy(y1,f1); jcb[1,5]:=(f1[1]-f0[1])/(2*delta*y[5]); {d_f1 po d_y5} jcb[2,5]:=(f1[2]-f0[2])/(2*delta*y[5]); {d_f2 po d_y5} jcb[3,5]:=(f1[3]-f0[3])/(2*delta*y[5]); {d_f3 po d_y5} jcb[4,5]:=(f1[4]-f0[4])/(2*delta*y[5]); {d_f4 po d_y5} jcb[5,5]:=(f1[5]-f0[5])/(2*delta*y[5]); {d_f5 po d_y5} end; procedure mult_a_v(var a:atab;var v,c:vtab); {protsedura umnozhaet matritsu A na vektor v rezultat - vektor c} begin for i:=1 to 5 do c[i]:=a[i,1]*v[1]+a[i,2]*v[2]+a[i,3]*v[3]+ a[i,4]*v[4]+a[i,5]*v[5]; end; {-------------------} function det5(var a:atab):double; {FUNKCIYA VYCHISLYAET OPREDELITEL MATRITSY 5-go PORYADKA a} begin det5:= +a[1,1]*a[2,2]*a[3,3]*a[4,4]*a[5,5]-a[1,2]*a[2,1]*a[3,3]*a[4,4]*a[5,5] +a[1,3]*a[2,1]*a[3,2]*a[4,4]*a[5,5]-a[1,1]*a[2,3]*a[3,2]*a[4,4]*a[5,5] -a[1,3]*a[2,2]*a[3,1]*a[4,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atab; i4,j4:integer; { d - stolbets pravyh chlenov sys - matritsa sistemy reshenie - vektor reshenie} begin { Zapominaem matritsu sistemy } for i4:=1 to 5 do for J4:=1 to 5 do sys1[i4,j4]:=sys[i4,j4]; {--- nahodim opredelitel' matritsy sistemy -------} detsys:=det5(sys); if detsys=0 then begin writeln(' DETERMINANT = ',detsys); writeln; writeln(' PRESSНемного теории можно посмотреть здесь: http://www.library.cornell.edu/nr/bookcpdf/c16-6.pdf http://www.ma.utexas.edu/documentation/nr/bookfpdf/f16-6.pdf краткое описание использованного мной метода лежит здесь: http://www.ualberta.ca/CMENG/courses/che674/handouts/chap6.pdf |