Current location - Training Enrollment Network - Mathematics courses - Boss, help! How to do this matlab problem?
Boss, help! How to do this matlab problem?
Numerical solutions of ordinary differential equations. Predictor-corrector Euler method is used to solve the initial value problem.

Find out the values of all points with the step size of h=0. 1 and draw a graph.

The solution method adopts the predictor-corrector Euler method, as follows:

Step 1, according to the boundary value of y(0)= 1, the initial value is calculated by the broken line method, that is

The above formula (1) is also a prediction formula.

Step 2, according to the initial value, a more accurate value is obtained through trapezoidal calculation, namely

The above formula (2) is also a correction formula.

Here, yn- represents the approximate value of y(xn); H = x(I+ 1)-x(I)- represents the step size.

Step 3, calculate the value of y(x) when x is equal to 0, 0. 1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 respectively.

Fourthly, according to the values of x and y, the numerical solution curve of differential equation is drawn.

Solution process

Through calculation, the numerical solution of differential equation is obtained.

x =[0 0. 1 0.20 30.4 0.50.6 0.7 0.8 0.9 1.0]

y =[ 1 1.0959 1. 1.64 1.2662 1.3434 1.4 1.4860 1.5525 1.665438

According to these points, you can draw its graphics.

Matlab solution steps:

First, according to the iterative formula of predictor-corrector Euler method, write its function, such as Euler_Cauchy(func, x0, y0, xf, h).

Here, func- is the differential equation, x0 and y0- are the initial values of the differential equation, xf- is the final value of x, and HF- is the step size.

Step 2, write the differential equation function, namely

Function f=func(x, y); ?

f( 1)= y-2 * x/y;

f = f(:);

end

The third step is to write the main program, namely

y0 = 1; ? % initial value

x0 = 0; xf = 1; Range of %x

n = 10; Equal part percentage

H=(xf-x0)/n% step size

[t,x]=Euler_Cauchy(@func,x0,y0,xf,h); Euler method calculation of% prediction correction

Plot(x, y,' ks-')% Draw a function diagram.

Tu draws grid lines in the% coordinate area.

Xlabel('x'), ylabel('y(x)')% indicates the coordinate axis name.

Step 4: After running, you can get the following figure.

Graphical analysis of numerical solutions From the above figure, we can see that the order of higher accuracy of numerical solutions compared with exact solutions is:

Euler method → improved Euler method (prediction-correction Euler method) → Runge-Kutta method → analytical solution.

Numerical solution of ordinary differential equation

1, Euler method. Euler method (also called broken line method) is the earliest numerical method. Euler method is a numerical method for solving differential equations, which was invented by Swiss mathematician Euler. The basic idea of Euler method is to transform the differential equation into a difference equation, and then approximate the solution of the differential equation by iteratively solving the difference equation. It is a first-order numerical method for solving ordinary differential equations (initial value problems) with given initial values. It is the most basic explicit method to solve numerical ordinary differential equations.

The specific steps of Euler method are as follows:

Firstly, the differential equation is transformed into a difference equation, that is, the differential equation replaces the derivative of the history, and then the function value of the previous moment replaces the unknown function value of the history of the differential equation, and a recursive formula is obtained. Then, from the initial moment, the function values of each moment are calculated in turn according to the recursive formula until the required moment is reached. Finally, the calculated function value is taken as the approximate solution of the differential equation.

Euler method iteration

2. Predict and modify Euler method. Predictive correction Euler method is an improved method of Euler algorithm. The essential feature of differential equation is that it contains derivative term. The first step of numerical solution is to try to eliminate its derivative value, which is called discretization. The basic way to realize discretization is to approximate the derivative with the forward difference quotient, which is the basis of Euler algorithm.

In this method, the initial value of equation (1) is provided by the broken line method, which is called the prediction formula. Formula (2) gives a more accurate value by trapezoidal method, which is called a modified formula. Modified formula of combined forecasting.