MATLAB Answers

hold on option is not working in the present code

42 ビュー (過去 30 日間)
MINATI PATRA
MINATI PATRA 2021 年 9 月 17 日 16:57
コメント済み: MINATI PATRA 2021 年 9 月 18 日 6:51
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 日 19:30
Due to legend style, the code stops. I think we should modify that. Please help.

サインインしてコメントする。

採用された回答

the cyclist
the cyclist 2021 年 9 月 17 日 20:06
編集済み: the cyclist 2021 年 9 月 17 日 20:09
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 件のコメント
MINATI PATRA
MINATI PATRA 2021 年 9 月 18 日 6:51
@
the cyclist
It was a huge mistake (how can I do that), Thanks for correcting.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by