Asked by:
Convert Matlab Math Trig into C#
Question

All replies

Hi pianoboyCoder,
It will be beneficial to resolve the issue if you add comment to describe the following code.
theta=0:pi/180:2*pi;
In addition, you could refer to Math method in .net framework, which provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions. Such as.
// PI var pi = Math.PI; //Cos var costheta = Math.Cos(pi);
Best regards,
Zhanglong
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com. Proposed as answer by Stanly Fan Wednesday, February 13, 2019 2:39 AM

I admit … I know NOTHING about MATLAB, but predicated on the information at
https://www.tutorialspoint.com/matlab/matlab_colon_notation.htm
I would think the C analog would be something like …
const double increment = Math.PI/180.0; const double upperLimit = 2.0 * Math.PI; double cosTheta; for (double theta = 0; theta <= upperLimit; theta += increment) cosTheta = Math.Cos(theta);
