2nd order euler method problem

조회 수: 1 (최근 30일)
jun seong park
jun seong park 2023년 1월 17일
답변: Jan 2023년 1월 17일
my brain is boiling
How to solve initial value problem?
x x ̈ +x ̇ ^2+cost=0, x(0)=√6, x ̇ (0)=0
% euler method 2nd order
clc;
clear;
close all;
h=0.1;
t = 0:h:10;
n = numel(size(t));
x = zeros(size(t));
dxdt = zeros(size(t));
dx2dt2 = zeros(size(t));
x(1) = sqrt(6);
dxdt(1) = 0;
plot(t,x);
for i = 1:n-1
dx2dt2(i+1) = dx2dt2(i) + h*f2(t(i),dx2dt2(i));
dxdt(i+1) = dxdt(i) + h*f1(t(i),dxdt(i));
end
function dx2dt2 = f2(t,x,dxdt)
dx2dt2 = -(dxdt^2 + cos(t))/x;
end
function dxdt = f1(t,x,dx2dt2)
dxdt = sqrt(cost(t)-x*dx2dt2);
end
also i made another code to slove same problem
% euler method 2nd order
clc;
clear;
close all;
h=0.1;
t = 0:h:10;
n = numel(size(t));
x = zeros(size(t));
dxdt = zeros(size(t));
dx2dt2 = zeros(size(t));
x(1) = sqrt(6);
dxdt(1) = 0;
f2 = @(t,x,dxdt) -(dxdt^2 + cos(t))/x;
f1 = @(t,x,dx2dt2) sqrt(cost(t)-x*dx2dt2);
for i = 1:n-1
dx2dt2(i+1) = dx2dt2(i) + h*f2(t(i),dx2dt2(i));
dxdt(i+1) = dxdt(i) + h*f1(t(i),dxdt(i));
end
plot(t,x);
thank you

답변 (1개)

Jan
Jan 2023년 1월 17일
You have to convert the 2nd order equation to a system of order 1 at first. Accumulating dx2/dt2 is not meaingful.
The 2nd derivative at the point [t, x, dxdt] is:
dx2dt2 = -(dxdt^2 + cos(t)) / x
You use this acceleration to calculate the velocity, and the velocity to get the position in each time step.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by