필터 지우기
필터 지우기

Plotting the output from differential equations

조회 수: 3 (최근 30일)
onsagerian
onsagerian 2018년 2월 13일
댓글: Walter Roberson 2018년 2월 14일
Hello,
I am trying to design a program for making a plot using the outcome from differential equations. I have tried to construct a code several times for this, but I failed. Actually, documents on MathWorks for this issue are very confusing. Would you check my code designed to solve coupled differential equations and let me know what commands are needed to make plots? (Two plots should be generated. One for time vs S_1 the other for time vs S_2.)
I think the basic idea of the program is to save each outcome from given differential equations and use the data for plotting, but I don't know.
(Again, the following code is only for solving differential equations, so additional commands are required to plot data.)
syms S_1(t) S_2(t);
K=1;
k_1=20;
k_2=5;
k_3=5;
k_4=5;
k_5=2;
n=4;
dsolve(diff(S_1,t)==k_1*S_2^n/(K^n+S_2^n)-k_3*S_1-k_5*S_1,S_1(0)==0.0);
dsolve(diff(S_2,t)==k_2+k_5*S_1-k_4*S_2,S_2(0)==0.6);

채택된 답변

Walter Roberson
Walter Roberson 2018년 2월 14일
As I explained in https://www.mathworks.com/matlabcentral/answers/381943-solving-differential-equation-with-initial-conditions#comment_534054 those are related functions and must be dsolve() together. I also indicated there that the functions are effectively impossible to solve in closed form.
You will need to switch to numeric resolution. Star Strider posted links to odeFunction. The first example for odeFunction takes you through the entire workflow of functions needed to convert symbolic ode into inputs for the ode* routines.
  댓글 수: 2
onsagerian
onsagerian 2018년 2월 14일
편집: Walter Roberson 2018년 2월 14일
I am sorry, but I assumed once I construct differential equations and add "some commands" for plotting, the single program would automatically produce the plot I want to see. Of course, in general, once I get an output after solving differential equations, and use it to get plots in a separate file, then I would expect the result(plots). However, it is very inconvenient. So, is there any way to make a plot without solving differential equations? The following code is for solving a very simple differential equation with initial conditions. Again, without using a separate file, what commands are needed to get a plot from it?
syms y(x);
Dy=diff(y,x);
cond1=y(0)==2;
cond2=Dy(0)==5;
simplify(dsolve(diff(y,x,x)+4*diff(y,x)+4*y==(3+x)*exp(-2*x),cond1,cond2))
Walter Roberson
Walter Roberson 2018년 2월 14일
In this simple example, dsolve is able to give you a closed form solution. You can store that closed form solution in a variable and fplot() that variable over the desired range.
In the case of the equations in your Question, above, there is no meaningful closed form solution and you will need to follow the work-flow show in odeFunction to translate your ode from symbolic to numeric and do a numeric simulation, which you can then plot.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equation Solving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by