help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: plotting mulitple variables vs y


From: Ben Abbott
Subject: Re: plotting mulitple variables vs y
Date: Tue, 23 Apr 2013 16:19:35 -0400

On Apr 23, 2013, at 4:01 PM, Kirk wrote:

> From: Ben Abbott <address@hidden>
> To: Kirk <address@hidden> 
> Cc: "address@hidden" <address@hidden> 
> Sent: Tuesday, April 23, 2013 11:25 AM
> Subject: Re: plotting mulitple variables vs y
> 
> 
> On Apr 23, 2013, at 12:01 PM, Kirk wrote:
> 
> > I am trying to plot 2 variables in an equation against the y value but it 
> > does not seem to be doing that for me in Octave.
> > my small example I came up with is this code below
> > 
> > z=0.1;
> > for x1 = 1:0.5:2
> > for x2 = 0:0.1:1.5
> > 
> > y = sqrt(x1+x2^2)+z;
> > hold on;
> > plot(y,x2);
> > end
> > hold off;
> > end
> > 
> > 
> > I don't know if there is an easier way or if my syntax is wrong but i get a 
> > plot but with no value points or a line connecting them.
> > Kirk
> 
> Does this do what you want?
> 
> z = 0.1;
> x1 = 1:0.5:2;
> x2 = 0:0.1:1.5;
> [x1, x2] = meshgrid (x1, x2);
> y = sqrt (x1 + x2.^2) + z;
> mesh (x1, x2, y)
> 
> Ben
> Ben thanks for the hint, I am more wanting to plot say y vs x1(for all value) 
> for the first value of x2 then increase the value of x2 by the number 0.5 and 
> plot y vs x1 for all vlaues of x1 and so on. So that in the end I end up with 
> say 3 lines from 0 to 1.5 in the x direction and there y values in the 
> vertical. SO this might come close but the mesh I believe is more of a 3d 
> plot. Thanks
> Kirk

Try ...

z = 0.1;
x1 = 1:0.5:2;
x2 = 0:0.1:1.5;
[x1, x2] = meshgrid (x1, x2);
y = sqrt (x1 + x2.^2) + z;
plot (x1.', y.')

Ben




reply via email to

[Prev in Thread] Current Thread [Next in Thread]