Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
strange result is there a simple way out

Subject: strange result is there a simple way out

From: David Edson

Date: 30 Apr, 2009 12:44:02

Message: 1 of 4

Hello dears,

I wrote the following function with the intension of generating a shape divided into k1 equal parts. Since I could not define the divided shape with a smooth curve, i did the what I did in Part II. I want to vary k1 from 1 to n. Unfortunately my approach only gave me what I wanted when k1=5. what is wrong that it does not work with another k1 value. Is there a way that a define a smooth function that does what I plan to do. Here is the function:


[t, b]=meshgrid((-pi/2):(pi/100):(pi/2),0:(pi/50):2*pi);
rx; ry ; rz;
k1=5; k2=-2; k3=2/30;
g=(ry/10)*(abs(sin(k1.*b/2))+ 2.^(k2.*t)- 2.^(k3.*t));
x=rx.*cos(t).*cos(b);
y=ry.*sin(t)+g;
z=rz.*cos(t).*sin(b);

for i=1:k1
x(b==(2*pi/k1)*i)=0;
z(b==(2*pi/k1)*i)=0; % part II
end
clf
mesh(x,y,z)
grid off
axis off
axis equal
axis ij


cheers,

TE

Subject: strange result is there a simple way out

From: Yi Cao

Date: 7 May, 2009 14:01:02

Message: 2 of 4

"David Edson" <tojadeb@example.com> wrote in message <gtc6ei$s7b$1@fred.mathworks.com>...
> Hello dears,
>
> I wrote the following function with the intension of generating a shape divided into k1 equal parts. Since I could not define the divided shape with a smooth curve, i did the what I did in Part II. I want to vary k1 from 1 to n. Unfortunately my approach only gave me what I wanted when k1=5. what is wrong that it does not work with another k1 value. Is there a way that a define a smooth function that does what I plan to do. Here is the function:
>
>
> [t, b]=meshgrid((-pi/2):(pi/100):(pi/2),0:(pi/50):2*pi);
> rx; ry ; rz;
> k1=5; k2=-2; k3=2/30;
> g=(ry/10)*(abs(sin(k1.*b/2))+ 2.^(k2.*t)- 2.^(k3.*t));
> x=rx.*cos(t).*cos(b);
> y=ry.*sin(t)+g;
> z=rz.*cos(t).*sin(b);
>
> for i=1:k1
> x(b==(2*pi/k1)*i)=0;
> z(b==(2*pi/k1)*i)=0; % part II
> end
> clf
> mesh(x,y,z)
> grid off
> axis off
> axis equal
> axis ij
>
>
> cheers,
>
> TE

What do you mean "it does not work with another k1 value"? I tried your code for several other k1 values. It seems work fine except I have to give rx, ry and rz values.

Yi

Subject: strange result is there a simple way out

From: David Edson

Date: 7 May, 2009 15:56:01

Message: 3 of 4



No, it is not possible to have k1 divided parts except k1=5. That is why i am puzzeled. check for example with k1 equals to 2,3,4,7... with a given rx; ry; rz or what ever values you want.



Yi Cao" <y.cao@cranfield.ac.uk> wrote in message <gtupiu$rl$1@fred.mathworks.com>...
> "David Edson" <tojadeb@example.com> wrote in message <gtc6ei$s7b$1@fred.mathworks.com>...
> > Hello dears,
> >
> > I wrote the following function with the intension of generating a shape divided into k1 equal parts. Since I could not define the divided shape with a smooth curve, i did the what I did in Part II. I want to vary k1 from 1 to n. Unfortunately my approach only gave me what I wanted when k1=5. what is wrong that it does not work with another k1 value. Is there a way that a define a smooth function that does what I plan to do. Here is the function:
> >
> >
> > [t, b]=meshgrid((-pi/2):(pi/100):(pi/2),0:(pi/50):2*pi);
> > rx; ry ; rz;
> > k1=5; k2=-2; k3=2/30;
> > g=(ry/10)*(abs(sin(k1.*b/2))+ 2.^(k2.*t)- 2.^(k3.*t));
> > x=rx.*cos(t).*cos(b);
> > y=ry.*sin(t)+g;
> > z=rz.*cos(t).*sin(b);
> >
> > for i=1:k1
> > x(b==(2*pi/k1)*i)=0;
> > z(b==(2*pi/k1)*i)=0; % part II
> > end
> > clf
> > mesh(x,y,z)
> > grid off
> > axis off
> > axis equal
> > axis ij
> >
> >
> > cheers,
> >
> > TE
>
> What do you mean "it does not work with another k1 value"? I tried your code for several other k1 values. It seems work fine except I have to give rx, ry and rz values.
>
> Yi

Subject: strange result is there a simple way out

From: Yi Cao

Date: 7 May, 2009 16:57:01

Message: 4 of 4

David,

It is still not clear to me what do you mean "it is not possible to have k1 divided parts except k1=5."?

I did try k1 = 2, 3, ..., all works without errors although I do not know whether the results are right ot not.

HTH
Yi

"David Edson" <tojadeb@example.com> wrote in message <gtv0ah$2kt$1@fred.mathworks.com>...
>
>
> No, it is not possible to have k1 divided parts except k1=5. That is why i am puzzeled. check for example with k1 equals to 2,3,4,7... with a given rx; ry; rz or what ever values you want.
>
>
>
> Yi Cao" <y.cao@cranfield.ac.uk> wrote in message <gtupiu$rl$1@fred.mathworks.com>...
> > "David Edson" <tojadeb@example.com> wrote in message <gtc6ei$s7b$1@fred.mathworks.com>...
> > > Hello dears,
> > >
> > > I wrote the following function with the intension of generating a shape divided into k1 equal parts. Since I could not define the divided shape with a smooth curve, i did the what I did in Part II. I want to vary k1 from 1 to n. Unfortunately my approach only gave me what I wanted when k1=5. what is wrong that it does not work with another k1 value. Is there a way that a define a smooth function that does what I plan to do. Here is the function:
> > >
> > >
> > > [t, b]=meshgrid((-pi/2):(pi/100):(pi/2),0:(pi/50):2*pi);
> > > rx; ry ; rz;
> > > k1=5; k2=-2; k3=2/30;
> > > g=(ry/10)*(abs(sin(k1.*b/2))+ 2.^(k2.*t)- 2.^(k3.*t));
> > > x=rx.*cos(t).*cos(b);
> > > y=ry.*sin(t)+g;
> > > z=rz.*cos(t).*sin(b);
> > >
> > > for i=1:k1
> > > x(b==(2*pi/k1)*i)=0;
> > > z(b==(2*pi/k1)*i)=0; % part II
> > > end
> > > clf
> > > mesh(x,y,z)
> > > grid off
> > > axis off
> > > axis equal
> > > axis ij
> > >
> > >
> > > cheers,
> > >
> > > TE
> >
> > What do you mean "it does not work with another k1 value"? I tried your code for several other k1 values. It seems work fine except I have to give rx, ry and rz values.
> >
> > Yi

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us