function [P Q r] = FullMixedModel_fixed_point(JJ, II, UUd, DDd, FFd, UUf, DDf, FFf, pd)
%
% One population of excitatory neurons, with mixed recurrent
% depressing/facilitating synapses
% Threshold-linear response function.
%
% tau dh/dt = - h + J * u * x * E(h) (eq. 1)
% dxD / dt = (1-xD)/DD - uD * xD * E(h) (eq. 2)
% duD / dt = (UD-uD)/FD + UD * (1-uD) * E(h) (eq. 3)
% dxF / dt = (1-xF)/DF - uF * xF * E(h) (eq. 4)
% duF / dt = (UF-uF)/FF + UF * (1-uF) * E(h) (eq. 5)
%
% E(h) = alpha * (h - theta) .* (h > theta)
%
P = [];
Q = [];
global theta alpha Ud Dd Fd Uf Df Ff J I ;
% Parameters initialization
Ud = UUd;
Dd = DDd;
Fd = FFd;
Uf = UUf;
Df = DDf;
Ff = FFf;
J = JJ;
I = II;
theta = 3.;
alpha = 1.;
% Fixed point search as intersections between two functions:
h = -5:0.1:100;
ud = Ud * (1 + Fd * (alpha .* (h-theta) .* (h>theta))) ./ (1 + Ud * Fd * (alpha .* (h-theta) .* (h>theta)));
xd = 1. ./ (1 + ud .* Dd .* (alpha .* (h-theta) .* (h>theta)));
uf = Uf * (1 + Ff * (alpha .* (h-theta) .* (h>theta))) ./ (1 + Uf * Ff * (alpha .* (h-theta) .* (h>theta)));
xf = 1. ./ (1 + uf .* Df .* (alpha .* (h-theta) .* (h>theta)));
g1 = I + J * (pd .* ud .* xd + (1. - pd) .* uf .* xf).* (alpha .* (h-theta) .* (h>theta));
Ie = I;
C = [];
C(1)=-Dd*Df*Fd*Ff*Ud*Uf*alpha^4;
C(2)=Dd*Fd*Ff*J*Ud*Uf*alpha^4 - Dd*Fd*Ud*alpha^2*(Df*Uf*alpha + Ff*Uf*alpha - 2*Df*Ff*Uf*alpha^2*theta) - Df*Ff*Uf*alpha^2*(Dd*Ud*alpha + Fd*Ud*alpha - 2*Dd*Fd*Ud*alpha^2*theta) + Dd*Df*Fd*Ff*Ie*Ud*Uf*alpha^4 - Dd*Fd*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= r(find( (abs(imag(r))<1e-8) & (r>theta)) )
if (isempty(r)), r = nan; end;
end