## Trigonometry and algebra using Matlab

Trigonometry and algebra are both branches of mathematics that have wide-ranging applications in real life. Algebra, in particular, has lots of applications. In fact, if you want to go far in mathematics, having a good knowledge of algebra is the key. Literally, every mathematics problem that you do applies algebra. Be it trigonometry, geometry, or statistics. Both trigonometrical and algebraic problems can be solved by the use of Matlab.

## Trigonometry

Trigonometry, as the name suggests, is all about triangles. The term trigonometry comes from a Greek word which means measurements pertaining to triangles. Trigonometry has a close relationship with geometry. They are both branches of mathematics used for measurements. If you are going to study trigonometry, then prepare yourself to draw a lot of triangles. However, trigonometry could l be fun if you master its formulas. The main trigonometric functions are the sine, cosine, and tangent. Each of these can be used to compute the angle and side of a triangle using a formula.

While studying trigonometry, you would be primarily concerned with right-angled triangles. . These triangles often have three sides- the adjacent, hypotenuse, and the opposite.

a = the hypotenuse

b = the opposite

c = the adjacent

Assuming that we have the right-angled triangle, we note that the hypotenuse is the longest side of the right-angled triangle, and it’s on the opposite side of the 90 degrees angle. The formula for the above-mentioned trigonometric functions are:

Sine D = opposite/hypotenuse

Cosine D = adjacent/hypotenuse

Tan D = opposite/adjacent.

These three formulas are particularly useful if we are to find the measurements of the side of the triangle if we have the other two sides. It could also help us find the angles and sides of the triangles which are not the right-angled triangle if we have the measurements of the sides.

### History of trigonometry

Trigonometry, as a mathematics branch, has its origin in antiquity. In ancient Greek, trigonometry was used in astronomy, where it was used to compute the angles of the celestial bodies. However, this geometry required a different computational method other than the plane geometry known as spherical geometry.

It’s stated that trigonometry was in use as early as 300BC by the Babylonians. They, however, did not use the modern functions of trigonometry, such as the sine and cosine, but used the chords. Babylonians are also credited for developing the degree measurements which are used in trigonometry.

Despite the fact that Babylonians knew much about trigonometry, Hipparchus is seen as the man behind the idea of trigonometry. This is because he developed the first table of chords. He is said to have written the first book of trigonometry also. Of course, it’s evident that the Babylonians knew much about trigonometry than him. But given that he wrote the first book on trigonometry, he is credited as the one who proposed the concepts of trigonometry. According to some other historical information, he was not the first one to have written a book on trigonometry. Archimedes is also accredited to have written a book on trigonometry, but there is a lack of evidence to support this.

### Application of trigonometry

Trigonometry has lots of applications in real life which makes it a worthy mathematical branch to study. Its applications are vast. One of the real-life examples where trigonometry is applied is a bridge. A bridge is constructed by applying the different forces of different angles.

It’s also applied in the GPS system. Like it or not, trigonometry is applied in the GPS system to track your location. A satellite situated on space uses the longitudes and latitudes to determine your exact location.

## Algebra

Algebra, as we have stated, is the very core of mathematics. In fact, it’s often referred to as the language of mathematics. Every mathematics concept can be expressed in algebraic form. In algebra, unknowns are used instead of numbers. Mathematical manipulations same as those done on numerical values are done to these unknowns. But these manipulations have certain rules that have to be followed. In your schooling days, you expressed the formula of calculating the area of a triangle as ½ *a*b, where a represented the base of a triangle and b the height of a triangle.

Algebra is meant to make the life of mathematicians and students easy. However, most students have a general dislike for algebra. It’s generally not easy to master algebra, but if a student masters algebra, then his/her foray into the world of mathematics becomes quite easy.

### History of algebra

It’s easy to assume that algebra has its origin in recent times. But its origin dates back to the origin of mathematics. Algebra is a name that is derived from the Arabian word al-jabr.

Babylonians and Egyptians are believed to be the first people to use algebra. Babylonian algebra was more complex than the Egyptian as Babylonian algebraic equations consisted of quadratic and cubic equations. The Egyptians only used linear equations. Apart from this, the Babylonians were familiar with the many forms of factoring.

### Applications of algebra

Algebra has lots of applications in real life. Right from the moment that you wake up, you use algebra in your daily plans. Algebra is also applied in business to approximate profits. Right now, you may be thinking about how logical this concept of algebra is. Logical thinking in its own way is an application of algebra whereby you try to break down a problem into simpler parts then find the solutions. To cut the story short, nearly all aspect of our lives where mathematics is applied algebra is used too.

## Trigonometry and algebra in Matlab.

Matlab is a full-fledged mathematical software that has all the functions that you will need in any mathematical computation. Matlab has all the basic trigonometric functions such as sine and cosine. You can also use it to solve a trigonometric equation. Solution to any kind of equation is entirely possible with Matlab. You can also use methods like the secant root finding and newton’s method.

The systematic toolbox is the Matlab toolbox that will help you in computing trigonometric and algebraic expressions. But before embarking on solving the mathematical problems, ensure that you go through the related documents first.

## Matlab assignment experts

Matlab assignment experts is a group of talented and highly motivated experts offering their expertise to students around the globe to help them complete their assignments at an affordable cost. We also promise a high grade to students who ask for our services. We are fully confident in the services that we offer.

This is not just any platform that gives promises of high grades to convince students who ask for the services. Instead, we have a proven track record of offering top-notch academic help services with Matlab. We have arrived at this status slowly and gradually until we became one of the most trusted online assistance companies. For close to a decade, we have been consistently providing students with outstanding services. This has made us the most reputable online assistance company.

Our experts are well versed in using Matlab. They have amassed this expertise by working on Matlab related assignments over the years. We also ensure that each of our experts is adorned with the highest academic qualification. This is to ensure that you, our esteemed clients, get five-star services from us. We value our clientele and always look forward to giving them the best quality assignment solutions all the time irrespective of how challenging the assignment might be.

If you really want to score a high grade in your assignment, then make it a point to contact us. You won’t regret this move.

In this example, the answer to two questions, viz, the value of Sin(x) using infinite power series method, and evaluation of binomial expansion has been demonstrated using Matlab function. In the first question, the expert demonstrates to calculate the value of Sinx for three different values of x. The sum is calculated using an infinite power series method. A Matlab function is written to accomplish the same. In the second question, the expert has revealed the evaluation of one binomial expansion. Here also, the tutor has written a Matlab function for this evaluation.

**SOLUTION: –**

Question 1

To solve this question, the following series is used as an approximation to calculate the sine of any value:

This is an approximation defined by a sum of infinite terms. However, to calculate the sine value, it cannot be calculated as a sum of infinite terms. Instead, a finite number of terms is used. The number of terms depends of a termination condition, which is established as a minimum error accepted. The error is calculated as the difference between real value of and the approximated value calculated at term . For this paper, the minimum error is established at:

The code used to calculate the (Appendix A) can calculate the values for small values of x. The results are presented below:

Discussion for Question 1

The series used as an approximation to the sine value turned out to be a fairly accurate approximation, since it allows to calculate the sine value of a number with an error less than or equal to 10 ^ -10. However, from the computational point of view, this approach has a weakness and it is at the time of calculating the denominator of each term. The denominator of each term is defined as the factorial of twice the position of the term minus 1. For a few terms, a computer calculates these values easily. However, when you want to calculate the sine of a larger number, a larger number of terms (for example, 50) is required and a computer is not able to calculate the factorial of that number because its value is excessively large.

One way to solve this problem is to set a maximum limit for the number of terms. In the case of MATLAB the maximum factorial that can be calculated is 171!. Therefore, this limit could be set using an if statement.

Question 2

To convert a floating-point binary number to a decimal number, the following method is applied:

First of all, the first bit in the mantissa is considered the sign of the number:

11110010 11000101 01101010

If the first number is zero, the resulting decimal number is positive. If the first bit is 1, the number is negative. So, for this example, the number should be negative.

The exponent is defined as an 8-bit binary number:

01011000

So, the floating-point binary number can be written as:

1 01011000 1110010 11000101 01101010

The exponent is calculated as:

clc, clear all, close all

%% Question 1: Calculate the sine of a value x using the series approximation

x = 0.5 % the value used to calculate the sin

real_val = sin(x) % variable to store the real value of sin(x)

e = 1e-10; % epsilon (min error)

calculated_val = 0; % variable to store the calculated value using the approximation

error = 1e50; % Initial error used for n = 1

s = 1; % Variable to store the sign of the term. (don’t touch) 1 for positive, -1 for negative

i = 1; % Counter

while(error > e)

k = 2*i-1; % exponent and factorial of term

term = x^k /factorial(k);

calculated_val = calculated_val + s*term; % Current calculated value of sin(x)

s = -1*s; % for each term, change the sign

error = abs(real_val – calculated_val); % Calculate current error

i = i + 1; % Increase counter

end

% Print results

fprintf(‘The values calculated using the sine approximation are:\n’);

fprintf(‘ sin(%s): %s\n’, num2str(x), num2str(real_val));

fprintf(‘ approximation: %s\n’, num2str(calculated_val));

Matlab function that converts a floating-binary to decimal

clc, clear all, close all

%% Question 1: Calculate the sine of a value x using the series approximation

x = 0.5 % the value used to calculate the sin

real_val = sin(x) % variable to store the real value of sin(x)

function ret = FloatingBinaryToDec(mantissa_str, exponent_str)

%% Question 2: Convert a floating-point binary to decimal

% Sizes of mantissa an exponent

mantissa_size = 24;

exponent_size = 8;

% Define the mantissa and exponent as strings

% mantissa_str = ‘11110010 11000101 01101010’

% exponent_str = ‘01011000’

% Remove spaces if exists

mantissa_str = mantissa_str(~isspace(mantissa_str));

exponent_str = exponent_str(~isspace(exponent_str));

m_sign = str2double(mantissa_str(1));

mantissa_sign = (-1)^m_sign; % Get the sign of the mantissa

exponent_val = 0;

for i = 1:exponent_size

val = 2^(i-1); % The value of the current term: 2^(i-1)

if str2double(exponent_str(exponent_size – i + 1)) == 1 % If the current bit is equal to 1, consider the term

exponent_val = exponent_val + val;

end

end

E = exponent_val-127; % Finally, the exponent is the calculated value – 127

% Add the hidden bit, implied to be 1. Also, we delete the first bit

% because that bit defines the sign of the mantissa

mantissa_str = mantissa_str(2:end); % we delete the first number because that’s the sign

mantissa_str = strcat(‘1’, mantissa_str); % hidden bit

M = 0; % The value of the mantissa M

for i = 1:mantissa_size

k = -(i-1);

if str2double(mantissa_str(i)) == 1

M = M + 2^k;

end

end

dec_val = mantissa_sign*M *2^E; % Finally, the result

ret = dec_val;

end

Matlab code to call the function

clc, clear all, close all

%% Question 2: Convert a floating-point binary to decimal

% Sizes of mantissa an exponent

mantissa_size = 24;

exponent_size = 8;

% Define the mantissa and exponent as strings

mantissa_str = ‘11110010 11000101 01101010’;

exponent_str = ‘01011000’;

m_sign = str2double(mantissa_str(1));

fprintf(‘******* QUESTION 2 PART a) *******\n’);

dec_val = FloatingBinaryToDec(mantissa_str, exponent_str);

mantissa_str_print = mantissa_str(2:end); % Get the original mantissa without the implied 1 and the sign bit

fprintf(‘The floating-point binary: %s %s %s is %.50f\n’, num2str(m_sign), mantissa_str_print, exponent_str, dec_val);

fprintf(‘\n\n******* QUESTION 2 PART b) *******\n’);

largest_number = FloatingBinaryToDec(‘011111111111111111111111’, ‘11111111’);

fprintf(‘The largest number (dec) that can be represented is: %s\n’, largest_number);

fprintf(‘\n\n******* QUESTION 2 PART c) *******\n’);

smallest_number = FloatingBinaryToDec(‘000000000000000000000001’, ‘00000000’);

fprintf(‘The smallest positive number (dec) that can be represented is: %s\n’, smallest_number);

fprintf(‘\n\n******* QUESTION 2 PART d) *******\n’);

fprintf(‘The difference between these numbers is: %s\n’, largest_number – smallest_number);

fprintf(‘\n\n******* QUESTION 2 PART e) *******\n’);

total_size = 2^(mantissa_size – 1);

fprintf(‘The total number of significant base-10 numbers that can be calculated is: %s\n’, total_size);