How to color a contour of two curves?

52 views (last 30 days)
Khadija
Khadija on 4 Dec 2024 at 21:39
Commented: Star Strider on 11 Dec 2024 at 13:55
Hi, I'm trying to color a contour between two function curves, the problem is that just the two curves appear, without a colored contour. And this message appears when i am running.
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize
your function to return an output with the same size and shape as the input arguments.

Accepted Answer

Star Strider
Star Strider on 4 Dec 2024 at 23:27
I am not certain what you want.
Try this —
% Diagramme de coexistence avec des contours colorés
% clc; clear; close all;
% Définir les limites des axes
Rs_min = 0; Rs_max = 5; % Intervalle pour Rs
Rh_min = 0; Rh_max = 5; % Intervalle pour Rh
% Générer une grille de points dans le plan (Rs, Rh)
[Rs, Rh] = meshgrid(linspace(Rs_min, Rs_max, 500), linspace(Rh_min, Rh_max, 500));
% Définir les seuils critiques
Rs1 = 1; % Seuil critique pour Rs
Rh1 = 1; % Seuil critique pour Rh
% Calculer les régions :
extinction = (Rs <= Rs1) & (Rh <= Rh1); % Dominace E_0
region1 = (Rs > Rs1) & (Rh <= Rh1); % Domination E*_1
region2 = (Rh > Rh1) & (Rs <= Rs1); % Domination E*_2
coexistence = (Rs > Rs1) & (Rh > Rh1); % Coexistence E*
% Créer une matrice de catégories pour les régions
regions = zeros(size(Rs));
regions(region1) = 1; % Code 1 : Domination Espèce E*_1
regions(region2) = 2; % Code 2 : Domination Espèce E*_2
regions(coexistence) = 3; % Code 3 : Coexistence E*
regions(extinction) = 4; % Code 4 : E_0
% Ajouter une relation entre R1 et R2 (par exemple, R2 = 1 / R1)
delta = 0.0001; % Taux de mortalité
delta_S = 0.0005; % Taux de mort de Syphilis.
delta_H = 0.00004;
Lambda =4.04 *100;
gamma=1.7;
phi_S =0.0006;
phi_H =0.00002;
c1 = 1;
c2=2 ;
theta1 =11 ;
theta2 = 5;
alpha = 0.4;
beta = 0.11;
rho1 = 0.5;
rho2= 1.5;
rho3=1.5;
y_1=gamma+delta+delta_S;
y_2=alpha+delta+delta_H;
y_4=rho1*gamma+rho2*alpha+delta+delta_S+delta_H;
m=delta./(delta+delta_S);
%expression de Rh en fonction de Rs
f = @(Rs) (((theta1*(Rs-1)*m*y_1+y_2)*y_4 )-theta1*(Rs-1)*m*y_1*rho1*gamma)/(((y_2*y_4)./ Rs)+c1*theta1*theta2*Rs*(1- 1 ./ Rs)^2* m^2*y_1*y_2+c1*theta2*m*(y_2)^2*(1- 1 ./ Rs)+rho1*gamma*theta2*m*(1- 1 ./ Rs)+c1*theta1*m*y_1*y_2*(1- 1 ./ Rs));
g=@(Rs) Rs*(theta2*delta*(Rs- 1 )+y_1)*y_4*y_2/(y_1*y_2*y_4+theta1*c2*delta*y_1* (Rs- 1 )*(theta2*delta*(Rs-1)+y_1)+theta2*c2*delta*(Rs-1)*y_1*y_2);
%t=@(Rs) Rs;
f_values = f(Rs); % Valeurs de la fonction `f` sur les points `x`
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
g_values = g(Rs);% Valeurs de la fonction `g` sur les points `x`
Warning: Matrix is singular to working precision.
X = [Rs, fliplr(Rs)];
Y = [f_values, fliplr(g_values)];
% Afficher la formule de la fonction symbolique
disp('La formule de la fonction est :');
La formule de la fonction est :
disp(f);
@(Rs)(((theta1*(Rs-1)*m*y_1+y_2)*y_4)-theta1*(Rs-1)*m*y_1*rho1*gamma)/(((y_2*y_4)./Rs)+c1*theta1*theta2*Rs*(1-1./Rs)^2*m^2*y_1*y_2+c1*theta2*m*(y_2)^2*(1-1./Rs)+rho1*gamma*theta2*m*(1-1./Rs)+c1*theta1*m*y_1*y_2*(1-1./Rs))
disp(g);
@(Rs)Rs*(theta2*delta*(Rs-1)+y_1)*y_4*y_2/(y_1*y_2*y_4+theta1*c2*delta*y_1*(Rs-1)*(theta2*delta*(Rs-1)+y_1)+theta2*c2*delta*(Rs-1)*y_1*y_2)
%disp(t);
figure(1);
hold on;
fill(X, Y, 'cyan', 'FaceAlpha', 0.5, 'EdgeColor', 'none'); % Remplissage de la région
fp1 = fplot( f, [1, Rs_max], 'k-', 'LineWidth', 0.5);% Courbe Rh en fonction de Rs
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
fp2 = fplot( g, [1, Rs_max], 'r--', 'LineWidth', 0.5);%courbe Rs en fct Rh( on adaptant meme nota pour tracer la recipro
Warning: Function behaves unexpectedly on array inputs. To improve performance, properly vectorize your function to return an output with the same size and shape as the input arguments.
x1 = fp1.XData;
y1 = fp1.YData;
x2 = fp2.XData;
y2 = fp2.YData;
patch([x1 flip(x2)], [y1 flip(y2)], 'g') % Plot Green ‘patch’
%fplot( t, [1, Rs_max], 'b-', 'LineWidth', 0.5);
% Ajouter des lignes critiques
plot([Rs1 Rs1], [Rh_min Rh_max], 'k--', 'LineWidth', 0.5); % Ligne verticale Rs1
plot([Rs_min Rs_max], [Rh1 Rh1], 'k--', 'LineWidth', 0.5); % Ligne horizontale Rh1
% Ajuster l'apparence
xlabel('R_s');
ylabel('R_h');
hold off
.
  16 Comments
Khadija
Khadija on 11 Dec 2024 at 13:29
Thank you so much!!
I solved the problem, your instructions were very helpful, you are an angel!!
Star Strider
Star Strider on 11 Dec 2024 at 13:55
As always, my pleasure!
I very much appreciate your compliment!

Sign in to comment.

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!