-1

Good afternoon, I have this code in Matlab plotting a 2 y axis curve also known as plotyy. I am interested in finding out why do I get two curves instead of one curve even though they are plotting the same curve?

    r=1.1;
    M=0.00063291;
    D=-0.05;
    kappa=0.5;
    SQ=sqrt(-(0.5*D)^2 +M);
    L=1001.6288;
    z=0:0.001:L;
    A=-kappa*SQ.*(z-L);
    B=((sqrt(M)*r)+(D/2))/(SQ);
    C=acot(B);
    E=SQ*cot(A+C);
    Pplus=E-(D/2);
    Pminus=M./Pplus;
    P0=Pplus+Pminus+D;
    gamma=20;%\W\km
    Pp=0.3159;
    A=gamma.*Pp;%\W
    y1=kappa.*1000.*(Pplus+Pminus);
    y2 =y1./A;
    figure
    hax=axes;
    [ax,p1,p2] = plotyy(z,y1,z,y2,'plot','plot');
     set(ax,{'ycolor'},{'k';'k'}) 
    set(ax,{'fontsize'},{18;18})
     set(p1,'linewidth',3)% to change the first line
     set(p2,'linewidth',3) % to change the second line
     set(p1,'Color','b')% to change the first line
     set(p2,'Color','b') % to change the second line
    str = sprintf('D = %.6f  ',D);
    title(str);
    ylabel(ax(1),'K_{SBS}(km)','fontsize',18,...
     'Color','k') % label left y-axis
    ylabel(ax(2),'K_{SBS}( \gamma P )','fontsize',18,...
    'Color','k') % label right y-axis
    xlabel(ax(2),'z(m)','fontsize',18,...
    'Color','k')% label x-axis
    set(ax(1),'XLim',[0 L])
    set(ax(2),'XLim',[0 L])
% M=0.000576;
% D=-0.0468;
% L=1012.1779;
% Pp=0.5;

But if i choose the values found in the last 4 lines of the code, I do not get that. I just want to know why? Thank you

  • 2
    You get two curves because you're plotting two curves. `plotyy(z,y1,z,y2,'plot','plot')`. You define `y2` to be `y1 ./ A` so it's going to be different...The scaling of the two axes that `plotyy` creates can be different. – Suever May 20 '16 at 04:55
  • I understand but I think I should be more clearer, why can't they be on top of each other though they represent the same function but just with different constant? – Abed Libnan Haidar May 22 '16 at 02:07

1 Answers1

1

The lines are on top of each other because your y axis have different limits and range. Use this with the values in your code to see what I mean:

set(ax(1),'YLim',[25.072 25.472])
set(ax(2),'YLim',[3.97 4.03])

Although I must say I can't see any point for that.

EBH
  • 10,350
  • 3
  • 34
  • 59