fourth order differential equation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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
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
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)
