Plotting the output from differential equations
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
onsagerian
am 13 Feb. 2018
Kommentiert: Walter Roberson
am 14 Feb. 2018
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);
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 14 Feb. 2018
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 Kommentare
Walter Roberson
am 14 Feb. 2018
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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Equation Solving finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!