New to matlab and not sure how to reduce to first order

조회 수: 1 (최근 30일)
Samantha
Samantha 2020년 12월 18일
편집: James Tursa 2020년 12월 18일
Solve the third-order ODE function
y′′′− 2 * y′′−(y′)^2 = 1
With tspan [0 5], y(0) = y’(0) = 0, y’’ = 1.
You need to reduce the given third-order ODE equation to standard 1st-order ODE equations before solving
  댓글 수: 2
KSSV
KSSV 2020년 12월 18일
So integrate first w.r.t first, it will be reduced into y'' and then use ode45.
Jon
Jon 2020년 12월 18일
Would this work? ode45 only solves first order equations, wouldn't you still have a second order equation

댓글을 달려면 로그인하십시오.

답변 (1개)

Jon
Jon 2020년 12월 18일
편집: Jon 2020년 12월 18일
Define
y1 = y
y2 = y'
y3 = y''
% and then make a function f, for example put the code below into an m-file called f.m
function dydt = f(t,y)
dydt(1) = y(2); % y1' = y2
dydt(2) = y(3); % y'' = y3
dydt(3) = 1 + 2*y(3) + y(2)^2;
then use one of the ode solvers e.g ode45 passing it the function f described above
Please see https://www.mathworks.com/help/matlab/math/choose-an-ode-solver.html especially the section on solving higher order equation
  댓글 수: 8
Jon
Jon 2020년 12월 18일
You can get documentation for ode45 by typing doc ode45 on the command line.
Once you get this running, if you have not already done so I would highly recommend taking the time to complete the MATLAB on ramp training to help you get more familiar with using MATLAB in general https://www.mathworks.com/learn/tutorials/matlab-onramp.html
James Tursa
James Tursa 2020년 12월 18일
편집: James Tursa 2020년 12월 18일
The ode45( ) call should not be inside your derivative function. That's backwards. The ode45( ) function is calling your derivative function, not the other way around. So you should have some code that defines initial conditions and calls ode45( ) like this:
tspan = [0 5]; % time span
y0 = [0 0 1]; % initial values of y, y', and y''
ode45(@odef,tspan,y0);
plot(t,y);
and then a separate code (e.g., in a file called odef.m, or maybe below the code listed above) that contains your derivative code:
function dydt = odef(t,y)
dydt = zeros(3,1); % the values y', y'', and y'''
dydt(1) = y(2); % y' = y2
dydt(2) = y(3); % y'' = y3
dydt(3) = 1 + 2*y(3) + y(2)^2; % y''' = 1 + 2y'' + (y')^2
end

댓글을 달려면 로그인하십시오.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by