- 142

- 0

For a project we need to do some simulations in matlab. The preliminary part requires us to solve a system of differential equations with initial values given. The system is

[tex]dx_1 = 2x_2[/tex]

[tex] dx_2 = -2x_1[/tex]

[tex] dx_3 = 200x_4[/tex]

[tex]dx_4 = -200x_3[/tex]

[tex]x(0) = [1, 0, 1, 0][/tex]

My MATLAB code is this:

function part1

options = odeset('RelTol',1e-3,'AbsTol',[1e-3 1e-3 1e-3 1e-3]);

[T,Y] = ode45(@prelim,[0:1:10],[1 0 1 0],options);

[T,Y]

function dx = prelim(t,x)

dx = zeros(4,1); % a column vector

dx(1) = 2*x(2);

dx(2) = -2*x(1);

dx(3) = 200*x(4);

dx(4) = -200*x(3);

end

end

My result is this:

ans =

ans =

0 1.0000 0 1.0000 0

1.0000 -0.4161 -0.9093 0.5098 0.8533

2.0000 -0.6536 0.7568 -0.4680 0.8700

3.0000 0.9602 0.2794 -0.9808 0.0445

4.0000 -0.1455 -0.9894 -0.5387 -0.8140

5.0000 -0.8391 0.5440 0.4193 -0.8749

6.0000 0.8439 0.5366 0.9601 -0.0893

7.0000 0.1367 -0.9906 0.5664 0.7728

8.0000 -0.9577 0.2879 -0.3695 0.8780

9.0000 0.6603 0.7510 -0.9373 0.1339

10.0000 0.4081 -0.9129 -0.5932 -0.7303

To see if this is correct I need to solve the system analytically as well. I've searched the web, but I can't seem to find any good info on how to solve a system of ODE's with initial conditions. I've taken linear algebra, and I'm guessing I have to find the eigenvalues of matrix of coefficients, but I'm not sure what I'd do from there. Could anyone step me through the process, or refer me to a good online resource? Thanks in advance.

[tex]dx_1 = 2x_2[/tex]

[tex] dx_2 = -2x_1[/tex]

[tex] dx_3 = 200x_4[/tex]

[tex]dx_4 = -200x_3[/tex]

[tex]x(0) = [1, 0, 1, 0][/tex]

My MATLAB code is this:

function part1

options = odeset('RelTol',1e-3,'AbsTol',[1e-3 1e-3 1e-3 1e-3]);

[T,Y] = ode45(@prelim,[0:1:10],[1 0 1 0],options);

[T,Y]

function dx = prelim(t,x)

dx = zeros(4,1); % a column vector

dx(1) = 2*x(2);

dx(2) = -2*x(1);

dx(3) = 200*x(4);

dx(4) = -200*x(3);

end

end

My result is this:

ans =

ans =

0 1.0000 0 1.0000 0

1.0000 -0.4161 -0.9093 0.5098 0.8533

2.0000 -0.6536 0.7568 -0.4680 0.8700

3.0000 0.9602 0.2794 -0.9808 0.0445

4.0000 -0.1455 -0.9894 -0.5387 -0.8140

5.0000 -0.8391 0.5440 0.4193 -0.8749

6.0000 0.8439 0.5366 0.9601 -0.0893

7.0000 0.1367 -0.9906 0.5664 0.7728

8.0000 -0.9577 0.2879 -0.3695 0.8780

9.0000 0.6603 0.7510 -0.9373 0.1339

10.0000 0.4081 -0.9129 -0.5932 -0.7303

To see if this is correct I need to solve the system analytically as well. I've searched the web, but I can't seem to find any good info on how to solve a system of ODE's with initial conditions. I've taken linear algebra, and I'm guessing I have to find the eigenvalues of matrix of coefficients, but I'm not sure what I'd do from there. Could anyone step me through the process, or refer me to a good online resource? Thanks in advance.

Last edited: