Diff equation for finite element method

조회 수: 8 (최근 30일)
samuel
samuel 2014년 4월 20일
답변: samuel 2014년 4월 21일
Hi all,
please could someone help me with this problem. I have to solve this diff equation y''= -6x+2 , x belongs to interval (0,2) and y(0)=y(2)=0
I tried to use dsolve
if true
x={0,2}
eqn2='D2y=-6(x)+2'
inits2='y(0)=0,y(2)=0'
y=dsolve(eqn2,inits2,'x')
end
but this does't work. And also tried to use ode45 function but i think this equation can't be solved by ode45 function. Could someone give me a hint how to do it, or better, example of code how to achieve solution. Many thanks
Sam

답변 (2개)

Mischa Kim
Mischa Kim 2014년 4월 20일
편집: Mischa Kim 2014년 4월 20일
Sam, use a bvp solver
function pdetest()
solinit = bvpinit(linspace(0,2,5),[0 0]);
sol = bvp4c(@mypde,@mybc,solinit);
x = linspace(0,2);
y = deval(sol,x);
plot(x,y(1,:));
end
function dydx = mypde(x,y)
dydx = [y(2); -6*x + 2];
end
function res = mybc(ya,yb)
res = [ya(1); yb(1)];
end

samuel
samuel 2014년 4월 21일
Hi Kim,
thanks a lot for your answer, sorry for long feedback, but this result is not suitable for me because i need result as an function, f.e. result of this equation should be
u(x)=x^2-x^3
and original qeuation is: -3y''=18x-6 U(x)=-2x this is how we can achieve this result (from my school book): because right side of diff eq is polynom of 1st degree so left side of diff eq is y(x) is polynom of 3rd degree -> y(x)=A + Bx + Cx^2 + Dx^3. So we'll solve coeficients A,B,C,D easily. If y(0)=0 then A=0, and when we appoint to diff eq left boundary point x=0 from interval (0,2) we get -3y''(0)= -6 -> -3*2C = -6, and from there C=1. When we appoint to diff eq right boundary point from interval (0,2) x=2 we get -3y''(2)=18*2-6 -> -3(2C+6D*2)=30, and from this we get D= -1. In the end we use condition 0=y(2)=A+B2+C*x^2+D^3, and from this we get B=2. And finally we get y(x)=2x+x^2+x^3. Soo final solution is u=U+y so
u(x)= -2x+[2x+x^2+x^3]=x^2+x^3
and this shoud be my output.
Pls Kim could you you help me how can I get this solution, because i am totally desperate
And this is solution for first element of finite element method.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by