changing the scale on the Y axis
조회 수: 4 (최근 30일)
이전 댓글 표시
Good evening sir
Sir I need -1 to 1 on Y-axis but i got this on X-axis. Now I request you please help me how to getting -1 to 1 on Y-axis. I attached my code and graph relating to my code.
Code:
xmesh1 = linspace(-1,0,10);
xmesh2 = linspace(0,1,10);
xmesh = [xmesh1,xmesh2];
yinit = [0 1 0 1 0 1 0 1];
init = bvpinit(xmesh,yinit);
sol = bvp5c(@f, @bc, init);
plot(sol.x,sol.y(2,:),'b-o',sol.x,sol.y(3 ,:),'r-o')
%line([1 1], [0 1], 'Color', 'k')
% legend('y1','y3')
% % title('A Three-Point BVP Solved with bvp5c')
% xlabel({'x', '\lambda = 2, \kappa = 5'})
% ylabel('v(x) and C(x)')
hold on
function dydx = f(x,y,region) % equations being solved
W=1;alpha=1;M=2;k1=1;k2=1;k3=1;k4=1;k=1; Ps=1;Po=1;R1=0;R2=2;
omega=1;
us = y(1);
usy = y(2);
uo = y(3);
u0y = y(4);
thetas = y(5);
thetasy = y(6);
thetao = y(7);
thetaoy = y(8);
dydx = zeros(8,1);
switch region
case 1 % x in [-1 0]
dydx(1) = usy;
dydx(2) = (M^2 + 1/k2)*us - alpha*Ps*R2;
dydx(3) = u0y;
dydx(4) = (M^2 + 1/k1 + 1i*omega*R2)*uo - alpha*Po*R2; % 1/K2 ?
dydx(5) = thetasy+thetas;
dydx(6) = k1*usy^2;
dydx(7) = thetaoy;
dydx(8) = k*thetao - k3*thetasy*thetaoy;
case 2 % x in [0 1]
dydx(1) = usy;
dydx(2) = (M^2 + 1/k1)*us - Ps*R1;
dydx(3) = u0y;
dydx(4) = (M^2 + 1/k1 + 1i*omega*R1)*uo - Po*R1;
dydx(5) = thetasy;
dydx(6) = k2*usy^2;
dydx(7) = thetaoy;
dydx(8) = k*thetao - k4*thetasy*thetaoy;
end
end
function res = bc(YL,YR)
mu1=1; mu2=1; k1=1; k2=1;
res = [YL(1,1)
YL(3,1)
YL(5,1)
YL(7,1)
YR(1,2)-1
YR(3,2)-1
YR(5,2)-1
YR(7,2)
YR(1,1)-YL(1,2)
mu1*YR(2,1)-mu2*YL(2,2)
YR(3,1)-YL(3,2)
mu1*YR(4,1)-mu2*YL(4,2)
YR(5,1)-YL(5,2)
k1*YR(6,1)-k2*YL(6,2)
YR(7,1)-YL(7,2)
k1*YR(8,1)-k2*YL(8,2)];
end
The graph relating to code is
But I need the -1 to 1 range on Y-axis like the following graph:
댓글 수: 7
답변 (2개)
ScottB
2024년 7월 11일
ylim([-1 1]);
y_values = [-1:0.2:1];
ha = gca;
set(ha, 'ytick', y_values);
yticklabels('manual');
yticklabels(y_values);
Pavl M.
2024년 11월 21일 11:52
편집: Pavl M.
2024년 11월 21일 11:57
xmesh1 = linspace(-1,0,10);
xmesh2 = linspace(0,1,10);
xmesh = [xmesh1,xmesh2];
yinit = [0 1 0 1 0 1 0 1];
init = bvpinit(xmesh,yinit);
sol = bvp5c(@f, @bc, init)
figure
plot(-abs(sol.y(2,:)),sol.x,'b-o',-abs(sol.y(3,:)),sol.x,'r-o')
ylim([-1 1]);
y_values = [-1:0.2:1];
ha = gca;
set(ha, 'ytick', y_values);
yticklabels('manual');
yticklabels(y_values);
%line([1 1], [0 1], 'Color', 'k')
% legend('y1','y3')
title('A Three-Point 8 values BVP Solved with bvp5c')
xlabel('u')
ylabel('y')
% xlabel({'x', '\lambda = 2, \kappa = 5'})
% ylabel('v(x) and C(x)')
function dydx = f(x,y,region) % equations being solved
W=1;alpha=1;M=2;k1=1;k2=1;k3=1;k4=1;k=1; Ps=1;Po=1;R1=0;R2=2;
omega=1;
us = y(1);
usy = y(2);
uo = y(3);
u0y = y(4);
thetas = y(5);
thetasy = y(6);
thetao = y(7);
thetaoy = y(8);
dydx = zeros(8,1);
switch region
case 1 % x in [-1 0]
dydx(1) = usy;
dydx(2) = (M^2 + 1/k2)*us - alpha*Ps*R2;
dydx(3) = u0y;
dydx(4) = (M^2 + 1/k1 + 1i*omega*R2)*uo - alpha*Po*R2; % 1/K2 ?
dydx(5) = thetasy+thetas;
dydx(6) = k1*usy^2;
dydx(7) = thetaoy;
dydx(8) = k*thetao - k3*thetasy*thetaoy;
case 2 % x in [0 1]
dydx(1) = usy;
dydx(2) = (M^2 + 1/k1)*us - Ps*R1;
dydx(3) = u0y;
dydx(4) = (M^2 + 1/k1 + 1i*omega*R1)*uo - Po*R1;
dydx(5) = thetasy;
dydx(6) = k2*usy^2;
dydx(7) = thetaoy;
dydx(8) = k*thetao - k4*thetasy*thetaoy;
end
end
function res = bc(YL,YR)
mu1=1; mu2=1; k1=1; k2=1;
res = [YL(1,1)
YL(3,1)
YL(5,1)
YL(7,1)
YR(1,2)-1
YR(3,2)-1
YR(5,2)-1
YR(7,2)
YR(1,1)-YL(1,2)
mu1*YR(2,1)-mu2*YL(2,2)
YR(3,1)-YL(3,2)
mu1*YR(4,1)-mu2*YL(4,2)
YR(5,1)-YL(5,2)
k1*YR(6,1)-k2*YL(6,2)
YR(7,1)-YL(7,2)
k1*YR(8,1)-k2*YL(8,2)];
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!