Second Order ODE solve

조회 수: 2 (최근 30일)
Patiphol Jiravanichkul
Patiphol Jiravanichkul 2021년 10월 12일
답변: Ashutosh Singh Baghel 2021년 10월 22일
Solve the following equation. Your answer must be real-valued functions and must be simplified.
y'' + 4y = f(x), f(x) = sin(2x) when pi/4 < x < 3*pi/4 and f(x) = 0 when otherwise
Given y(pi/4) = 3, y(pi/2) = 0.

답변 (1개)

Ashutosh Singh Baghel
Ashutosh Singh Baghel 2021년 10월 22일
Hi Patiphol,
I believe you wish to plot this second order ode dependent on x. Please find a reference example
fx = linspace(0, 10, 50);
f = sin(2*fx);
xspan = [pi*0.25 pi*0.5];
y_0 = [3 0];
[x,y] = ode45(@(x, y) myode1(x, y, fx, f), xspan, y_0);
plot(x, y(:,1), '-r ', x, y(:,2), '--g');
legend('y(1)', 'y(2)');
xlabel('x');
ylabel('y Solution');
function dydx = myode1(x, y, fx, f)
f = interp1(fx, f, x);
dydx = [y(2); f - 4*y(1)];
end
Please refer to the following MATLAB Documentation page on the 'ode45' function and relevant information on the 'Differential Equation'.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by