Basic Trigonometry Operations in MATLAB Get Certified
MATLAB provides a variety of built-in trigonometric functions to perform operations such as calculating sine, cosine, tangent, and their inverses. These functions work with both degrees and radians, making them versatile for different types of problems.
Basic Concepts
In MATLAB, trigonometric functions operate on angles provided in radians by default. To work with degrees, you can use the degree-specific functions or convert degrees to radians using deg2rad.
% Basic trigonometric functions
theta = pi/4; % Angle in radians (45°)
sin_val = sin(theta);
cos_val = cos(theta);
tan_val = tan(theta);
disp(sin_val);
disp(cos_val);
disp(tan_val);
Expected output:
0.7071 0.7071 1.0000
You can use deg2rad to convert angles in degrees to radians:
% Conversion from degrees to radians
theta_deg = 45;
theta_rad = deg2rad(theta_deg);
sin_val = sin(theta_rad);
disp(sin_val);
Expected output:
0.7071
Alternatively, you can use the degree-specific functions sind, cosd and tand that accept angles directly in degrees:
% Using angles directly in degrees
theta_deg = 45;
sin_val = sind(theta_deg);
cos_val = cosd(theta_deg);
tan_val = tand(theta_deg);
disp(sin_val);
disp(cos_val);
disp(tan_val);
Expected output:
0.7071 0.7071 1
Inverse Trigonometric Functions
MATLAB also provides functions to compute the inverse of trigonometric values. The output is in radians by default:
% Inverse trigonometric functions
x = 0.7071;
angle_rad = asin(x);
angle_deg = rad2deg(angle_rad);
disp(angle_rad); % radians
disp(angle_deg); % degrees
Expected output:
0.7854 45.0000
Handling Complex Results
Trigonometric functions in MATLAB can handle complex numbers, providing results in the complex plane:
% Trigonometric functions with complex numbers
z = 1 + 1i; % Complex number
sin_z = sin(z);
disp(sin_z);
Expected output:
1.2985 + 0.6349i
Common Trigonometric Operations
Hyperbolic Trigonometry
MATLAB supports hyperbolic trigonometric functions:
% Hyperbolic sine and cosine
x = 1;
sinh_val = sinh(x);
cosh_val = cosh(x);
disp(sinh_val);
disp(cosh_val);
Expected output:
1.1752 1.5431
Finding Angles
Using atan2 to find angles in the full range [−π, π]:
% Finding angles with atan2
y = 1;
x = 1;
angle = atan2(y, x);
disp(angle);
Expected output:
0.7854
Useful MATLAB Functions for Trigonometry
A = sin(B) returns the sine of B (in radians). Works element-wise on arrays.A = cos(B) returns the cosine of B (in radians). Works element-wise on arrays.A = tan(B) returns the tangent of B (in radians). Works element-wise on arrays.A = asin(B) computes the inverse sine (arcsin) of B; result is in radians.A = acos(B) computes the inverse cosine (arccos) of B; result is in radians.A = atan(B) computes the inverse tangent (arctan) of B; result is in radians.A = atan2(Y,X) computes the four-quadrant inverse tangent of Y and X.A = deg2rad(B) converts degrees to radians.A = rad2deg(B) converts radians to degrees.Practice Questions
Test Yourself
1. Find the sine, cosine, and tangent of a 30-degree angle.
2. Compute the angle (in degrees) whose tangent is 1.
3. Use atan2 to find the angle for y = -1 and x = -1.