Difference between numerical and analytical solution of differential equation?

188 Views Asked by At

I am solving two differential equations numericaly, in Matlab, and analyticaly. But when I compare results, they are not the same, I cannot conclude why?

These are equations:

$$x_0' = \dfrac{-32 \beta}{R^4 x_0}$$ $$(x_0 x_1)' = - \dfrac{8}{R} x_0'$$ Also, I have next conditions: $$z=1: x_0 = 0, x_1 = 0$$ And $$x_0' = \dfrac{\mathrm{d}x_0}{\mathrm{d} z}, \quad R = R(z) = r_i-z(r_i-1)$$

When I solve it analyticaly, I got: $$x_0 = \sqrt{1+ \dfrac{64 \beta}{3(r_i-1)} \left( 1-\dfrac{1}{R^3} \right)}$$ $$x_1 = \dfrac{8}{R}\left( \dfrac{1}{x_0}-1 \right)$$

I am solving it numericaly in this way:

function [f, R] = fun_p(z, x, beta, ri)
R = ri - z .* (ri - 1);
f = zeros(2, size(x,2));
f(1,:) = - 32 .* beta ./ (R .^ 4 .* x(1,:));
f(2,:) = ( - 8 .* f(1,:) ./ R - f(1,:) .* x(2,:) ) ./ x(1,:);

I am calling fun_p from this file:

clear all;
clc;
options = odeset('RelTol',1.e-6, 'AbsTol',1.e-6);
Ree = 0.1;
Kne = 0.1;
eps = 0.01;
beta = 0.06;
z = linspace(1, 0, 1001);
ri = 0.7;
R = ri - z .* (ri - 1);
[~, pv] = ode45(@(z, x)fun_p(z, x, beta, ri), z, [1; 0], options);
x0 = pv(:, 1);
x1 = pv(:, 2);
x00 = ( 1 + 64 .* beta .* ( 1 - 1 ./ R .^ 3) ./ ( 3 .* (ri - 1))) .^ 0.5;
x11 = 8 .* ( 1 ./ x00 - 1 ) ./ R;
figure;
plot(z,x00);
hold on;
plot(z,x0, 'x');
hold on;
plot(z,x11);
hold on;
plot(z,x1, 'x');
hold on;
legend({'analytical', 'numerical', 'analytical', 'numerical'}, 'FontSize', 16, 'Interpreter', 'LaTeX');

When I compare results I get some difference for x1, I cannot conclude why: comparison of numerical and analytical x1

1

There are 1 best solutions below

0
On

numerical solutions are just aproximations.

The differences arise sometimes when there is non-linearity in the system.

I your case to it is sometimes useful when ucompare is to start the numerical solution from the point where the analytical solution crosses the y-axis.