0% found this document useful (0 votes)
2 views2 pages

Question 4

The document presents a MATLAB script that calculates and displays the square root, sine, and cosine of values ranging from -5 to 5 in increments of 0.5. It handles negative values for square roots using complex numbers and computes sine and cosine in degrees. The results are displayed in a formatted manner, showing the row matrix for x, the square roots, sine, and cosine values.

Uploaded by

sonu2915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Question 4

The document presents a MATLAB script that calculates and displays the square root, sine, and cosine of values ranging from -5 to 5 in increments of 0.5. It handles negative values for square roots using complex numbers and computes sine and cosine in degrees. The results are displayed in a formatted manner, showing the row matrix for x, the square roots, sine, and cosine values.

Uploaded by

sonu2915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

% Name: Sauvik Arya

% Roll No: 10
% Question 4
clc;

% Defining X from -5 to 5 with increment of +0.5


x = -5:0.5:5;
format short;

% Computing square root, handling negative values using complex numbers


sqrt_X1 = sqrt(x); % sqrt() handles negative values as complex numbers

% Computing sine and cosine of x in degrees


sin_x = sind(x); % Use sind() for degree-based sine
cos_x = cosd(x); % Use cosd() for degree-based cosine

% Displaying results
disp('Row Matrix x is:');
disp(x);
disp('************************************************************************
**************************');
disp('Square Root of x (handling negatives as complex numbers):');
disp(sqrt_X1);
disp('************************************************************************
**************************');
disp('Sine of x in degrees:');
disp(sin_x);
disp('************************************************************************
**************************');
disp('Cosine of x in degrees:');
disp(cos_x);

Row Matrix x is:


Columns 1 through 7

-5.0000 -4.5000 -4.0000 -3.5000 -3.0000 -2.5000 -2.0000

Columns 8 through 14

-1.5000 -1.0000 -0.5000 0 0.5000 1.0000 1.5000

Columns 15 through 21

2.0000 2.5000 3.0000 3.5000 4.0000 4.5000 5.0000

******************************************************************************
********************
Square Root of x (handling negatives as complex numbers):
Columns 1 through 4

0.0000 + 2.2361i 0.0000 + 2.1213i 0.0000 + 2.0000i 0.0000 + 1.8708i

1
Columns 5 through 8

0.0000 + 1.7321i 0.0000 + 1.5811i 0.0000 + 1.4142i 0.0000 + 1.2247i

Columns 9 through 12

0.0000 + 1.0000i 0.0000 + 0.7071i 0.0000 + 0.0000i 0.7071 + 0.0000i

Columns 13 through 16

1.0000 + 0.0000i 1.2247 + 0.0000i 1.4142 + 0.0000i 1.5811 + 0.0000i

Columns 17 through 20

1.7321 + 0.0000i 1.8708 + 0.0000i 2.0000 + 0.0000i 2.1213 + 0.0000i

Column 21

2.2361 + 0.0000i

******************************************************************************
********************
Sine of x in degrees:
Columns 1 through 7

-0.0872 -0.0785 -0.0698 -0.0610 -0.0523 -0.0436 -0.0349

Columns 8 through 14

-0.0262 -0.0175 -0.0087 0 0.0087 0.0175 0.0262

Columns 15 through 21

0.0349 0.0436 0.0523 0.0610 0.0698 0.0785 0.0872

******************************************************************************
********************
Cosine of x in degrees:
Columns 1 through 7

0.9962 0.9969 0.9976 0.9981 0.9986 0.9990 0.9994

Columns 8 through 14

0.9997 0.9998 1.0000 1.0000 1.0000 0.9998 0.9997

Columns 15 through 21

0.9994 0.9990 0.9986 0.9981 0.9976 0.9969 0.9962

Published with MATLAB® R2024b

You might also like