Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Numerical approximation of the solution

  1. Feb 24, 2010 #1
    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
     
  2. jcsd
  3. Feb 25, 2010 #2
    anyone can help?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook