changing the scale on the Y axis
Afficher commentaires plus anciens
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 commentaires
Torsten
le 11 Juil 2024
What is u, what is y and what is R_I in your code ?
mallela ankamma rao
le 11 Juil 2024
So y is the independent variable x in your code. But what function is plotted and which parameter is varied ?
Once you have found this, you can simply plot independent and dependent variables reversed:
plot(sol.y(2,:),sol.x,'b-o',sol.y(3,:),sol.x,'r-o')
instead of
plot(sol.x,sol.y(2,:),'b-o',sol.x,sol.y(3 ,:),'r-o')
But note that the solutions are complex-valued; thus it is only possible to plot abs(sol.y), real(sol.y) or imag(sol.y).
mallela ankamma rao
le 11 Juil 2024
Déplacé(e) : Torsten
le 11 Juil 2024
But the graphs are reversed. I need graphs like the following graph sir and X range is 0 to 1 sir. Please Give me some suggestions sir.
If you know that your sol.y(2,:) and sol.y(3,:) are plotted in the article (real or imaginary part or absolute value) and your plot is different, then there must be something different in your code compared to the code that the authors used. So the only advice I can give is to compare your code to the mathematical equations.
mallela ankamma rao
le 12 Juil 2024
mallela ankamma rao
le 12 Juil 2024
Réponses (2)
ScottB
le 11 Juil 2024
ylim([-1 1]);
y_values = [-1:0.2:1];
ha = gca;
set(ha, 'ytick', y_values);
yticklabels('manual');
yticklabels(y_values);
1 commentaire
mallela ankamma rao
le 11 Juil 2024
Mr. Pavl M.
le 21 Nov 2024
Modifié(e) : Mr. Pavl M.
le 21 Nov 2024
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
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




