Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the core of Java linear algebra

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "what is the core of Java linear algebra". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Linearity in Life: supermarket settlement

We imagine a supermarket that sells only two goods, selling green vegetables and soybeans. 5 yuan per bundle of green vegetables and 3 yuan per box of soybeans. In addition, the supermarket also has a points system, with 2 points for each bundle of vegetables and 4 points for each packet of soybeans. A settlement system is needed to calculate the total price and points for the customer.

This is not a challenge for programmers. Each language can be easily implemented, such as using Python:

# By Vameidef bill (x1, x2): Y1 = 5*x1 + 3*x2 y2 = 2*x1 + 4*x2 return y1, y2

X1 and 2 are the number of green vegetables and soybeans respectively. Y1pr y2 is the total price and points. By inputting the purchase number of different varieties, we get the output. The output here has two elements: the total price and the integral.

The above calculation can also be written as a set of simple mathematical equations:

Y1x 5 × x1x 3 × x2y1=5 × x1x 3 × x2

Y 2x x 1m 4 x x2y2=2 x x 1m 4 x x 2

Let's imagine a situation in which a couple goes to the supermarket to buy vegetables. The husband bought a bundle of green vegetables and two boxes of soybeans for 11 yuan and 10 points when he checked out. The wife bought 2 bundles of green vegetables and 3 boxes of soybeans, which were 19 yuan and 16 points at checkout.

But if the wife meets her husband before checking out, they put things together for a total of three bundles of vegetables and five boxes of soybeans. According to our settlement system, the total price is 5 × 3 × 5 × 305 × 3 × 5 × 30 yuan, and the total score is 2 × 3 × 4 × 562 × 3 × 526.

You may refute me, why bother? Just add up the two lists just now. 11'19 '3011' 19'30 yuan, 10'16 '2610' 16'26 points. The calculation results through the settlement system are exactly the same.

That's the right idea. You are already using linear system (Linear System) thinking:

The sum of the items in several shopping carts and the separate bills is the same as the result of the general account at one time.

There are more complicated situations in linear systems. Give the two shopping carts to the salesman and let the salesperson according to the same ratio, three carts for the husband and two carts for the wife. So, the new total price should be the husband's small ticket multiplied by 3, plus the wife's small ticket multiplied by 2.

Linear thinking is so common that we have to think more about it before we can come up with non-linear examples. The following is a non-linear situation: the supermarket changes the points system, if the score is more than 20, you will get double points. At this time, if you check out separately and the points for both husband and wife are less than 20, then the points are 10 and 16 respectively, with a total of 26. If you check out together, because the score is more than 20, the score will be 52. Couples with life experience must have checked out together instead of separately.

We have created a nonlinear system. Write the new settlement system into a function and still use Python:

# By Vameidef non_linear_bill (x1, x2): Y1 = 5*x1 + 3*x2 y2 = 2*x1 + 4*x2 if y2 > 20: Y2 = y2 * 2 return y1, y2

Nonlinearity is not the usual way of thinking. Supermarkets and shopping malls often have complex discount, coupon and points systems, which are often non-linear. The brain takes a lot of energy to handle it. So, as a super linear boy, my usual idea is: fuck it, I don't have to take so much trouble to close or open orders.

Strangely, girls can be super proficient in dealing with a variety of non-linear shopping systems, or even multiple in parallel. The rib that God took away must be non-linear.)

"one"

We are about to change our understanding of the data of a unit. Cite a data.

As a programmer, he most directly enumerates a piece of data, such as an integer or a floating point number.

Which structure? A structure in the C language can contain multiple elements. We know that each element is written separately and is not the complete data of the structure. For example:

Typedef struct {int veg; int bean;} Cart

Go on, what about the data of an object? An object can have multiple properties. When we talk about the data of an object, we mean multiple properties of the object. For example:

Public class Cart {int veg; int bean;}

For example, when we talk about a person's data, it includes name, height, weight, and IQ. These multiple values can constitute "one" data for this person. We can create such a Person (name, height, weight, IQ) table in the SQL database. Each row, that is, a record, can be regarded as a unit of data.

Even for a data container such as a list, a list can be regarded as "one" data if the meaning of each location data is fixed. For example, the husband's shopping cart is [1pm 2] and the wife's shopping cart is [2p3].

This kind of data, which contains multiple elements, is called vector. Correspondingly, a single numerical value is called a scalar.

A vector

We use letters with small arrows to represent a vector. For example, the husband's shopping cart:

X examples = [12] x → = [12]

Vectors can be added and subtracted, and only the elements of the corresponding row need to be added, which is equivalent to merging or separating shopping carts. For example, the husband and wife's shopping cart merger:

[12] + [23] = [35] [12] + [23] = [35]

A vector can also be multiplied by a scalar. For example, x shopping × 5x → × 5 represents the number of five shopping carts. At this point, you just need to multiply the scalar by the line elements of the vector.

5 [12] = [510] 5 [12] = [510]

Along with the vector, there is a simple concept, dimension. The shopping cart vector above contains two values, namely, the number of vegetables and the number of beans. So we say that the vector is two-dimensional. The number of elements in the structure and the number of attributes of the object are all dimensions. I will delve into the concept of dimension in future articles.

With an in-depth understanding of the data, the characteristics of the linear system can be summarized as follows:

L (aD1 → + bD2 →) = aL (D1 →) + bL (D2 →) L (aD1 → + bD2 →) = aL (D1 →) + bL (D2 →)

D1 → D1 → and D2 → D2 → are vectors, which are shopping carts for husbands and wives, respectively. While an and b are two scalars, for example, an is 2 and b is 3, which means that the husband's shopping cart times 2 and the wife's shopping cart times 3. L is the settlement system. It is shown on the right side of the equation that the bill is settled together. The right side of the equation says that the husband and wife separate the notes, multiply them and add them together. The two sides of the equation are equal.

Matrix revolution

Mathematically, we already have a set of equations that represent a linear system. There are some inconveniences in the above equations:

Input elements (number of soybeans) and system parameters (unit price) are mixed together

There are many letters.

Mathematicians are lazy animals, much like programmers. They finally found a convenient way to describe it. Use the vector just now. A separate representation of the relationship between input, linear system, and output:

[1110] = [5234] [12] [1110] = [5324] [12]

The equation is a vector at the far left and a vector at the right. The strange thing is a pile of numbers enclosed in parentheses. This is called a Matrix. As you can see, there are four elements in this matrix, including the unit price of each item and the points available for each item. This is usually the data contained in the settlement system. We can guess that this matrix is equivalent to a settlement system. The vector on the left is output and the vector on the right is input.

Settlement system

When the settlement system is running, the input vector is placed horizontally and multiplied by each line element of the settlement system to obtain the corresponding output element. For example, the first element of the output:

According to this operation rule, a linear system is completely represented by a matrix.

You can express the matrix as the letter A, then write the relationship between the output and the matrix and input in algebraic form:

Y → = Ax → = Ax →

This algebraic form plays a fundamental role in linear algebra. On the right side of the equation, we say that matrices and vectors are multiplied. The rules of this operation work as we described above. This is simply an operator overload (operator overload) of multiplication symbols.

We can use the program to implement the above calculation process. Writing a similar C program is not complicated. It is more convenient to call existing library functions, such as numpy in Python:

# By Vameiimport numpy as np# matrixa = np.matrix ([[5,3], [2,4]]) # input Vectorx = np.array ([[1], [2]]) # multiplicationy = np.dot (a, x) print (y)

The matrix greatly reduces the representation of the settlement system. More importantly, the linear system and the matrix are interoperable. The matrix represents a linear system. A linear system can always represent a matrix.

For a long time, the matrix equals the linear system.

This is the end of "what is the Core of Java Linear Algebra". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report