Showing posts with label fun. Show all posts
Showing posts with label fun. Show all posts

Wednesday, July 17, 2013

plotting 3D vector field in MATLAB in many different ways

Recently I read post from Dr. Doug Hull's blog:

http://blogs.mathworks.com/videos/2009/10/23/basics-volume-visualization-19-defining-scalar-and-vector-fields/

I liked this video tutorial so much and I really felt that should finish the 'homework' assigned at the very end. So I spent sometime on it and here are my code and figures.

clear;close all;clc;
load wind
speed=sqrt(u.*u+v.*v+w.*w);
%%
figure(1)
scatter3(x(:),y(:),z(:),[],speed(:))
%%
figure(2)
slice(x,y,z,speed,[],[],[5 10 15])
zlim([0 20])
%%
figure(3)
[xs, ys]=meshgrid(60:140, 20:60);
zs=20*ys./xs;
slice(x,y,z,speed,xs,ys,zs)
%%
figure(4)
contourslice(x,y,z,speed,[],[],[5 10 15],20)
zlim([0 20])
view(3)

%%
figure(5)
fv1=isosurface(x,y,z,speed, 10);
fv2=isosurface(x,y,z,speed, 20);
fv3=isosurface(x,y,z,speed, 30);
h1=patch(fv1);
h=patch(fv2);
h3=patch(fv3);
set(h1,'FaceColor',[1, 0.6, 0])
set(h1,'EdgeColor','none')

set(h,'FaceColor',[0, 0.5, 0.5])
set(h,'EdgeColor','none')

set(h3,'FaceColor',[1, 0.4, 1])
set(h3,'EdgeColor','none')
camlight;
lighting gouraud
view(3)

%% 
figure(6)
quiver3(x,y,z,u,v,w);

%%
figure(7)
[cx,cy,cz]=meshgrid([70 80 90 100 110 120], [20 30 40 50 60],[0 5 10 15]);
coneplot(x,y,z,u.*100,v.*100,w.*100,cx,cy,cz,speed);
% set(h, 'edgecolor','none')
shading interp;
view(3)

%%
figure(8)
streamline(x,y,z,u,v,w,80,40,10)
hold on
plot3(80,40,10, 'bo')
view(3)

%%
figure(9)
[sx,sy,sz]=meshgrid(100,[20 30 40], [5 10]);
streamline(x,y,z,u,v,w,sx,sy,sz)
hold on
plot3(sx(:),sy(:),sz(:),'bo')
view(3)

%%
figure(10)
streamslice(x,y,z,u,v,w,[],[],1)
view(3)

%%
figure(11)
streamtube(x,y,z,u,v,w,sx,sy,sz)
shading interp;
view(3)
%%
figure(12)
h=streamribbon(x,y,z,u,v,w,sx,sy,sz);
shading interp;
view(3)


Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12



Monday, February 15, 2010

Give curves random color, just for fun

A few days ago, I drew some curves on a same plot. And now I want to randomize the curve color.

Because the color syntax can be expressed as letters such as k, g, b etc. and also as a three element row, which indicate the RBG mode, such as [1, 0, 1], [0.1,0.7, 0.4] and so on.

So here I wrote a M-file to randomize the color and plot 10 curves in each subplot.

%this code produce a three element row
%which can be used to specify a random color
%created on 02/15/2010
function rndclr=f()
rndclr=[rand, rand, rand];
%this code draws some curves
%of random color
clf
t=0:0.01:100*pi;
for j=1:9
for i=1:10
hold all;
x=(i+2)*cos(t/i)+cos((i-1)*t);
y=i*sin(t/i)+sin((i-3)*t);
subplot (3,3,j);
plot(x,y,'color',rndclr)
axis('equal')
axis off
end
end

And here is the figure:

Yahoo META Tag


I'm not sure if this will work or not. Let's see!

Factorial in Matlab

To calculate the factorial of n in Matlab, that's simple:
factorial (n)
will do it.

Sunday, February 14, 2010

plotting some curves, just for fun

%this code draws some curves
clf
t=0:0.01:100*pi;
for i=1:10
    hold all;
x=(i+2)*cos(t/i)+cos((i-1)*t);
y=i*sin(t/i)+sin((i-3)*t);
plot (x,y,'red')
end
axis('equal')




Friday, February 5, 2010

3D Random walk

% random walk
x=[];
y=[];
z=[];
x(1)=0;
y(1)=0;
z(1)=0;
for i=1:20000
J=rand*6;
if J<1>1)&(J<2)>2)&(J<3)>3)&(J<4)>4)&(J<5)
x(i+1)=x(i);
y(i+1)=y(i);
z(i+1)=z(i)+1;
else
x(i+1)=x(i);
y(i+1)=y(i);
z(i+1)=z(i)-1;
end
end

plot3(x,y,z)

Result:

2D Random walk program

Why I want to do this?
http://en.wikipedia.org/wiki/Random_walk

Here's the code I wrote:

% random walk
x=[];
y=[];
x(1)=0;
y(1)=0;
for i=1:100000
J=rand;
if J<0.25
x(i+1)=x(i)+1;
y(i+1)=y(i);
elseif (J>0.25)&(J<0.5)
x(i+1)=x(i)-1;
y(i+1)=y(i);
elseif (J>0.5)&(J<0.75)
x(i+1)=x(i);
y(i+1)=y(i)+1;
else
x(i+1)=x(i);
y(i+1)=y(i)-1;
end
end

plot(x,y)

And here are the figure I got:

Saturday, June 27, 2009

Pictures of magic matrix (50x50)

Plotmatrix: This one is 5x5
area:

bar:

comet:

compass:

contour:

contourf:

image:

imagesc:

loglog:

mesh:

pcolor:

plot:

polar:

ribbon:

semilogx

semilogy

spy

stairs

stem3

stem

surf

my-alpine and docker-compose.yml

 ``` version: '1' services:     man:       build: .       image: my-alpine:latest   ```  Dockerfile: ``` FROM alpine:latest ENV PYTH...