필터 지우기
필터 지우기

Solve differential equation using ode23 and ode45

조회 수: 2 (최근 30일)
emonhossain roy
emonhossain roy 2019년 6월 24일
댓글: Pullak Barik 2019년 6월 25일
Question: solve the differential equation regarding y as the independent variable rather than x. Also find solution for x(0)=1. Finally plot y vs x(y). Also use ode23 and ode45 to solve the equation and plot again.
My approach:
code:
syms x(y);
eqn=diff(y,x)==(x+y*exp(y));
cond=x(0)==1;
dsolve(eqn,cond)
But now how to use ode23 or ode45 and how to plot? Any solution will be appreciated .
Thanks in advance .
  댓글 수: 3
emonhossain roy
emonhossain roy 2019년 6월 24일
@Star Strider I edited my post
Torsten
Torsten 2019년 6월 25일
편집: Torsten 2019년 6월 25일
No, you didn't since you still write
eqn=diff(y,x)==(x+y*exp(y));

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

채택된 답변

Pullak Barik
Pullak Barik 2019년 6월 25일
Firstly, as correctly mentioned in the comments, the eqn variable should be written as-
eqn = diff(x, y) == (x + y*exp(y));
Now, for plotting the solution, you can use fplot- fplot documentation
xSol = simplify(dsolve(eqn, cond)); %simplify, as the name suggests, simplifies the expression obtained after dsolve
fplot(xSol);
Now, about using ode23 or ode45, I suggest you to refer to the documentation to gain an understanding on the same. I am posting a code below which uses ode45 (referred directly from the documentation)-
[y, x] = ode45(@(y, x) (x + y*exp(y)), [-10 10], 1)
Link to ode45 documentation- ODE45
  댓글 수: 1
Pullak Barik
Pullak Barik 2019년 6월 25일
You can use plot(y, x) after using the ode45 code above to plot the result

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by