fourth order differential equation
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
syms f(x)
Df = diff(f,x);
D2f = diff(f,x,2);
D3f = diff(f,x,3);
D4f = diff(f,x,4);
ode =3*D4f+(2*x^2+6)*D3f+5*D2f-Df-2*f == - 4*x^6+ 2*x^5 -55*x^4 - 24*x^3 - 22*x^2 - x*32;
cond1 = f(0)==0;
cond2 = Df(0)==1;
cond3 = D2f(0) == -8;
cond4 = D3f(0) == 6;
conds = [cond1 cond2 cond3 cond4];
fSol(x) = dsolve(ode,conds);
figure
ezplot(fSol(x),[0 1])
The error is :
Warning: Unable to find explicit solution.
> In dsolve (line 201)
(line 13)
Error using inlineeval (line 14)
Error in inline expression ==> matrix([])
Undefined function 'matrix' for input arguments of type 'double'.
Error in inline/feval (line 33)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in ezplotfeval (line 51)
z = feval(f,x(1));
Error in ezplot>ezplot1 (line 486)
[y, f, loopflag] = ezplotfeval(f, x);
Error in ezplot (line 158)
[hp, cax] = ezplot1(cax, f{1}, vars, labels, args{:});
Error in sym/ezplot (line 78)
h = ezplot(fhandle(f),varargin{:});%#ok<EZPLT>
Error in try2 (line 15)
ezplot(fSol(x),[0 1])
採用された回答
Star Strider
2019 年 12 月 31 日
If an analytical solution is not an option, and a plot of the solution is the objectrive:
syms f(x) X Y
Df = diff(f,x);
D2f = diff(f,x,2);
D3f = diff(f,x,3);
D4f = diff(f,x,4);
ode =3*D4f+(2*x^2+6)*D3f+5*D2f-Df-2*f == - 4*x^6+ 2*x^5 -55*x^4 - 24*x^3 - 22*x^2 - x*32;
% cond1 = f(0)==0;
% cond2 = Df(0)==1;
% cond3 = D2f(0) == -8;
% cond4 = D3f(0) == 6;
[VF,Sbs] = odeToVectorField(ode);
odefcn = matlabFunction(VF, 'Vars',{x,Y});
[X,Y] = ode45(odefcn, [0 1], [0 1 -8 6]);
figure
plot(X, Y)
grid
legend(string(Sbs))
producing:

15 件のコメント
Star Strider
2019 年 12 月 31 日
kingcruises‘s ‘Answer’ —
I want to plot the solution coming out from this fourth order differential equation
Star Strider
2019 年 12 月 31 日
@kingcruises —
What part of my Answer does not do what you want?
It plots the function and all the derivatives!
kingcruises
2019 年 12 月 31 日
The code didn’t work still
Star Strider
2019 年 12 月 31 日
What does ‘didn’t work’ mean, exactly?
The code I posted ran for me without error and produced the plot I posted. It is simply an extension of your code, using odeToVectorField to produce a column vector of first-order differential equations, and matlabFunction to create an anonymous function that ode45 then integrates to create the plot.
kingcruises
2019 年 12 月 31 日
please can u provide me with matlab file '.m'
kingcruises
2019 年 12 月 31 日
Error using symfun/subsref
Too many output arguments.
Error in (line 13)
[X,Y] = ode45(odefcn, [0 1], [0 1 -8 6]);
it gave this error
Star Strider
2019 年 12 月 31 日
I do not understand the problems you are having with my code.
If you run my code exactly as I wrote it, you should have no problems with it. Note that ‘odefcn’ is the result of odeToVectorField first, followed by matlabFunction. You cannot use a symbolic function with ode45 or any of the other numeric solvers!
The anonymous function ‘odefcn’ is:
odefcn = @(x,Y) [Y(2); Y(3); Y(4); x.*(-3.2e+1./3.0)-((x.^2.*2.0+6.0).*Y(4))./3.0+Y(1).*(2.0./3.0)+Y(2)./3.0-Y(3).*(5.0./3.0)-x.^2.*(2.2e+1./3.0)-x.^3.*8.0-x.^4.*(5.5e+1./3.0)+x.^5.*(2.0./3.0)-x.^6.*(4.0./3.0)];
Just copy that from this Comment and paste it to your script.
Then run it as:
[X,Y] = ode45(odefcn, [0 1], [0 1 -8 6]);
figure
plot(X, Y)
grid
Sbs = {'f' 'Df' 'D2f' 'D3f'};
legend(string(Sbs))
That should work without problems.
kingcruises
2020 年 1 月 2 日
can we get a code with dsolve as my initial code because I have to compare with the MOM "method of moments" solution. As the below figure I have to have the same figure but using dsolve

Star Strider
2020 年 1 月 2 日
Apparently, dsolve cannot integrate your differential equation. (I doubt that an analytic solution exists for it.) That is the reason we went with the numeric integration. The simplify function cannot simplify it to the extent that dsolve can solve it.
kingcruises
2020 年 1 月 2 日
the code works well.
i want dsolve result same as mom solution. I can solve for second order but nor for fourth order

Star Strider
2020 年 1 月 2 日
I do not believe the fourth-order symbolic solution is possible, at least with the functions available in the Symbolic Math Toolbox.
kingcruises
2020 年 1 月 2 日
what do you recommend to use that can solve the fourth order differential equation.
kingcruises
2020 年 1 月 2 日
can method of moemnst give same graph as dsolve and how ?
kingcruises
2020 年 1 月 2 日
hey i must plot ode as a total not f, D2f, Df, D3f each one alone.
I want to plot ode as one graph
Star Strider
2020 年 1 月 2 日
The ‘method of moments’ was not part of my undergraduate or graduate education. (I had to look it up.) I will leave that part to you.
Plotting the total of the derivatives is straightforward. Only one change to my posted code is needed and that to sum across the columns in the plot call:
[X,Y] = ode45(odefcn, [0 1], [0 1 -8 6]);
figure
plot(X, sum(Y,2))
grid
That should do what you want.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Calculus についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
