Solve differential equation using ode23 and ode45
2 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226162/image.png)
My approach:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226168/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226168/image.png)
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 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!