hold on option is not working in the present code

1 次查看(过去 30 天)
M = 0.2; L = 0.01; K = 0.1; G = 2; Pr = 2; s = 0.1; Ec = 0.01; m = 0.5; R = 0.5; fw = 0.5; a = 1; n = 0.5;
for M = [0 .1 .2]
for fw = [-1 0 1]/2
ODE = @(x,y)[ y(2); y(3); (y(2)^2 - y(1)*y(3) + M*y(2) - K*y(5) - L*y(6))/(1+K); y(5); (y(2)*y(4) - y(1)*y(5) + K*(2*y(4) + y(3)))/G;
y(7); Pr*( m*y(2)*y(6) - s*y(6) - Ec*y(3)^2 - y(1)*y(7) )/(1+(4/3)*R) ];
BC = @(ya,yb)[ya(1)-fw; ya(2)-1-a*(1+K)*ya(3); ya(4)+n*ya(3); ya(7)-1; 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); f0 = deval(sol,0);
set( 0,'DefaultAxesColorOrder',[1 0 0; 0 1 0; 0 0 0] )
figure(11),plot(x,S(2,:),'LineWidth',2); hold on,
ax = gca; ax.XColor = 'black'; ax.YColor = 'black'; ax.XAxis.FontSize = 10; ax.YAxis.FontSize = 10; ax.FontWeight = 'bold';
xlabel('\bf\eta','Color','blue'); ylabel('\bff^{\prime}(\eta)','Color','blue');
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}\bffw = - 0.5','\color{green}\bffw = 0','\color{black}\bffw = 0.5'},'Box','off');
end
end
Error using vertcat
Dimensions of arrays being concatenated are not consistent.

Error in solution (line 4)
ODE = @(x,y)[ y(2); y(3); (y(2)^2 - y(1)*y(3) + M*y(2) - K*y(5) - L*y(6))/(1+K); y(5); (y(2)*y(4) - y(1)*y(5) + K*(2*y(4) + y(3)))/G;

Error in bvparguments (line 105)
testODE = ode(x1,y1,odeExtras{:});

Error in bvp5c (line 135)
bvparguments(solver_name,ode,bc,solinit,options);
  4 个评论
MINATI PATRA
MINATI PATRA 2021-9-17
@Adam Thanks for your suggestion, I will work on it.
@Cris What next Dear?
MINATI PATRA
MINATI PATRA 2021-9-17
Due to legend style, the code stops. I think we should modify that. Please help.

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2021-9-17
编辑:the cyclist 2021-9-17
The problem doesn't really have anything to do with the legend. The fundamental problem is that you first define L as a parameter, but inside the for loop, you then use L as a 1x3 vector of graphics handles from the plots.
Therefore, when you get to the second iteration of the for loop, this expression
% I commented this so that it does not run
% y(2)^2 - y(1)*y(3) + M*y(2) - K*y(5) - L*y(6)
is a spurious 1x3 vector. That's why you get a concatenation error.
Change one of those variable names to something else.
L = 0.01;
K = 0.1;
G = 2;
Pr = 2;
s = 0.1;
Ec = 0.01;
m = 0.5;
R = 0.5;
a = 1;
n = 0.5;
xa = 0;
xb = 6;
x = linspace(xa,xb,101);
for M = [0 .1 .2]
for fw = [-1 0 1]/2
ODE = @(x,y)[ y(2); y(3); (y(2)^2 - y(1)*y(3) + M*y(2) - K*y(5) - L*y(6))/(1+K); y(5); (y(2)*y(4) - y(1)*y(5) + K*(2*y(4) + y(3)))/G;
y(7); Pr*( m*y(2)*y(6) - s*y(6) - Ec*y(3)^2 - y(1)*y(7) )/(1+(4/3)*R) ];
BC = @(ya,yb)[ya(1)-fw; ya(2)-1-a*(1+K)*ya(3); ya(4)+n*ya(3); ya(7)-1; yb([2;4;6])];
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; 0 1 0; 0 0 0] )
figure(11),plot(x,S(2,:),'LineWidth',2);
hold on,
ax = gca;
ax.XColor = 'black';
ax.YColor = 'black';
ax.XAxis.FontSize = 10;
ax.YAxis.FontSize = 10;
ax.FontWeight = 'bold';
xlabel('\bf\eta','Color','blue');
ylabel('\bff^{\prime}(\eta)','Color','blue');
LL(1) = plot(nan,nan,'r-','Linewidth',2);
LL(2) = plot(nan,nan,'g-','Linewidth',2);
LL(3) = plot(nan,nan,'k-','Linewidth',2);
legend(LL,{'\color{red}\bffw = - 0.5','\color{green}\bffw = 0','\color{black}\bffw = 0.5'},'Box','off');
end
end
  2 个评论
Adam Danz
Adam Danz 2021-9-17
编辑:Adam Danz 2021-9-17
I've moved by duplilcate answer here since the cyclist and I answered nearly at the same time and we both came to the same conclusion.
The error occurs because you are overwriting the variable L defined in the first line of your code. Your 3 plot() commands are storing the output handles in a variable named L which overwrites L with a 1x3 vector. Then in the ODE() function, the vertical concatenation throws an error because it expects L to be a scalar value.
Solution:
Rename the 3 plot() outputs and rename the first input to your legend() funciton.
This problem may have been avoided by writing cleaner code where each statement gets its own line.
MINATI PATRA
MINATI PATRA 2021-9-18
@
the cyclist
It was a huge mistake (how can I do that), Thanks for correcting.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by