PDA

View Full Version : numerical approximation of the solution


splelvis
Feb24-10, 07:09 PM
u''(x)=f(x),
boundary conditions u(a)=0,u(b)=0.
(u(x+h)-2u(x)+u(x-h))/h^2=f(x);

maltab code:

clear all
a=0;
b=1;
n=10;
h=(b-a)/(n+1);
x_with_boundary=linspace(a,b,n+2)';
x=x_with_boundary(2:n+1);
A=h^(-2).*(diag(ones(1,n-1),-1)+diag(-2.*ones(1,n),0)+diag(ones(1,n-1),1));
rhs=f4(x);
sol=A\rhs;
sol_with_boundary_conds=[0;sol;0];
plot(x_with_boundary,sol_with_boundary_conds);


open a new document,f4,
function y=f4(x)
y=ones(length(x),1);

parabola comes out.



now the question is ,

u''(x)=sin(2pix);
u(-1)=0;
u(1)=0;
interval[-1;1]

,how to change the matlab code to become u''=sin(2pix)?
thanks in advance

splelvis
Feb25-10, 02:00 PM
anyone can help?