sub plotting odes15 in MATLAB

2 vues (au cours des 30 derniers jours)
BlahBlah
BlahBlah le 11 Déc 2014
Commenté : Star Strider le 12 Déc 2014
I am trying to practice for a final coming up and I was given an old question and I am having trouble with the odes15 and sub plotting. I tried using the examples given on the MATLAB main website but couldn't figure out why it would work. The question is:
My code is:
function dx = problem1(t,x)
P1 = 0.028735 ;
P2 = 0.028344 ;
P3 = 5.035 * 10^(-5) ;
Vi = 12 ;
n = 5/54 ;
D_t = 3*exp(-0.05*t) ;
U_t = 3 ;
Gb = 4.5;
Xb = 15;
Ib = 15;
G = x(1);
X = x(2);
I = x(3);
dx = zeros(3,1);
dx(1) = -P1*(G-Gb) - (X-Xb)*G + D_t ;
dx(2) = -P2*(X-Xb) + P3*(I-Ib) ;
dx(3) = -n*I + U_t/Vi ;

Réponses (1)

Amit
Amit le 11 Déc 2014
You have done most of it already. Now to call ode15s, you should do like this :
[T,X] = ode15s(@problem1,[0 60*24],[4.5 15 15])
Read more of using ode15s at - http://www.mathworks.com/help/matlab/ref/ode15s.html 60*24 is for 1 day as all the units are in mins. T is time (in mins) and X will be corresponding values at that time where the columns will represent [G I X].
not for subplot:
subplot(3,1,1);
plot(T,X(:,1)); % Plot G
subplot(3,1,2); % Second subplot
plot(T,X(:,2)); % Plot I
subplot(3,1,3); % Second subplot
plot(T,X(:,3)); % Plot X
  9 commentaires
BlahBlah
BlahBlah le 12 Déc 2014
Just to make it clear, is it possible to put the subplots somewhere within a function whether with this one or separate so that I don't have to manually type in the command window what to plot?? Thanks for the help!!
Star Strider
Star Strider le 12 Déc 2014
That is what the script file is for. A script file is what you would otherwise type into the Command Window, but exists as an executable file that you can run and edit anytime. If you make any changes to it, you have to save it again after the changes for them to be executed in the file, since the file executes as the latest saved version.
See the documentation for Create Scripts and Scripts vs. Functions for details. To start the Editor, click on ‘New Script’ at the left under the ‘Home’ tab.
In addition to using the ‘Run’ green triangle, you can execute a particular script by typing its name in the Command Window (with or without the .m extension). That’s what I do (without the extension). The only requirement is your script .m-file has to be in your MATLAB search path.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by