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
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
RE: Need little coding help
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
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
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
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
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
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
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
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
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
"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
Fe (IronX32)