Self-Consistent Method (I)

For intial value problems, the physical quantities as a function of time can be obtained by the iteration, when the differential equations are transformed based on the finite difference. For boundary value problems, we usually did not have the first-order derivative, while the value at the boundary is given instead. In such a case, we can use the shooting method to find the proper value of the first-order derivative, further solving the problem.

(1) Shooting method

Taking the  thrown up object as an example, the acceleration is g=9.8 m/s^2. Suppose s(t=0)=0 and s(t=5s)=40. What will v(t=0) be? We can use the function below.

function y=shootfun(a)
g=9.8;dt=0.2;
t(1)=0;v(1)=a;s(1)=0;
for j=2:round(5/dt);
    s(j)=s(j-1)+v(j-1)*dt;
    v(j)=v(j-1)-g*dt;
    t(j)=t(j-1)+dt;
end
y=s(end);

Given the initial velocity v(1)=a, we can obtain the displacement at t=5s, which the returned value y. Then, we can try the possible initial velocities and pick up the right one for s(t=5s)=40.  

(2)  Solution of Equation

As shown above, the shooting method is the way of using iteration for initial value problem to solve boundary value problem. Well, it might be fussy. In addition, it is hard to be extended for two-dimensional cases. The   Self-Consistent Method will be more feasible. Here we use the example of solving equation to show how it works.

 Transforming the equation into series, we can obtain every x(k+1) from x(k). As the iteration goes, the difference between  x(k+1) and x(k) will converge to zero. Here the criterion is set as delta <= 0.001, after which the loop will break and the root of equation is obtained.

clear
x(1)=1.5;delta=1;i=1;
while delta>0.001&i<100
    x(i+1)=(x(i)+1)^(1/3);
    delta=abs(x(i+1)-x(i));
    i=i+1;
end

(3) Self-Consistent Method 

 

As the equation with boundary values shown, the solution of this equation is y=x. To solve it numerically, we should use the finite difference for second-order derivative. As the code shown below, we use an array of 1x11 to represent the solution y. According to the boundary values, y(1)=-1 and y(end)=1. With the finite difference, we can obtain a new array of y2 from y(line 8). delta is the difference between these two arrays(line 10), where abs is to get absolute value and sum is to sum up all the components of array.

clear
y=zeros(1,11);
y(1)=-1;y(end)=1;
delta=1;j=1;
while delta>0.01&j<1000
    y2=y;
for i=2:length(y)-1
    y2(i)=0.5*(y(i-1)+y(i+1));
end
delta=sum(abs(y-y2));
y=y2;
j=j+1;
end

  

猜你喜欢

转载自www.cnblogs.com/xbyang99/p/11746763.html
I
今日推荐