Can the arrow came directly following increasing OR decreasing behaviour of the curves

3 Ansichten (letzte 30 Tage)
Fr = .1; M = .2; Kp = 0.50; lambda = 0.1; Nr = 0.1; Pr = 7; Rd = 0.5; Nb = 0.5; Nt = 0.5; H = 0.01;
Ec = 0.01; Le = 2; Sr = 1; D = 0.5; n = 1; E = 0.5; Bi = 0.5; Slip = 0.1; V = [0 3 5]/10;
for M = V
for Kp = [0 0.5]
ODE = @(x,y)[ y(2); y(3); - y(1)*y(3) + (1+Fr)*y(2)^2 + (M+Kp)*y(2) - lambda*( y(4) - Nr*y(6) );
y(5); -(Pr/(1+Rd))*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2 );
y(7); -Pr*Le*y(1)*y(7) - (Nt/Nb)*(-(Pr/(1+Rd))*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2)) + Le*Pr*Sr*(1 + D*y(4))^n *y(6)*exp(-E/(1 + D*y(4)))];
BC = @(ya,yb)[ya(1); ya(2)-1-Slip*ya(3); ya(5)+Bi*(1-ya(4)); ya(7)+(Nt/Nb)*ya(5); yb([2;4;6])]; xa = 0; xb = 6; x = linspace(xa,xb,101);
solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
set( 0,'DefaultAxesColorOrder',[1 0 0; 1 0 0;1 0 0;0 1 0; 0 1 0;0 1 0] )
figure(2),plot(x,S(2,:),'-','LineWidth',2); hold on, ax = gca; ax.XColor = 'black'; ax.YColor = 'black'; ax.XAxis.FontSize = 12; ax.YAxis.FontSize = 12; ax.FontWeight = 'bold';
xlabel('\bf\eta','Color','blue','FontSize',16);ylabel('\bff^{\prime}(\eta)','Color','blue','FontSize',16);
L(1) = plot(nan,nan,'r-','Linewidth',2); L(2) = plot(nan,nan,'g-','Linewidth',2); %L(3) = plot(nan,nan,'k-','Linewidth',2);
legend(L,{'\color{red}\bfKp = 0.0','\color{green}\bfKp = 0.5'},'FontSize',12,'Box','off'); %legend boxoff;
a = [0.5 0.2]; b = [.2 .5]; a1 = annotation('textarrow',a,a,'Color','b','LineWidth',2);
a2 = annotation('textbox',[0.4 0.2 0.6 0.4],'String',strcat ('M = ',num2str( V)),'LineStyle','none','Color','b','FontSize',12,'FontWeight','bold');
end
end
%%% I have TWO questions
%% 1. In the attched PDF, I want to draw the arrow mark but DIRECTLY through the code following the INCREASING or DECREASING behaviour of the curves.
%% 2. )6 number of ARROWS and TEXTBOXES are coming as the code ran for 06 values, but it should be once.
%% Anyone can input ideas will be appreciated.

Akzeptierte Antwort

Mathieu NOE
Mathieu NOE am 27 Nov. 2023
hello
this is my suggestion
the arrow generation is done after the two for loops , so it's done once instead of 6 times
I compute also the direction of the curves and this drives a and b vectors so the arrow will point according to curves going downwards or upward
with the given values y_sign = -1 so the arrow ispointing downward
as I am not sure how to generate curves that go upward I simply tested my code by forcing y_sign = +1 and you get this result in that case
Fr = .1; M = .2; Kp = 0.50; lambda = 0.1; Nr = 0.1; Pr = 7; Rd = 0.5; Nb = 0.5; Nt = 0.5; H = 0.01;
Ec = 0.01; Le = 2; Sr = 1; D = 0.5; n = 1; E = 0.5; Bi = 0.5; Slip = 0.1; V = [0 3 5]/10;
mx = [];
my = [];
for M = V
for Kp = [0 0.5]
ODE = @(x,y)[ y(2); y(3); - y(1)*y(3) + (1+Fr)*y(2)^2 + (M+Kp)*y(2) - lambda*( y(4) - Nr*y(6) );
y(5); -(Pr/(1+Rd))*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2 );
y(7); -Pr*Le*y(1)*y(7) - (Nt/Nb)*(-(Pr/(1+Rd))*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2)) + Le*Pr*Sr*(1 + D*y(4))^n *y(6)*exp(-E/(1 + D*y(4)))];
BC = @(ya,yb)[ya(1); ya(2)-1-Slip*ya(3); ya(5)+Bi*(1-ya(4)); ya(7)+(Nt/Nb)*ya(5); yb([2;4;6])]; xa = 0; xb = 6; x = linspace(xa,xb,101);
solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
set( 0,'DefaultAxesColorOrder',[1 0 0; 1 0 0;1 0 0;0 1 0; 0 1 0;0 1 0] )
figure(2),plot(x,S(2,:),'-','LineWidth',2);
hold on, ax = gca;
ax.XColor = 'black';
ax.YColor = 'black';
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;
ax.FontWeight = 'bold';
xlabel('\bf\eta','Color','blue','FontSize',16);
ylabel('\bff^{\prime}(\eta)','Color','blue','FontSize',16);
L(1) = plot(nan,nan,'r-','Linewidth',2); L(2) = plot(nan,nan,'g-','Linewidth',2); %L(3) = plot(nan,nan,'k-','Linewidth',2);
legend(L,{'\color{red}\bfKp = 0.0','\color{green}\bfKp = 0.5'},'FontSize',12,'Box','off'); %legend boxoff;
end
my = [my, mean(S(2,:))]; % mean y value for each M value curve - to drive arrow direction
end
y_sign = sign(mean(diff(my)));
% y_sign = +1; % for debug only
if y_sign<0
a = [0.5 0.2];
b = [0.4 0.2 0.6 0.4];
else
a = [0.2 0.5];
b = [0.4 0.2 0.6 0.4];
end
a1 = annotation('textarrow',a,a,'Color','b','LineWidth',2);
a2 = annotation('textbox',b,'String',strcat ('M = ',num2str( V)),'LineStyle','none','Color','b','FontSize',12,'FontWeight','bold');
  5 Kommentare
Mathieu NOE
Mathieu NOE am 28 Nov. 2023
regarding the export to word , there are already some submissions that do the job, I siply picked this one :
and tried on this code to see if the 3 figures would actually be saved in the same word document - and it works ! (fortunately)
% simple demo code
for k = 1:3
x = 0:pi/100:2*pi;
y = sin(k*x);
figtoprint = figure(k); %opens new figure window
plot(x,y);title('Title');xlabel('x-label');ylabel('y-label');grid on;
save2word('junk.doc',figtoprint)
end
and so in your code this would be :
clc
clearvars
close all
Fr = .1;
M = .2;
Kp = 0.50;
lambda = 0.1;
Nr = 0.1;
Pr = 7;
Rd = 0.5;
Nb = 0.5;
Nt = 0.5;
H = 0.01;
Ec = 0.01;
Le = 2;
Sr = 1;
D = 0.5;
n = 1;
E = 0.5;
Bi = 0.5;
Slip = 0.1;
V = [0 3 5]/10;
mx = [];
my = [];
for M = V
for Kp = [0 0.5]
ODE = @(x,y)[ y(2); y(3); - y(1)*y(3) + (1+Fr)*y(2)^2 + (M+Kp)*y(2) - lambda*( y(4) - Nr*y(6) );
y(5); -(Pr/(1+Rd))*( y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2 );
y(7); -Pr*Le*y(1)*y(7) - (Nt/Nb)*(-(Pr/(1+Rd))*(y(1)*y(5) + Nb*y(5)*y(7) + Nt*y(5)^2 + H*y(4) + Ec*y(3)^2)) + Le*Pr*Sr*(1 + D*y(4))^n *y(6)*exp(-E/(1 + D*y(4)))];
BC = @(ya,yb)[ya(1); ya(2)-1-Slip*ya(3); ya(5)+Bi*(1-ya(4)); ya(7)+(Nt/Nb)*ya(5); yb([2;4;6])]; xa = 0; xb = 6; x = linspace(xa,xb,101);
solinit = bvpinit(x,[0 1 0 1 0 1 0]); sol = bvp5c(ODE,BC,solinit); S = deval(sol,x);
set( 0,'DefaultAxesColorOrder',[1 0 0; 1 0 0;1 0 0;0 1 0; 0 1 0;0 1 0] )
fig2 = figure(2);plot(x,S(2,:),'-','LineWidth',2);
hold on, ax = gca;
ax.XColor = 'black';
ax.YColor = 'black';
ax.XAxis.FontSize = 12;
ax.YAxis.FontSize = 12;
ax.FontWeight = 'bold';
xlabel('\bf\eta','Color','blue','FontSize',16);
ylabel('\bff^{\prime}(\eta)','Color','blue','FontSize',16);
L(1) = plot(nan,nan,'r-','Linewidth',2); L(2) = plot(nan,nan,'g-','Linewidth',2); %L(3) = plot(nan,nan,'k-','Linewidth',2);
legend(L,{'\color{red}\bfKp = 0.0','\color{green}\bfKp = 0.5'},'FontSize',12,'Box','off'); %legend boxoff;
end
my = [my, mean(S(2,:))]; % mean y value for each M value curve - to drive arrow direction
end
y_sign = sign(mean(diff(my)));
% y_sign = +1; % for debug only
if y_sign<0
a = [0.5 0.2];
b = [0.4 0.2 0.6 0.4];
else
a = [0.2 0.5];
b = [0.4 0.2 0.6 0.4];
end
a1 = annotation('textarrow',a,a,'Color','b','LineWidth',2);
a2 = annotation('textbox',b,'String',...
strcat ('M = ',num2str( V)),'LineStyle','none','Color','b','FontSize',12,'FontWeight','bold');
% save to word
save2word('junk.doc',fig2)
Mathieu NOE
Mathieu NOE am 28 Nov. 2023
I saw your code suggestion but I am not super familiar with ActivX server
as a standalone code it seems to work even though I had to comment some lines , but I am not sure how to turn that into a function (I tried but it opens a new word doc at each figure)
again , in the Fex submission this one is also great (I tried it) :

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