ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ
ํ•„ํ„ฐ ์ง€์šฐ๊ธฐ

Euler's Method

์กฐํšŒ ์ˆ˜: 3 (์ตœ๊ทผ 30์ผ)
Ahmet Akcura
Ahmet Akcura 2021๋…„ 8์›” 21์ผ
ํŽธ์ง‘: Wan Ji 2021๋…„ 8์›” 23์ผ
Hello,
๐‘‘๐‘ฆ/๐‘‘๐‘ฅ = ๐‘ฅ^-2 (๐‘†๐‘–๐‘›2๐‘ฅโˆ’2๐‘ฅ๐‘ฆ), ๐‘ฆ(1)=2
I need to write code to calculate the values of y(x) when 1โ‰ค๐‘ฅโ‰ค2 and h=0.25 by using Euler's Method.
But I couldn't take the integral of dy/dx which I will use for my code. To solve integral, I used integration by parts but the answer didn't come. I dont know can I write directly in Matlab code or not. Can you please help me? I really need help.

๋‹ต๋ณ€ (1๊ฐœ)

Wan Ji
Wan Ji 2021๋…„ 8์›” 22์ผ
ํŽธ์ง‘: Wan Ji 2021๋…„ 8์›” 23์ผ
Euler forward?
clc;clear
odefun = @(x,y) x^(-2) *(sin(2*x)-2*x*y); % I have rewritten the ode function
xspan = [1,2];
x0 = xspan(1);
y0 = 2;
h = 0.25;
nstep = diff(xspan)/h;
obj = ode(odefun, x0, y0);
a = obj.forwardEuler(h, nstep);
plot(a.t, a.y)
xlabel('x'); ylabel('y')
the ode class
classdef ode
properties
odefun
t0
y0
t
y
end
methods
function obj = ode(odefun, t0, y0)
obj.odefun = odefun;
obj.t0 = t0;
obj.y0 = y0;
end
function obj = forwardEuler(obj, dt, nstep)
obj.t = obj.t0 + (0:nstep)*dt;
obj.y = zeros(numel(obj.y0), numel(obj.t));
obj.y(:,1) = obj.y0;
for i = 1:1:nstep
obj.y(:,i+1) = obj.y(:,i) + dt*obj.odefun(obj.t(i),obj.y(:,i));
end
end
end
end
  ๋Œ“๊ธ€ ์ˆ˜: 2
John D'Errico
John D'Errico 2021๋…„ 8์›” 23์ผ
Please don't do student;s homework assignments for them. This does not help the student, except to learn there will be someone willing to do their job for them, if only they ask. And that does more to hurt the student than to help them. It also damages the site itself, since by encouraging students to post their homework with no effort shown or made, they will do it again.
Wan Ji
Wan Ji 2021๋…„ 8์›” 23์ผ
ํŽธ์ง‘: Wan Ji 2021๋…„ 8์›” 23์ผ

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Animation์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

Community Treasure Hunt

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

Start Hunting!

Translated by