Diff equation for finite element method
8 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!