Mark a point on graph

8 Ansichten (letzte 30 Tage)
Leonor Vieira Dias
Leonor Vieira Dias am 1 Feb. 2021
Kommentiert: Star Strider am 1 Feb. 2021
Hello,
I have made a graph with the following code. My goal was to know whey the y-axis is equal to 0.331. This means, the time it takes for the concentration of the lake to be 0.331. I also wanted to mark that point in my graph. Is that possible?
Thank you in advance
First, let's define our variables:
r = 10^5 ;
V = 10^10 ;
c_i = 100 ;
t = 0:10^7 ;
Then, we enter our model for the concentration in the lake :
c_L = c_i.*(1-exp((-r.*t)./V));
Finally, we plot the evolution of the concentration in the lake:
plot(t,c_L);
semilogx(c_L);
xlabel("Time t (hours)");
ylabel("Concentration of pollutant in the lake cL (kg/m^3)");
title("Concentration vs time");

Akzeptierte Antwort

Star Strider
Star Strider am 1 Feb. 2021
Try this:
r = 10^5 ;
V = 10^10 ;
c_i = 100 ;
t = logspace(-2, 7, 20);
c_L = c_i.*(1-exp((-r.*t)./V));
Q1 = nnz(diff(c_L)==0)
c_crit = 0.331;
t_crit = interp1(c_L, t, c_crit);
figure
plot(t,c_L);
hold on
plot(t_crit, c_crit, 'sr', 'MarkerFaceColor','r')
hold off
set(gca, 'XScale','log', 'YScale','log')
% semilogx(c_L);
xlabel("Time t (hours)");
ylabel("Concentration of pollutant in the lake cL (kg/m^3)");
title("Concentration vs time");
text(t_crit, c_crit, sprintf(' \\leftarrow t = %5.1f, Concentration = %6.3f', t_crit, c_crit), 'HorizontalAlignment','left', 'VerticalAlignment','middle')
Change it to produce the result you want.
  2 Kommentare
Leonor Vieira Dias
Leonor Vieira Dias am 1 Feb. 2021
that work out very well! thank you very much
Star Strider
Star Strider am 1 Feb. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by