help-octave
[Top][All Lists]

## Re: Plotiing a 3d function

 From: Søren Hauberg Subject: Re: Plotiing a 3d function Date: Sun, 02 Jul 2006 11:51:06 +0200

```Hi,
Are you sure that's a 3d function? It looks 1d to me. Anyway, you can
plot in 3d in several ways. If you want to plot points you can use the
'plot3' function, or if you want to draw a surface you can use the
'mesh' function.

By the way I think you can vectorize you code. I haven't tested this but
you should be able to use this code instead:

n = 2;
j = 1:n-1;
y = sum( 100*(x(j).^2-x(j+1)).^2+(x(j)-1).^2 );

Good luck,
Søren

P.S. you shouldn't use the word 'sum' as a variable, because Octave
provides a function called sum that you overwrite with your variable.

søn, 02 07 2006 kl. 01:21 -0300, skrev Rafael Almeida:
> Hello,
>
> I need to plot a function, more specifically this one
> function y = rosenbrock(x)
>     n = 2;
>     sum = 0;
>     for j = 1:n-1;
>         sum = sum+100*(x(j)^2-x(j+1))^2+(x(j)-1)^2;
>     endfor
>     y = sum;
> endfunction
>
> But I can't figure out how can I plot it. It's suposed to be a 3d
> graph. The fplot function seems to do only 2d. Or at least I couldn't
> figure out how to do it. I need to plot it using level curves also.
> Could anyone help me out on this one?
>
> thanks.
> _______________________________________________
> Help-octave mailing list