Detailed explanation of Runge Kutta's calculation force
(1) Periodic deviations in the situation are:
Cyclong-Kutta Act has a high degree of height, earning 25947; stability (in certain conditions) can be improved in calculation process, without need to calculate high-level levels, but still needs to be calculated at a number of points, such as the four-cyclog-Kutta Act requires four calculations per time. This makes a certain complexity for the real calculation, and therefore more used to calculate the table.
II, subprocess
#include < stdio.h > < br/>#include < math.h > < br/>#define f(x,y) (-1*(x)*(y)*(y)))
void main(void)
{
double a,b,x0,y0,k1,k2,k3,k4,h;
br/>int n,i;< br/>printf(input a,b,x0,y0,n:);< br/>scanf(%lf%lf%lf%lf%d, & a, & b, & x0, & y0, & n);< br/>printf(x0 k1 k2 k3 k4
);< br/>for(h=(b-a)/n,i=0; i!= n; i++)
{
k1=f(x0.y0);< br/>k2=f(x0+h/2.y0+k1*h/2);< br/>k3=f(x0+h/2.y0+k2*h/2);< br/>k4=f(x0+h.y0+h*k3);<0+h br/>printf(%lf %lf ,x0.y0);< br/>printf(%lf %lf ,k1,k2);< br/>printf(%lf %lf
,k3,k4);< br/>y0+=h*(k1+2*k2+2*k3+k4)/6; < br/>x0+=h;<
}
printf(xn=%lf yn=%lf
.x0.y0);< br/>}
Operation Results:
input a,b,x0.y0, n:0 0 5 0 0 0 0 0 2 20 20 20 20 20 20 20 20 20 20 by br/br/ >...........................................................................................................................................................................599896 -1.279834 -1.295851 -1.292250
-1.222728
0.750000 1.279948 -1.228700 -1.110102 -1.139515
-0.990162
-1.000000 1.0027 -1.00000054 -0.5837 /-0.8995555837
-0.25005555556 - 0.7661515852 / / >1.250065555556-0.25005555556-0.76661552852 / / >1.2500652852/br / / >1.250065555555555555555556 1.750000 0.492374 -0.424257 -0.361915 -0.374868
-0.317855
-2.000000 0.400054 -0.320087 -0.275466 -0.284067
-0.243598
2.250000 0.329940 -0.244935 -0.212786 -0..21218538
-0.18994444482/br/br/ >-0.189444482
-0.2121858585383838 /...-0.21212185853838 /.......-0.212185858585383838 /..-0.18944br /..........-0.16666841414141-0.16668414141 -0.17000074444 min0.166668414141 -0.17020 -0.120024 -0.106973 -0.108868
-0.097048
3.250000 0.172989 -0.097256 -0.087300 -0.088657
-0.079618
3.500000 0.150956 -0.079757 -0.072054 -0.00773042minmin - 0.0007304242
-0.0055305
-0.0055305
-0.039833
-0.039833
4.500000 0.094123-0.039866 -0.036750 -0.037072
-0.034202
4.750000.084885-0.034226 -0.031675 -0.031926
-0.029571
n=5.000000 yn=0.076927

there is a derivation
it points out a misunderstanding of the building owner. Runge Kutta method is only a numerical solution, which can not be said to solve the equations. The numerical solution is only an approximate description of the analytical solution
function zd530003514
a=0.1; < br/>b=0.1;< br/>Y0 = [b-1; 0; 0 b; < br/>
%mole
[t,Y]= ode45(@ode,[0 10]; Y0);< br/>y1=Y(:.1);< br/>y2=Y(:.3);< br/>
%map
subplot 211
plot(t,y1);< br/>subplot 212
plot(t,y2);< br/>
%microwave definition
function dY = ode(t, Y)
L1=5;< br/>L2=0.01;< br/>a0=2;< br/>b0=2;< br/>c0=2;< br/>
y1=Y(1); y2=Y(3);< br/>dY = [
< Y(2);< br/> -(a0*y2+b0*y2^2+c0*y2^3) - L1^2*L2*y1 - L1^2*y1; < br/> < Y(4);< br/> -(a0*y2+b0*y2^2+c0*y2^3) - L1^2*L2*y1; < br/>;
K1=f(t,X);< br/>K2=f(t+h/2.X+h/2*K1);< br/>K3=f(t+h/2.X+h/2*K2);< br/>K4=f(t+h,X+h*K3);< br/>Y=X+h/6*(K1+2*K2+2*K3+K4);< br/>end
The code of the 4-cycle GUTA Act:
self-write communications, consisting of f.m
function dxdt = f (t,x)
dxdt(1)=exp(x(1)*sin(t)+x(2);< br/>dxdt(2)=exp(x(2)*cos(t)+x(1); % x(1) is your f, x(2) is your g
dxdt=dxdt(:);
End
itself gives t0.x0.h (initial time, initial value, steplength)
if the orbit requires 20 to t1: for example
t0=0; t1 is 5. h=0.02; x 0 is equal to negative 1. < br/>T=t0:h:t1; X=zero(length(x0),length(T)); X(:.1)=x0; < br/> for j=1:length(T)-1
> X(:,j+1)=RK45(T(j),X(:,j), @(t,x) f(t,x),h);
plot(T,X(1,:);< < br/>plot(T,X(2,:),' r'); < br/>specific parameters themselves
y'= y-2x/y
(0< x < 1)
y/br/>y(0)(0)=1
y(0)=1
y(0)=1
y(0)=1
y(0)=1
private
private
private
sub
form_click()
/>minmin //>
singlesingle,
single, <
y2
single,
y4
=
0.2
i
=
0
to
1
step
0.2
k1
=
f(x, <
=
f(x,
y1)
y2
=
y
+
h
<
2
*
k3
+
k4)
" < < < < br // >y
private
private
function
singlesingle single,
bb b
bb b
atat
atat at
<
-
2
*
a
/
b
end
function
define function,
F = func (x, y)
if y (1) & gt; 126,
f=[f1(y(1),y(2)), f2(y(1),y(2))];< br />else
f=[g1(y(1),y(2)), g2(y(1),y(2))];
end
then it's easy
