changing the scale on the Y axis
3 views (last 30 days)
Show older comments
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 Comments
Answers (2)
ScottB
on 11 Jul 2024
ylim([-1 1]);
y_values = [-1:0.2:1];
ha = gca;
set(ha, 'ytick', y_values);
yticklabels('manual');
yticklabels(y_values);
Pavl M.
on 21 Nov 2024 at 11:52
Edited: Pavl M.
on 21 Nov 2024 at 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 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!