
fourth order differential equation
12 次查看(过去 30 天)
显示 更早的评论
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])
0 个评论
采纳的回答
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
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!