h=0.05; % step size
syms x1 y0 y1 y2 % declaring symbolic variables
dy = (y2-y1)/h; % defining first derivative
d2y= (y2-2*y1-y0)/(h^2); % defining second derivative
f=d2y== -4*x1*dy+(2/(x1^2))*(y1-log(x1)); % defining BVP
% initializing
x=1:h:2;
n=length(x);
y_a=1340; % boundary values
y_b=124;
A=[1 zeros(1,n-1)]; % inserting the first row  Â
b=[y_a]; % inserting initial value Â
for i=2:n-1Â Â
[p q]=equationsToMatrix(subs(f,x1,x(i))); % substituting x_i in BVP
p=[zeros(1,i-2) p zeros(1,n-i-1)]; % zero padding to match matrix size
A=[A;p]; % appending
b=[b;q]; Â Â
end
A=[A; zeros(1,n-1) 1];% inserting the last row
b=[b;y_b]; % inserting final value Â
Y=A\b;
index=uint8(1+(1.35-1)/h); % finding index for y(1.35)
vpa(Y(index),9) % value of y(1.35)
Comments
Leave a comment