Diff equation for finite element method

8 Ansichten (letzte 30 Tage)
samuel
samuel am 20 Apr. 2014
Beantwortet: samuel am 21 Apr. 2014
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

Antworten (2)

Mischa Kim
Mischa Kim am 20 Apr. 2014
Bearbeitet: Mischa Kim am 20 Apr. 2014
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 am 21 Apr. 2014
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.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by