I need help with this problem (finite difference method and ode)

조회 수: 2 (최근 30일)
jcn2912
jcn2912 2017년 12월 5일
답변: Torsten 2017년 12월 5일
Hello, I solved this question using ode45. But I'm having trouble solving for y(t) using finite difference method. Here is the code I have so far. Can you explain to me how to use finite difference method on this problem? Thanks.
clear all
close all
c=0.0001;
g=9.81;
%dy/dt=v
%dv/dt=-cv^3-g
%ODE system dy_dt=F(t,y)
F = @(t,y) [y(2);-c*(y(2))^3-g];
%dy-dt=f(t,y)
f = @(t,y) -y;
%initial conditions
y0 = [40;0];
%Numerical solution using ode45
[t,yNumerical]=ode45(F,[0 5],y0);
%Analytical Solution
figure
plot(t,yNumerical(:,1),'--o','LineWidth',2)
hold on
plot(t,yNumerical(:,2),'--o','LineWidth',2)
legend('Position','Velocity')

채택된 답변

Torsten
Torsten 2017년 12월 5일
How do you know that dy/dt at t=0 has to be 0 in order to reach a height of 5 m after 5 seconds ?
Hint: "ODE45" is not the correct solver for this problem, but "bvp4c".
For a finite-difference solution see
Best wishes
Torsten.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by