How to color a contour of two curves?

조회 수: 3 (최근 30일)
Khadija
Khadija 2024년 12월 4일
댓글: Star Strider 2024년 12월 11일
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.

채택된 답변

Star Strider
Star Strider 2024년 12월 4일
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
Khadija
Khadija 2024년 12월 11일
Thank you so much!!
I solved the problem, your instructions were very helpful, you are an angel!!
Star Strider
Star Strider 2024년 12월 11일
As always, my pleasure!
I very much appreciate your compliment!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by