u''(x)=f(x),(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Numerical approximation of the solution

Loading...

Similar Threads - Numerical approximation solution | Date |
---|---|

Matlab Parameter fitting with a numerical solution | Feb 9, 2018 |

CAS and Numerical Computing | Mar 24, 2017 |

I don't get a reasonable output for my code? | Mar 18, 2017 |

Mathematica Numerically solve recurrence relation | Mar 12, 2017 |

Numerical boundary conditions for wide approximation finite difference | Jan 21, 2014 |

**Physics Forums - The Fusion of Science and Community**