From: Lukáš Jiřiště Date: Mon, 20 May 2024 13:59:31 +0000 (+0200) Subject: Change pseudo_exp.m so it is closer to real data X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=2078434b4b0bbaca940e7c78f9a3e66139d534dd;p=analyse_servo.git Change pseudo_exp.m so it is closer to real data The data was meassured in a different way to what I assumed hence the pseudo experimental data were not that similar to the real data. This commit changes the pseudo_exp function so it mimics the experiment much more closely. --- diff --git a/pseudo_exp.m b/pseudo_exp.m index 8d5a40a..26cf9d7 100644 --- a/pseudo_exp.m +++ b/pseudo_exp.m @@ -1,13 +1,22 @@ -function [t, p, t_open] = pseudo_exp(p1, V1, V2, Vvz, n) - t_open = rand(1, n) * (50 - 15) + 15; - t_open = ceil(cumsum(t_open)); - t = (0:ceil(t_open(n)) + 20); +function [t, p, t_open, t_fill] = pseudo_exp(p_supply = 10, V1 = 1000, V2 = 1000, Vvz = 200, n = 10, V_supply = V1) + t_fill = rand(1, n) * (200 - 100) + 100; + t_fill = ceil(cumsum(t_fill)); + t_open = t_fill + 10; + t = (0:ceil(t_open(n)) + 100); p = zeros(size(t)); - peq = 0; - for i = ceil(t_open) - p2 = (p(i + 1) * (V2 - Vvz) + p1 * V1) / (V1 + V2 - Vvz); - peq += 0.7 * (p2 - peq); - p(i + 1:end) = (p2 - peq) * exp((-((i + 1):length(p)) + i + 1) / 10) + peq; + p1 = 0; + p2 = 0; + for i = 1:length(t_fill) + p1 = (p1 * V1 + p_supply * V_supply) / (V1 + V_supply); + p((t_fill(i) + 1):(t_open(i))) = p1; + p1 = (p1 * V1 + p2 * (V2 - Vvz)) / (V1 + V2 - Vvz); + peq = p2 + 0.7 * (p1 - p2); + if (i != length(t_fill)) + p((t_open(i) + 1):t_fill(i + 1)) = (p1 - peq) * exp(-(t((t_open(i) + 1):t_fill(i + 1)) - t(t_open(i))) / 10) + peq; + else + p((t_open(i) + 1):end) = (p1 - peq) * exp(-(t((t_open(i) + 1):end) - t(t_open(i))) / 10) + peq; + end + p2 = peq; end p += rand(size(t)) * p1 / 100; end