i want to solve that system using 4 order kutta method

1 次查看(过去 30 天)
this is my code
function dxdt = myderiv(t,x)
x1 = x(1);
x2 = x(2);
dx1dt = (-x1 + (0.097).*(1-x1)*exp(x2/(x2/20)+1));
dx2dt = (-x2 + 8.*(0.097).*(1-x1)*exp(x2/(x2/20)+1) - (0.3).*x2);
dxdt = [dx1dt;dx2dt];
end
and
f = @(t,x) myderiv(t,x)
h = 0.00001;
t = (0:h:1)';
t(1)=0;
x(:,1) = [0 ; 0] ;
for i=1:100000
K1 = f( t(i) , x(:,i) );
K2 = f( t(i) + h/2, x(:,i) + K1*h/2 );
K3 = f( t(i) + h/2, x(:,i) + K2*h/2 );
K4 = f( t(i) + h , x(:,i) + K3*h );
x(:,i+1) = x(:,i) + (h/6)*( K1 + 2*K2 + 2*K3 + K4 );
end
plot(t,x,'.b')
I need to see a graph result of system.

采纳的回答

Jan
Jan 2021-11-18
编辑:Jan 2021-11-18
The output is a simple point at [0, 0].
You start at 0. Then the expression x2/(x2/20) + 1 is NaN, because you divide by 0:
x2/(x2/20) + 1 =
20 * x2 / x2 + 1
All following points are NaN in consequence, so the trajectory is you initial value only.
Replace:
exp(x2 / (x2 / 20) + 1)
% by
exp(x2 / (x2 / 20 + 1))
Avoid using too many parentheses. Including scalar contants in parentheses is clutter. Spaces around operators are useful:
dx1dt = -x1 + 0.097 * (1 - x1) * exp(x2 / (x2 / 20 + 1));
dx2dt = -x2 + 8 * 0.097 * (1 - x1) * exp(x2 / (x2 / 20 + 1)) - 0.3 .* x2;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by