Solving 4th Order Differential Equations

조회 수: 9 (최근 30일)
Michael Johnson
Michael Johnson 2017년 12월 11일
편집: John D'Errico 2017년 12월 11일
I am trying to solve a fourth order Differential Equation (no previous Diff Q experience) and I'm running into issues with the ode45 function. I think I have entered the differential equations correctly in order for MATLAB to see them as first order equations. Any help is welcome. The equation would be f = f2 below.
if true
%clear all
clc
t = [0 9]; syms y y0
yx = y^3; y1 = diff(y0,1);
y2 = diff(y0,2);
y3 = diff(y0,3);
y4 = diff(y0,4);
f=y4+5.*(1-y0)*y3+2.*y2+3*y1+yx;
f2 = 10.*sin(pi.*t);
z = [y0 y1 y2 y3]; Z = transpose(z);
y0=0; [t,y] = ode45(@(z,y)f2,t,y0); end
  댓글 수: 1
John D'Errico
John D'Errico 2017년 12월 11일
편집: John D'Errico 2017년 12월 11일
Please don't put in comments as an answer. And then don't accept your own answer.
I moved your accepted answer into a comment. Please accept Star's answer if you feel it helped you.

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

채택된 답변

Star Strider
Star Strider 2017년 12월 11일
You appear to be on the correct path.
I would take your original symbolic differential equation as an argument to the Symbolic Math Toolbox odeToVectorField (link) function, then use that output to an argument to the matlabFunction (link) function:
syms y(t) y0(t) Y t
yx = y^3;
y1 = diff(y0,1);
y2 = diff(y0,2);
y3 = diff(y0,3);
y4 = diff(y0,4);
f=y4+5.*(1-y0)*y3+2.*y2+3*y1+yx;
[F, Fsubs] = odeToVectorField(f)
Fcn = matlabFunction(F, 'Vars',{t Y})
This gives you:
F =
Y[2]
Y[3]
Y[4]
(5*Y[1] - 5)*Y[4] - y(t)^3 - 3*Y[2] - 2*Y[3]
Fsubs =
y0
Dy0
D2y0
D3y0
and (slightly edited):
Fcn = @(t,Y) [Y(2); Y(3); Y(4); -y(t).^3+(Y(1).*5.0-5.0).*Y(4)-Y(2).*3.0-Y(3).*2.0];
that you can use in ode45.
  댓글 수: 2
Star Strider
Star Strider 2017년 12월 11일
My pleasure!
John D'Errico
John D'Errico 2017년 12월 11일
Moving the "non-answer" comment into a comment from Michael:
"Thanks! That was a great help!"

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by