Alireza
Alireza

Reputation: 311

plot from data not a function

If you plot

sin(x*y)  

you see some lines.
Now if u have all coordinates of all points of these lines and want to plot theme
(connecting dots without using sin(x*y) function), how is possible?
by this codes, i try to obtain coordinates of each 'x'(beta-bar) for each 'lam' and
save roots in a matrix.

clc; clear;    
lmin=0.8;       lmax=2.5;  
bmin=1;            bmax=1.5;  
lam=linspace(lmin,lmax,100);  
for n=length(lam):-1:1  
    increment=0.001;  tolerence=1e-14; xstart=bmax-increment;  
    x=xstart;  
    dx=increment;  
    m=0;  
    while x > bmin  
        while dx/x >= tolerence  
            if sign(f(lam(n),x))*sign(f(lam(n),x-dx))<0  
                dx=dx/2;  
            else  
                x=x-dx;  
            end  
        end  
        m=m+1;  
        r(m,n)=x;  
        dx=increment;  
        x=0.999*x;  
    end  
end  

    figure  
hold on,plot(lam,r(1,:),'b')  
plot(lam,r(2,:),'c')  
plot(lam,r(3,:),'r')  
xlim([lmin,lmax]);ylim([bmin,bmax]),  
xlabel('\lambda(\mum)'),ylabel('\beta-bar')  

and
function y=f(x,y)
y=sin(4*x*y);
end

what is wrong with it?
how to separately plot each line?

Upvotes: 0

Views: 886

Answers (2)

user492238
user492238

Reputation: 4084

use the plot() command. From the Matlab docu ('help plot' on the command line):

'PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X.'

So while plot(sin(X,Y)) used the plot(X) overload of the function, you will use the plot(X,Y) overload.

Upvotes: 0

Vivek Goel
Vivek Goel

Reputation: 24140

Use plot(X1,Y1,...,Xn,Yn) See link for more details http://www.mathworks.com/help/techdoc/ref/plot.html

Upvotes: 0

Related Questions