prompt='input the module > Module = ';
m=input(prompt);
prompt='input the number of teeth > Teeth Number = ';
T=input(prompt);
prompt='input the pressure angle at pitch radius > Pressure Angle(deg) = ';
pre_ang=input(prompt);
prompt='input the addendum coefficient > a = ';
a=input(prompt);
% Evaluate the "Pitch Radius"
rp = (m*pi)/2;
% Evaluate the "Base Radius"
rb = rp*cos(degtorad(pre_ang));
% Evaluate the "Tip Radius"
rt = rp + a*m;
% Evaluate the "Circular Pitch Tooth Thickness"
cptt = (pi*m)/2;
% Evaluate the "Involute Angle at pitch point (theta)"
theta_pitch = tan(degtorad(pre_ang))- degtorad(pre_ang);
prompt= 'input the slice number on involute curve= ';
n_slice=input(prompt);
deltar = (rt-rb)/n_slice;
figure;
hold on;
for i = 1:n_slice
x = i*deltar;
R(i) = x+rb;
% Evaluate the pressure angle at Ri
theta(i) = acos(rb/R(i));
%Evaluate the involute angle at Ri
inv_ang(i)= tan(theta(i))-theta(i);
% Evaluate the Circular Tooth Thickness at Ri
ctt(i) = (2.*R(i))*((0.5*cptt/rp) + theta_pitch - inv_ang(i));
B = 0.5*ctt(i)/R(i);
%Eventually, Coordinates might be evaluated
X(i) = R(i)* sin(B);
Y(i) = R(i)* cos(B);
plot(X(i),Y(i),'r+')
end
% Is that right? I would use push.back by using C++, I am confused if it is need in here and please tell me how many ways of doing this, and the names. sincerely !

 採用された回答

dpb
dpb 2015 年 11 月 12 日

0 投票

In Matlab, one generally avoids looping...once you've got the two starting positions and the number of points desired, then something like...
R=linspace(rb,rt,n_slice); % vector length N between [rb rt]
% Evaluate the pressure angle at Ri
theta = acos(rb./R);
%Evaluate the involute angle at Ri
inv_ang = tan(theta)-theta;
% Evaluate the Circular Tooth Thickness at Ri
ctt = 2*R.*(0.5*cptt./rp + theta_pitch-inv_ang);
B = 0.5*ctt./R;
%Eventually, Coordinates might be evaluated
X = R.*sin(B);
Y = R.*cos(B);
plot(X,Y,'r+')
I think I did the translation correctly; you'll want to check carefully, of course...

4 件のコメント

Ender Rencuzogullari
Ender Rencuzogullari 2015 年 11 月 12 日
編集済み: Ender Rencuzogullari 2015 年 11 月 12 日
I would like to ask that why should I avoid the loops ? Beacause, the result is the same. thanks by the way
dpb
dpb 2015 年 11 月 12 日
The simple answer is "because!". :) Seriously, the strength of Matlab and a primary (albeit not only) reason for its existence is the "MATrixLABoratory" portion of its abilities. For one thing, the implementation as written above without the loop much more nearly approximates the actual algorithm, removing the "noise" of the subscripting from the code leaving the essence. This makes understanding the code simpler and is less coding effort in the implementation, besides.
Secondly, although it won't show up for such a simple problem as here, that Matlab is interpreted rather than compiled, the internal array operations are implemented with optimized BLAS libraries where as the for loop is executed linearly and hence will typically be slower. While TMW has made great strides in its JIT optimizer and so the bottlenecks aren't what they once were, it's still a general truism that vectorized code will outperform procedural looping constructs.
One trades memory for performance. See the documentation section on "Techniques for Improving Performance" under the "Advanced Software Development" section; it has general guidelines and a link to "Vectorization".
Ender Rencuzogullari
Ender Rencuzogullari 2015 年 11 月 12 日
Thanks a lot :)
dpb
dpb 2015 年 11 月 12 日
You're certainly welcome! Once you've become a little more familiar with and adept w/ Matlab you'll probably find reverting to coding with loops and all very frustrating. My background is Fortran and while it's progressing towards many areas of array syntax and even dynamic allocation on assignment, it's still light years from the ease of Matlab. Of course, for absolute performance, there's generally a cost to be paid still with Matlab, but unless it's an extremely large or complex application, chances are that Matlab will be "fast enough!".

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2015 年 11 月 12 日

コメント済み:

dpb
2015 年 11 月 12 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by