2nd order ode using euler method
์กฐํ ์: 6 (์ต๊ทผ 30์ผ)
์ด์ ๋๊ธ ํ์
MD RESHAD UL HOQUE
2018๋
11์ 25์ผ
The following second-order ODE is considered to be stiff: d2y/dx2=โ1001dy/dxโ1000?
initial conditions are: y(0)=1 and ?โฒ(0)=0
What to solve the ODE using Eulerโs method with implicit function.
I implemetd the above question using matlab. But implemented code gives this error.
![euler.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/196619/euler.png)
I attached the code. Can anyone suggest me about the bug of this code?.
function dy = dpnon(t, y)
dy = [y(2);-1000*y(1)-1001*y(2)];
end
function [x,y]=euler_explicit(f,xinit,yinit,xfinal,h)
n=(xfinal-xinit)/h;
% Initialization of x and y as column vectors
x=[xinit zeros(1,n)]; y=[yinit zeros(1,n)];
% Calculation of x and y
for i=1:n
x(i+1)=x(i)+h;
y(i+1)=y(i)+h*f(x(i),y(i));
end
end
xinit=0;
xfinal=3;
yinit=0;
h=.5;
euler_explicit(@dpnon,xinit,yinit,xfinal,h)
๋๊ธ ์: 0
์ฑํ๋ ๋ต๋ณ
Torsten
2018๋
11์ 26์ผ
ํธ์ง: Torsten
2018๋
11์ 27์ผ
function main
xinit = 0;
xfinal = 3;
yinit = [1 0];
h = .5;
[x,y] = euler_explicit(@dpnon,xinit,yinit,xfinal,h)
plot(x,y(:,1))
end
function [x,y]=euler_explicit(f,xinit,yinit,xfinal,h)
n = (xfinal-xinit)/h;
% Initialization of x and y as column vectors
x = [xinit;zeros(n,1)];
y = [yinit;zeros(n,2)];
% Calculation of x and y
for i = 1:n
x(i+1) = x(i) + h;
y(i+1,:) = y(i,:) + h*f(x(i),y(i,:));
end
end
function dy = dpnon(t, y)
dy = [y(2),-1000*y(1)-1001*y(2)];
end
๋๊ธ ์: 0
์ถ๊ฐ ๋ต๋ณ (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!