×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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.

Students Click Here

Need little coding help

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

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

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

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.

peace
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.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login



News


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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close