MATLAB Answers

How to plot ode

2 views (last 30 days)
Ana Rasic
Ana Rasic on 25 Nov 2020
Edited: Ana Rasic on 26 Nov 2020
I will need a help.So,I have 4 different variables

  0 Comments

Sign in to comment.

Accepted Answer

Alan Stevens
Alan Stevens on 25 Nov 2020
First, you should combine your three "prom" ode functions into one
IC = [n0 m0 h0];
[t, NMH] = ode45(@(t,nmh) prom(t,nmh,V1), tspan, IC);
n = NMH(:,1):
m = NMH(:,2);
h = NMH(:,3);
...
where your ode function is something like
function dNMHdt = prom(t,NMH,V1)
n = NMH(1);
m = NMH(2);
h = NMH(3);
dndt = ....;
dmdt = ....;
dhdt = ....;
dNMHdt [ dndt; dmdt; dhdt];
end
Then you can think of doing something along the lines of:
V1 = [20 40 60 80];
for i = 1:4
[t, NMH] = ode45(@(t,nmh) prom(t,nmh,V1(i)), tspan, IC);
n(:,i) = NMH(:,1);
m(:,i) = ....etc.
end

  4 Comments

Show 1 older comment
Ana Rasic
Ana Rasic on 26 Nov 2020
Hey,I just wanna say that everything work with little modifications, so thank you again
I have just one more question
What exactly mean this line, n(:,i) = NMH(:,1), what's happen when I put this in the loop?
Alan Stevens
Alan Stevens on 26 Nov 2020
It saves the values of NMH for that value of i (if I've got the syntax right!) so that you can plot/display/examine all four sets of values after the loop is completed. Similarly for m and h.
Ana Rasic
Ana Rasic on 26 Nov 2020
Right, I understand:)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by