Solve and plot a loop

Hi. I'm try to plot ODE 2 equations system for different parameter D values. My system:
That's why I tried, but I receiving error:
Qmax=100;
tet=10;
sig=3;
A=1.3;
vm=-2.1;
mv=-1.8;
tm=0.1;
tv=0.1;
sys=@(t,x, D)[tm*(-x(1)+mv*(Qmax/(1+exp(-(x(2)-10)./sig)))+A); tv*(-x(2)+vm*(Qmax/(1+exp(-(x(1)-10)./sig)))+D)];
tspan = linspace(0, 1, 25);
D = linspace(0, 0.1, 5);
for k1 = 1:length(D)
[t,x] = ode45(@(t,x) sys(t,x,D(k1)), tspan, [0 0]);
ty1(k1,:,:) = [t x];
end
Also, I want to plot graph plot(D, x(1)). Maybe somebody can help to fix and update this code?

Risposte (1)

Walter Roberson
Walter Roberson il 19 Mag 2020
Unrecognized variable c1, and you do not use c1 anywhere in the loop. It would seem to make more sense to iterate to length(D)
Also, I want to plot graph plot(x(1), D)
Ummm, okay...
plot(ty1(:,:,2),D)
This will give you 25 lines, one for each tspan entry. And since D is the independent variable and x(1) is the dependent variable, it seems strange to use the x(1) value as the independent (first) coordinate and D as the dependent (second) coordinate.

6 Commenti

Ewona CZ
Ewona CZ il 19 Mag 2020
Hi Walter. Yes, it should be length(D), it was a typo and yes should be (D, x(1)).
ty1(k1,:,:) = [t x]; - Matlab gives error in this line.
Thanks for comments. Is it possible to plot such graph?
@Walter
I ran your code changing only c1 to D. After that
plot(D, ty1(:,:,2))
You might have an old ty1 in memory that needs to be removed
Ewona CZ
Ewona CZ il 19 Mag 2020
Modificato: Ewona CZ il 19 Mag 2020
Yes, it works, but seems I wrote wrong code. I actually wanted to plot solutions depending on paramater D.
This graph is in my book for this system. Is it possible to get? :D I try something like this for the first time.
Walter Roberson
Walter Roberson il 20 Mag 2020
At the moment, I cannot tell which variable is Vm in terms of your x output.
To get that kind of graph, with multiple Vm values for a given D value, D would have to be the dependent variable, which is not the case in your code.
Ewona CZ
Ewona CZ il 20 Mag 2020
Modificato: Ewona CZ il 20 Mag 2020
Not sure, but actually in my article D is given like a parameter, but I really saw such graphs in books where D - different values, not a function. I think Vm here is a solution for the first equation of the system. I added original system to my question, please have a look if you are able. Thanks in advance!
Walter Roberson
Walter Roberson il 20 Mag 2020
I do not seem to understand how that diagram is constructed, sorry.
The only guess I have is that maybe there are different initial values for Vm that in combination with a D value lead to some particular outcome, but I have no guesses about what they might be looking for.

Accedi per commentare.

Categorie

Scopri di più su Mathematics in Centro assistenza e File Exchange

Richiesto:

il 19 Mag 2020

Commentato:

il 20 Mag 2020

Community Treasure Hunt

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

Start Hunting!

Translated by