×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Need little coding help

## Need little coding help

(OP)

The code below plots 'k' along the y-axis and 'theta' along the x-axis.

I would like help on the following, for which I do not know how to write out the code in MATLAB:
1. I want to extract only those 'theta' values corresponding to integer values of 'k'
2. Then, use the above 'theta' values and solve for corresponding 'alpha' values from the equation:
d*sin(alpha) - r*sin(theta-alpha) = 0
3. I would also like to print an array of x and y coordinates corresponding to the above theta values
x = r*cos(theta) and y = r*sin(theta)

n=12;
d = 200;
r = 3200;
dbyr=d/r;
theta=0:0.0001:2*pi;
k=(n/(2*pi))*(theta+dbyr*sin(theta));
plot(theta,k)

Thanks.

### RE: Need little coding help

(OP)
No, not for school assignment.

### RE: Need little coding help

(OP)

k does have integer values: 1,2,.......,12. The y-axis of the plot generated shows them.

n=12;
d = 200;
r = 3200;
dbyr=d/r;
theta=0:0.0001:2*pi;
k=(n/(2*pi))*(theta+dbyr*sin(theta));
plot(theta,k)

Thanks.

### RE: Need little coding help

Did you not take trig in high school? If this is not homework, why must you do this in MATLAB, since the solutions for theta can be found by inspection?x`

TTFN
FAQ731-376: Eng-Tips.com Forum Policies Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Need little coding help

OK, I've watsed a minute on this. theta is in integer multiples of 0.0001

k is an integer divided by pi times (x.sin(theta)+theta)

dividing things that aren't pi, by pi, rarely results in integers.

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

### RE: Need little coding help

Unless his equation is incorrect, Theta as multiples of pi result in integer values of k, since the sin term gets zeroed, leaving n*m*pi/2*pi = 6m, since n=12.

TTFN
FAQ731-376: Eng-Tips.com Forum Policies Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Need little coding help

To be precise, there is exactly one integer value in k. You can find it like so:

for j=1:62832
if(round(k(j)) == k(j))
j
end
end

Unsurprisingly, it's the value for when theta is 0. As already stated, everything else gives you an expression with pi, which is never going to be exactly integer.

To suggest "k does have integer values: 1,2,.......,12. The y-axis of the plot generated shows them." is wrong - the plot shows a continuous line. The values of k are discrete, and are never exactly integer (except at the origin). If you want values that are "close enough" to integers, you need to use numerical methods. Time to rethink the problem you're trying to solve. Which is?

### RE: Need little coding help

IRStuff, the input is never pi, 2*pi or 3*pi. The input is "0:0.0001:2*pi;". So 0 is in but the closest to pi you get is 3.1416 and oddly enough, even the last input is not 2*pi (Matlab rounds it to something a bit surprising - I can't remember exactly what).

I agree, if the input were exactly pi, 2*pi or 3*pi, the equation would give a rational result since the sin term goes to zero and the remaining theta term cancels with the pi on the denominator.

### RE: Need little coding help

This isn't helping the OP much, but then if you are talking about mathematics and you aren't using the words correctly then you either get with the program or you get out of the kitchen.

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

### RE: Need little coding help

The OP is wandering aimlessly. Look at what he says he wants:
"I want to extract only those 'theta' values corresponding to integer values of 'k' " The fact that he can't even figure out his own Matlab code suggests that his vector for theta is arbitrarily constructed.

TTFN
FAQ731-376: Eng-Tips.com Forum Policies Need help writing a question or understanding a reply? forum1529: Translation Assistance for Engineers

### RE: Need little coding help

The OP's question is illogical and makes no sense. Fe (IronX32)

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

#### Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a partâ€™s function at the center of their design considerations. Download Now
Industry Perspective: Education and Metal 3D Printing
Metal 3D printing has rapidly emerged as a key technology in modern design and manufacturing, so itâ€™s critical educational institutions include it in their curricula to avoid leaving students at a disadvantage as they enter the workforce. Download Now

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!