Diff equation for finite element method
5 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Mischa Kim
on 20 Apr 2014
Edited: Mischa Kim
on 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
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!