|
On Dec 15, 1:25=A0pm, Dave <dspg...@netscape.net> wrote:
> On Dec 15, 1:14=A0pm, Dave <dspg...@netscape.net> wrote:
>
>
>
> > On Dec 15, 10:07=A0am, "mlt" <a...@asd.com> wrote:
>
> > > Hm seems that crossing with =A0(0,1,0) does not give the correct resu=
lt
> > > either. Here is the result when I cross with (0,0,1):
>
> > >http://img132.imageshack.us/img132/755/matsf2.jpg
>
> > > Only the normals on the top are correct, and for some reason the grow=
larger
> > > when the x-values increase!
>
> > > and the code:
>
> > > step =3D 0.5;
> > > x=3D0:step:9*pi/2;
> > > z_dim =3D zeros(1,length(x));
> > > y_dim =3D ones(1,length(x));
> > > f =3D sin(x);
> > > plot(x, f)
> > > hold on
>
> > > FX =3D gradient(f);
> > > T =3D [x;FX;z_dim];
> > > Y =3D [z_dim; z_dim; y_dim];
>
> > > Normal =3D cross(T,Y);
> > > NX =3D Normal(1,:);
> > > NY =3D -1*Normal(2,:);
>
> > > quiver(x, sin(x), NX, NY)
>
> > > "mlt" <a...@asd.com> wrote in message
>
> > >news:49466f85$0$90267$14726298@news.sunsite.dk...
>
> > > > Don't you mean:
>
> > > > normal =3D cross(T, (0,1,0))
>
> > > > since the function only have 1 variable (only defined over the x do=
main
> > > > and values belong to the the domain).
>
> > > > "Dave" <dspg...@netscape.net> wrote in message
> > > >news:fd16be8f-771a-46d4-bf84-29b4f17bb20b@t26g2000prh.googlegroups.c=
om...
> > > > Wouldn't you just form the cross product of the tangent vector you
> > > > already have and the k vector where k is a vector perpendicular to =
the
> > > > plane of your computer monitor. So form the cross product of (Tx,Ty=
,0)
> > > > and (0, 0, 1).
>
> > > > Cheers,
> > > > Dave
>
> > > > On Dec 15, 9:29 am, "mlt" <a...@asd.com> wrote:
> > > >> I have computed the gradient of the function sin(x):
>
> > > >> x=3D0:0.1:5*pi/2;
> > > >> f =3D sin(x);
> > > >> FX =3D gradient(f);
>
> > > >> I would now like to plot 'f' and the corresponding 'normals' (not
> > > >> tangents):
>
> > > >> quiver(x, sin(x), x, FX)
>
> > > >> But it looks more like I get the tangents.
>
> > > >> How do I determine the normals and plot those instead?
>
> > You're calculating the components of the tangent vector incorrectly.
> > The gradient() calculates df/dx. From your code you're setting df =3D F=
X
> > therefore dx =3D1 for all your vectors.
>
> > Note: You're not sampling the function quickly enough to get accurate
> > estimates of the derivative. Also gradient doesn't know about the
> > scaling of the x values. To get more realistic values try increasing
> > the sampling to 0.01 i.e. x=3D 0:0.01:2*pi;
> > f=3Dsin(x)
> > FX=3D gradient(f);
> > FX=3DFX/(x(2)-x(1)); %Note x(1) =3D 0 so you can just divide by x(2);
>
> > tan_vec =3D [ones(size(FX))' FX'];
> > quiver(x,sin(x), tan_vec(:,1)', tan_vec(:,2)');
>
> > To make it more viewable you can try:
> > tan_vec =3D tan_vec/3; %scale the tangent vectors by a fixed quantity.
> > Ind=3D1:10:length(x); % Subsample the indices - only plot every 10 th
> > sample
> > quiver(x(Ind),sin(x(Ind)), tan_vec(Ind,1)', tan_vec(Ind,2)');
>
> > Cheers,
> > David
>
> Sorry,
> To scale the vectors try the following:
> quiver(x(Ind),sin(x(Ind)), tan_vec(Ind,1)', tan_vec(Ind,2)', 0.2);
>
> Cheers,
> Dave
To plot the normals do the following:
tan_vec =3D[tan_vec zeros(size(tan_vec,1),1)];
Z=3Dzeros(size(tan_vec,1),3);
Z(:,3)=3D1; %create z direction vectors
nor=3Dcross(Z,tan_vec);
quiver(x,sin(x), nor(:,1)', nor(:,2)', 0.05);
Cheers,
David
|