Find Trace and Normal of a Given Matrix in Swift

Ankita Saini
Updated on 29-Dec-2022 17:21:58

164 Views

In this article, we will learn how to write a swift program to find trace and normal of a given matrix. Calculating the Trace of a given Matrix Trace is known as the sum of primary diagonal elements of the given square matrix. For example, we have a 3x3 square matrix − 2 3 4 3 4 6 1 3 2 So the primary diagonal elements are 2, 4 and 2. Hence the trace of the given 3x3 matrix is 2+4+2 = 8. Algorithm Step 1 − Define the size of the matrix. Step 2 − Create a ... Read More

Interchange Elements of First and Last Rows of a Matrix in Swift

Ankita Saini
Updated on 29-Dec-2022 17:21:05

313 Views

In this article, we will learn how to write a swift program to interchange the elements of first and last in a matrix across rows. Therefore, to interchange the elements we need to swap the elements of the first row with the elements of the last row of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping the first and last rows we get: 1 1 1 1 3 4 6 2 6 7 7 2 2 4 5 6 ... Read More

Interchange Diagonals of a Matrix in Swift

Ankita Saini
Updated on 29-Dec-2022 17:20:23

253 Views

In this article, we will learn how to write a swift program to interchange the diagonals. Therefore, to interchange the diagonals we need to swap the elements of primary diagonal with the elements of secondary diagonal of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping diagonals we get: 6 4 5 2 3 6 4 2 6 7 7 2 1 1 1 1 Algorithm Step 1 − Create a function. Step 2 − Run a for loop ... Read More

Print Boundary Elements of a Matrix in Swift

Ankita Saini
Updated on 29-Dec-2022 17:11:17

332 Views

In this article, we will learn how to write a swift program to print boundary elements of a matrix. Boundary elements of a matrix are those elements that are present on the boundary of the matrix that are elements in the first row, last row, first column, and last column. For example − Given Matrix: 2 4 5 6 7 8 4 5 6 7 3 2 3 4 5 6 2 1 1 1 1 1 1 1 3 4 3 4 3 4 2 2 2 2 2 2 Boundary elements are: 2 4 5 6 ... Read More

Interchange Elements of First and Last Columns of Matrix in Swift

Ankita Saini
Updated on 29-Dec-2022 17:04:11

383 Views

In this article, we will learn how to write a swift program to interchange the elements of first and last in a matrix across columns. Therefore, to interchange the elements we need to swap the elements of the first column with the elements of the last column of the given matrix. For example − Original matrix: 2 4 5 6 3 4 6 2 6 7 7 2 1 1 1 1 So after swapping the first and last column we get: 6 4 5 2 2 4 6 3 2 7 7 6 1 1 1 1 ... Read More

Swift Program to Display Lower Triangular Matrix

Ankita Saini
Updated on 29-Dec-2022 17:01:30

253 Views

In this article, we will learn how to write a swift program to display lower triangular matrix. Lower triangular matrix is a matrix in which all the elements above primary diagonal are zero. As shown in the below image: $$\mathrm{\begin{bmatrix} 1 & 0 & 0 & 0 & 0 & 0ewline 3 & 5 & 0 & 0 & 0 & 0ewline 1 & 4 & 6 & 0 & 0 & 0ewline 1 & 2 & 2 & 2 & 0 & 0ewline 4 & 5 & 6 & 1 & 2 & 0ewline 1 & 1 & 1 ... Read More

Calculate Average Using Arrays in Swift

Ankita Saini
Updated on 29-Dec-2022 15:53:37

3K+ Views

In this article, we will learn how to write a swift program to calculate averages using an array. Average is defined as the ratio of the sum of the elements present in the given sequence to the total number of elements available in the given sequence. The general formula of average is − Average = (p1+p2+p3+..+pn)/n Here we use the following methods to calculate the average using array − Using pre−define functions Without using predefine functions Method 1: Using Pre-Define Functions To find the average of the given array, we use reduce() method to find the sum ... Read More

Explain JSON in AJAX

Rushi Javiya
Updated on 29-Dec-2022 15:35:26

5K+ Views

JSON, or JavaScript Object Notation, is a simple format for exchanging data. It is a human−readable and machine−understandable format. It is based on a portion of Standard ECMA−262, Third Edition, December 1999's JavaScript Programming Language. Despite using conventions recognizable to programmers of the C family of languages (C, C++, Java, JavaScript, Perl, Python, and many others), JSON is a text format fully independent of the programming language. JSON is the best language for exchanging data due to its characteristics and simplicity. AJAX is a method of web development used to build interactive web applications. Web pages can request data from ... Read More

Explain RegExp in ES6

Rushi Javiya
Updated on 29-Dec-2022 15:33:42

186 Views

The ES6 is the latest JavaScript version which was introduced in 2015. We will learn about all the features of RegExp means regular expression, which Es6 contains. What is the Regular Expression and Usage of it The regular expression is a string representing the particular search pattern containing the different characters, such as numeric, alphabetic, and special characters. Let’s understand the real−time usage of regular expression. We hope you all have filled out any form in the past and seen particular form field validation errors. For example, if you don’t enter the email with the ‘@’ character or enter a ... Read More

Explain Promise.allSettled with Async/Await in JavaScript

Rushi Javiya
Updated on 29-Dec-2022 15:24:03

8K+ Views

Promise.allSettled() is a method that takes an iterable of promises as an argument and returns a promise that is fulfilled when all of the promises in the iterable have been settled, meaning that they have either been fulfilled or rejected. When the returned promise is fulfilled, it is resolved with an array of objects containing information about the fulfilled or rejected promises. Each object has a status property, either fulfilled or rejected, and a value or reason property, respectively. For example, if you have an array of promises that represent network requests and want to know each request's status (whether ... Read More

Advertisements