% Define the source term f = @(x, y) sin(pi*x).*sin(pi*y);
% Compute the load vector F = zeros(nx+1, 1); for i = 1:nx+1 F(i) = f(i*k); end matlab codes for finite element analysis m files
% Apply boundary conditions K(1,:) = 0; K(1,1) = 1; K((nx+1)*(ny+1),:) = 0; K((nx+1)*(ny+1), (nx+1)*(ny+1)) = 1; % Define the source term f = @(x, y) sin(pi*x)
$$-\frac{d^2u}{dx^2} = f$$