Graphics Programs Reference
In-Depth Information
second-orderboundary value problems. The subfunction residual(y) returns
the residuals of the finite difference equations, which are the left-hand sides of
Eqs. (8.11). The differentialequation y =
y ) is definedinthe subfunction
y2Prime . In this problemwe chose for the initial solution y i
f ( x
,
y
,
5 x i , which cor-
responds to the dashed straight line shown in the rough plot of y in Example 8.1.
Note that we relaxed the convergence criterioninthe Newton-Raphsonmethod to
1
=
0
.
10 5 , which is more in line with the truncation errorinthe finite difference
method.
.
0
×
function fDiff7
% Finite difference method for the second-order,
% nonlinear boundary value problem in Example 8.7.
globalNHX %Maketheseparams.global.
xStart = 0; xStop = 2; % Range of integration.
N=11; %Numberofmeshpoints.
freq = 1; % Printout frequency.
X = linspace(xStart,xStop,N)';
y = 0.5*X;
% Starting values of y.
H = (xStop - xStart)/(N-1);
y = newtonRaphson2(@residual,y,1.0e-5);
printSol(X,y,freq)
functionr=residual(y);
% Residuals of finite difference equations (left-hand
% sides of Eqs (8.11)).
globalNHX
r = zeros(N,1);
r(1) = y(1); r(N) = y(N) - 1;
fori=2:N-1
r(i) = y(i-1) - 2*y(i) + y(i+1)...
- H*H*y2Prime(X(i),y(i),(y(i+1) - y(i-1))/(2*H));
end
functionF=y2Prime(x,y,yPrime)
%Second-orderdifferentialequationF=y''.
F = -3*y*yPrime;
Search WWH ::




Custom Search