Si2:Aula4

De WikiLICC
Ir para: navegação, pesquisa

Quádrica

n1=20;
n2=20;

for i=1:n1
  s= (i-1)/(n1-1);
  x(i)= -1*(1-s) + 1*s;
end
for i=1:n2
  s= (i-1)/(n2-1);
  y(i)= -1*(1-s) + 1*s;
end

for i=1:n1
  for j=1:n2
   z(i,j)= x(i)^2 - y(j)^2;
//    grad2d( x(i), y(j) )
    p(i,j)=-0.7;
  end
end

plot3d( x, y, z)
//plot3d( x, y, p)

contour( x, y , z , 11)

Vetor 2d

function vetor2d( xi,yi, xf,yf )
 plot( [xi;xf], [yi;yf] )
endfunction

Gradiente

function grad2d( x,y )
 
 fx= 2*x;
 fy=-2*y;  
 plot( [x;x+fx], [y;y+fy] )
 
endfunction

Outro Exemplo

N =10;
x1=-2;  x2= 2;
y1=-2;  y2= 2;

for i=1:N
  for j=1:N
    r = (i-1)/(N-1);
    s = (j-1)/(N-1);    
    x(i,j)=x1 *r + x2*(1-r);
    y(i,j)=y1 *s + y2*(1-s);

    xv(i) =x(i,j);
    yv(j) =y(i,j);
    z(i,j)=1-x(i,j)-y(i,j);
  end
end

surf(x,y, z,'facecol','interp')  

fig = gcf();
fig.color_map=coolcolormap(32);
contour2d( xv,yv, z,20)