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])
采纳的回答
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 个评论
kingcruises‘s ‘Answer’ —
I want to plot the solution coming out from this fourth order differential equation
@kingcruises —
What part of my Answer does not do what you want?
It plots the function and all the derivatives!
The code didn’t work still
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.
please can u provide me with matlab file '.m'
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
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.
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

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.
the code works well.
i want dsolve result same as mom solution. I can solve for second order but nor for fourth order

I do not believe the fourth-order symbolic solution is possible, at least with the functions available in the Symbolic Math Toolbox.
what do you recommend to use that can solve the fourth order differential equation.
can method of moemnst give same graph as dsolve and how ?
hey i must plot ode as a total not f, D2f, Df, D3f each one alone.
I want to plot ode as one graph
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!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 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)
