text:
Matrix multiplication in Java

I am taking input from a text file, performing matrix multiplication, then outputting to another text file. I just want to be a better programmer, so please be a detailed as you want. Comments, naming, formatting, etc.

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class MartixMain {
public static void main(String [] args){
BufferedWriter bw = null;
FileWriter fw = null;
List<Integer> numbers = new ArrayList<>();
// This is the rows and columns for the matries
int row1,column1,row2,column2;
try {
Scanner input = new Scanner(new File("C:/Users/jeremiahlukus   /Desktop/New folder/jj.txt"));
// adds numbers from .txt to ArrayList numbers
while(input.hasNextInt()){
}
}
catch(FileNotFoundException e){
System.err.println("Unable to find the file: fileName");
}
row1 = numbers.get(0);
column1 = numbers.get(1);
row2 = numbers.get(2);
column2 = numbers.get(3);

if(column1 != row2){
System.out.println("Column 1 is not equal to row 2. Matrix Multiplication is not possible.");
try{
fw = new FileWriter(new File("mytextfile.txt"));
fw.write(String.format("Column 1 is not equal to row 2. Matrix Multiplication is not possible."));
fw.close();
}catch(Exception e){
System.out.println("NONE");
}
}else{
//checking to see if they hold the right numbers
System.out.println("Matrix 1 has " + row1 + " rows and " + column1+ " columns");
System.out.println("Matrix 2 has " + row2 + " rows and " + column2+ " columns");
// This puts the first four numbers as the dimensions of int [][]
int [][] matrix1 = new int [row1][column1];
int [][] matrix2 = new int [row2][column2];
// Removes the first four numbers from the List which are used as dimensions
numbers.remove(0);
numbers.remove(0);
numbers.remove(0);
numbers.remove(0);
// This fills the matrix[][]'s up with the numbers in the List
int iter = 0; // iterates the index of the List
for( int row = 0; row < matrix1.length; row++){
for( int col = 0; col < matrix1[row].length;col++){
matrix1[row][col]= numbers.get(iter);
iter++;
}
}
for( int row = 0; row < matrix2.length; row++){
for( int col = 0; col < matrix2[row].length;col++){
matrix2[row][col]= numbers.get(iter);
iter++;
}
}
System.out.println("The elements in Matrix 1 are:");
System.out.println(Arrays.deepToString(matrix1));
System.out.println("The elements in Matrix 2 are:");
System.out.println(Arrays.deepToString(matrix2));

int[][] multi = multiply(matrix1, matrix2);
System.out.println("Product of Matrix 1 and Matrix 2 is: ");
for (int i = 0; i < multi.length; i++) {
for (int j = 0; j < multi[0].length; j++) {
System.out.print(multi[i][j] + " ");
}
}
try{
fw = new FileWriter(new File("MatrixMultiplication.txt"));
fw.write(String.format ("Matrix 1 has " + row1 + " rows and " + column1+ " columns"));
fw.write(System.lineSeparator()); //new line
fw.write(String.format ("Matrix 2 has " + row2 + " rows and " + column2+ " columns"));
fw.write(System.lineSeparator()); //new line
fw.write(String.format("The elements in Matrix 1 are:"));
fw.write(System.lineSeparator()); //new line
fw.write(String.format(Arrays.deepToString(matrix1)));
fw.write(System.lineSeparator()); //new line
fw.write(String.format("The elements in Matrix 2 are:"));
fw.write(System.lineSeparator()); //new line
fw.write(String.format(Arrays.deepToString(matrix2)));
fw.write(System.lineSeparator()); //new line
fw.write(String.format("Product of Matrix 1 and Matrix 2 is: "));
fw.write(System.lineSeparator()); //new line

for (int i = 0; i < multi.length; i++) {
for (int j = 0; j < multi[0].length; j++) {
fw.write(String.format(multi[i][j] + " "));
}
}
fw.close();
}catch(IOException ex) {
ex.printStackTrace();
}

}
}
// This method multiplies the matrices
public static int[][] multiply(int[][] a, int[][] b)
{
int rowsInA = a.length;
int columnsInA = a[0].length; // same as rows in B
int columnsInB = b[0].length;
int[][] c = new int[rowsInA][columnsInB];
for (int i = 0; i < rowsInA; i++) {
for (int j = 0; j < columnsInB; j++) {
for (int k = 0; k < columnsInA; k++) {
c[i][j] = c[i][j] + a[i][k] * b[k][j]; // Multiplies the matrices together
}
}
}
return c;
}
}

Input:

3            3
3 4

1         2 3
4 5 6
7 8 9

1 2 3 4
5 6 7 8
9 10 11 12

Output:

Matrix 1 has 3 rows and 3 columns
Matrix 2 has 3 rows and 4 columns
The elements in Matrix 1 are:
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
The elements in Matrix 2 are:
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
Product of Matrix 1 and Matrix 2 is:
38 44 50 56 83 98 113 128 128 152 176 200

In addition to what Hosch has told you:

Make use of try with resources

You utilize several classes which implement the Closable interface, but aren't explicitly freeing resources you use. Employing a try-with-resources statement will amend that with the benefit of reducing the scope of some variables you currently declare outside.

As an example, rather than the following:

try {
Scanner input = new Scanner(new File("C:/Users/jeremiahlukus   /Desktop/New folder/jj.txt"));
// adds numbers from .txt to ArrayList numbers
while(input.hasNextInt()){
}
}

You can write:

try (Scanner input = new Scanner(
new File("C:/Users/jeremiahlukus/Desktop/New folder/jj.txt") {
// logic
}

The newline character

Everywhere you're calling System.lineSeparator() could be replaced with a '\n' newline character preceding where you'd want it.

e.g. This chunk:

fw.write(String.format(Arrays.deepToString(matrix2)));
fw.write(System.lineSeparator()); //new line
fw.write(String.format("Product of Matrix 1 and Matrix 2 is: "));
fw.write(System.lineSeparator()); //new line

Could be just:

  fw.write(String.format(Arrays.deepToString(matrix2)));
fw.write(String.format("%nProduct of Matrix 1 and Matrix 2 is:%n"));

Be DRY

Anytime you see yourself encountering repition like the following:

numbers.remove(0);
numbers.remove(0);
numbers.remove(0);
numbers.remove(0);

it's a big indication your code could probably do with some refactoring. You could use simple loop:

for (int i = 1; i <= 4; i++) {
numbers.remove(0);
}

or better yet structured in a method

private static void remove(List<Integer> target, iterations) {
for (int i = 1; i <= iterations; i++) {
target.remove(0);
}
}

which you could invoke, simply, by calling remove(numbers, 4); of course now you have the added benefit of recycling the method elsewhere if necessary.

Don't just catch Exception

While many of us are guilty of just wanting the initial version before changing it, you never want to only catch Exception, for obvious reasons. Be as specific as possible.

Declare variables on separate lines

Let's examine this line: int row1,column1,row2,column2;

Firstly, for the sake of readability you should get in the habit of adding a space after your commas, but even still conventionally each variable should have its on own separate line. It may even seem 'wasteful' to you to do it that way, but the distinct locations make things more readable, flexible and maintainable.

• Extremely helpful!! Thank you so much. You just taught me so much ha – jermiah Feb 1 '16 at 2:26
• The suggestion of "The newline character" is incorrect. Windows and Linux uses different line breaks, so if you run this on Windows with your suggestion you would still get Linux-style line breaks. – Simon Forsberg Feb 4 '16 at 17:17
• Good point, %n would be platform independent and the more correct approach. – Legato Feb 4 '16 at 17:32

First of all, naming:

int[][] c

This do not tell me what the variables are and what they contain. Most of your naming is OK, although it is best to avoid names like row1, &c.

Your formatting could also use some improvement:

      fw.write(System.lineSeparator()); //new line

for (int i = 0; i < multi.length; i++) {
for (int j = 0; j < multi[0].length; j++) {
fw.write(String.format(multi[i][j] + " "));
}
}
fw.close();
}catch(IOException ex) {
ex.printStackTrace();
}

}

}else{
//checking to see if they hold the right numbers
System.out.println("Matrix 1 has " + row1 + " rows and " + column1+ " columns");

You should keep each level at the same indentation so you can see at a glance what level has what scope.

fw.write(System.lineSeparator()); //new line

Most people probably know what System.lineSeparator() is.

Also, your comment above multiply() could become a documentation comment. A doc comment is used to supply information to IntelliSense tools and can also be exported to other files if needed. These comments look like:

/**
* A comment describing the method
*
* @param  paramName  A description of a parameter
* @return            A description of what the method returns
* @see               Other references to check out
*/

Have you ever seen the abbreviation SRP? It stands for Single Responsibility Principle, and states that every unit should do only one thing. For example, a method should only do one thing, a class should only do one thing, and so on. Your main() method should start the program and only start the program. Reading the data, working with the data, outputting the data, and so on should all have their own methods that are responsible for, and only responsible for, that. Your multiply() method is good as it is only responsible for multiplying the two matrices.

What happens when the input is formatted incorrectly? Does your program handle this use case? While this program may not need to have intensive error handling, many programs do, so this is a point worth mentioning. If the user left out one of the numbers in one of the arrays, it appears your program would throw an exception when you are filling your 2D arrays:

numbers.get(iter);

Swallowing FileNotFoundException without printing its message

When opening the input file, you are swallowing a FileNotFoundException without printing its message.

This exception is also thrown under the following conditions:

• When you try to open a directory as a file
• Opening a file were you don't have read permissions for
• The file doesn't exists

The best way to print a message would be:

catch(FileNotFoundException e){
System.err.println("Error opening: " + e.getMessage());
}

This would show up as:

Error opening: C:/test.txt (Permission denied)

Formatting

Your formatting (in particular the indentation) is inconsistent, making it hard to see the structure of the code at a glance. You really should be using a code formatter (in eclipse, press Ctrl+Shift+F or configure a save action to format the code whenever you save the file).

Structure

Your main method is rather big. If I have to locate some particular piece of code in there, I have to skim nearly a 100 lines of code. By making shorter methods with clear names, you can make the structure of your code more evident, and permit fast drill-down to any part of the code.

Variables

In Java, it is customary to declare your variables on first use, rather than on top of the method. This makes your code shorter, and more self contained. In particular, it is easier to extract methods because the logical sections of your big method are more self-contained. It also makes it easy to spot unused variables such as br and bw.

Also, avoid assigning default values to local variables (as in br = null). The compiler will emit an error if you use a variable you have not assigned, so it is impossible to run into trouble by using unassigned variables. If you assign a default value, you forgo this safety net.

Finally, some variables have misleading names. I would expect column2 to be the second column, not the number of columns in the second matrix.

Exception Handling

You should close files and streams even if an exception occurs. The try-with-resources statement makes this easy.

Algorithm

First reading the file into an ArrayList is unnecessary.

Example

Combining these, we end up with something like this:

public static void main(String[] args) throws Exception {
File input = new File("C:/Users/jeremiahlukus   /Desktop/New folder/jj.txt");
try (Scanner scanner = new Scanner(input)) {
int rows1 = scanner.nextInt();
int cols1 = scanner.nextInt();
int rows2 = scanner.nextInt();
int cols2 = scanner.nextInt();

if (cols1 != rows2) {
throw new IllegalArgumentException("The matrices have incompatible sizes: "
+ cols1 + " columns vs. " + rows2 + "rows");
}

int[][] matrix1 = readMatrix(scanner, rows1, cols1);
int[][] matrix2 = readMatrix(scanner, rows2, cols2);

int[][] product = multiply(matrix1, matrix2);

System.out.println("The result is:");
System.out.println(format(product));

try (PrintWriter pw = new PrintWriter(new File("MatrixMultiplication.txt"))) {
pw.println("Matrix 1 is the " + rows1 + "x" + cols1 + " matrix");
pw.print(format(matrix1));
pw.println("Matrix 2 is the " + rows2 + "x" + cols2 + " matrix");
pw.print(format(matrix2));
pw.println("Their product is the " + rows1 + "x" + cols2 + " matrix");
pw.print(format(product));
}
}
}

private static int[][] readMatrix(Scanner scanner, int rows, int cols) {
int[][] matrix = new int[rows][cols];
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
matrix[row][col] = scanner.nextInt();
}
}
return matrix;
}

private static int[][] multiply(int[][] a, int[][] b) {
int rowsInA = a.length;
int columnsInA = a[0].length; // same as rows in B
int columnsInB = b[0].length;
int[][] c = new int[rowsInA][columnsInB];
for (int i = 0; i < rowsInA; i++) {
for (int j = 0; j < columnsInB; j++) {
for (int k = 0; k < columnsInA; k++) {
c[i][j] = c[i][j] + a[i][k] * b[k][j]; // Multiplies the
// matrices together
}
}
}
return c;
}

private static String format(int[][] matrix) {
StringBuilder sb = new StringBuilder();
for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {
sb.append(matrix[row][col]);
sb.append(' ');
}
sb.append(System.lineSeparator());
}
return sb.toString();
}

• Ok so everything needs/should be contained in methods. The main should only run what the methods do ? – jermiah Feb 1 '16 at 2:36

In Java and general, having row to row multiplication like

 c[i][j] = c[i][j] + a[i][k] * b[j][k]

is ~5-10 times faster. Just remember in the code to initiate and manave the b like transposed. Also do not modify the address c[i][j] each time and use the variable for summ instead, also maybe try to use a 1-D array, this may give some performance boost.


text:
Ask Your Question

# Creating TOC for Chapter (not for the entire document)

I have a series of documents which I will call "Chapters". These will be placed in a Master document. I require that each Chapter only display the TOC for the Chapter. I am unable to pursuade Writer to create a Table Of Contents (TOC) for a Chapter. In the Writers Guide, Chapter 15 (Tables of Contents, Indexes, Bibliographies), it states: "Writer identifies a “chapter” as all the headings between two first level outline headings (normally Heading 1)." I have attached a document that uses the same template as all the documents. I have temporarily changed a few headings so that "Summary" is the first "Heading 1" and "Roads" is the last "Heading 1". Therefore, if I select Create TOC for Chapter, it should create a TOC for all the headings between Summary and Roads. However, it does not. See attached Writer document.

Using: Version: 6.0.5.2 (x64) Build ID: 54c8cbb85f300ac59db32fe8a675ff7683cd5a16 CPU threads: 4; OS: Windows 10.0; UI render: default; Locale: en-AU (en_AU); Calc: group

C:\fakepath\Land and Roads.odt

edit retag close merge delete

## 2 Answers

Sort by » oldest newest most voted

In your attached document, there are two problems:

1. It's unclear where do you want to add the chapter ToC. Is that the one in the beginning? If so, then which chapter are you targeting it to? It's outside of the chapter (range from "Summary" to "Roads") you are talking about; so it cannot guess the intended chapter (note that the option is for current chapter, i.e., the one inside which ToC is).
2. For some reason, you had assigned Outline level 1 to Contents Heading paragraph style. So even trying to insert the ToC inside the chapter (like, after the "Summary"'s introductory text on page 4(2)), you'd add a paragraph of the said style, and simply stop the chapter "Summary" and started a new chapter, say, "Table of Contents". The starting point of the ToC is, though, still in the "Summary" chapter, and so the ToC would only list what is left in that lonely chapter now... i.e., that level 1 entry itself, and nothing else.

I have removed the outline level 1 setting from the said paragraph style, and inserted the ToC in the position I mentioned, so now it works as intended - see the result.

more

## Comments

Thank you. It is now obvious what the problem was and I can see how to fix it.

( 2018-07-31 14:07:25 +0200 )edit

The structure you need to build to have partial TOCs goes like this:

• General TOC (all levels)

• Level 1 heading (set in Tools → Chapter numbering)

• Partical TOC, set to display only the chapter

• Levels 2 (and below) headings

• Another Level 1 heading

• A new TOC, set to display only the chapter

• More Levels 2 (and below) headings

• Repeate

No other document structure will allow you to use partial TOCs in Writer.

EDIT: TOCs do not refresh by themself, you need to manually refresh them.

more

## Comments

Thank you. Very useful information on the structure required.

( 2018-07-31 14:09:02 +0200 )edit

## Stats

Asked: 2018-07-31 09:46:47 +0200

Seen: 61 times

Last updated: Jul 31 '18

format: plain


text:
Question: DESeq2: Paired multifactor test with batch effect - one or more variables in design formula are linear combinations of others
0
4 weeks ago by
erin.gill8140
erin.gill8140 wrote:

Hi, I'm analyzing an RNA-Seq data set and I would like to perform a paired multifactor test that incorporates batch effect. When I use the design formula

~ response + response:PID + response:timepoint

then eliminate columns from the model matrix manually that contain only zeroes, DESeq2 will run the analysis as expected. However, when I change the design to

~ response + response:PID + response:timepoint + batch

I get the familiar error message

Error in checkFullRank(full) :
the model matrix is not full rank, so the model cannot be fit as specified.
One or more variables or interaction terms in the design formula are linear
combinations of the others and must be removed.

This is what my colData(dds) looks like

sample PID timepoint batch response
01-0603_on P01  fiftysix   one       PD
01-0603_pre P01      zero   one       PD
03-0601_on P01  fiftysix   one       PR
03-0601_pre P01      zero   one       PR
03-0606_on P02  fiftysix   one       PR
03-0606_pre P02      zero   one       PR
04-0605_on P03  fiftysix   one       PR
04-0605_pre P03      zero   one       PR
04-0632_on P02  fiftysix three       PD
04-0632_pre P02      zero three       PD
05-0614_on P04  fiftysix three       PR
05-0614_pre P04      zero three       PR
05-0621_on P03  fiftysix three       PD
05-0621_pre P03      zero three       PD
05-0624_on P05  fiftysix three       PR
05-0624_pre P05      zero three       PR
08-0631_on P04  fiftysix three       PD
08-0631_pre P04      zero three       PD

I realize that my samples aren't well balanced between batches (only one PD response in batch one), but was under the impression that I could still incorporate batch in the design formula in this case. Could you please tell me what I'm missing here and if there is a way to incorporate batch into my analysis?

Thanks!

deseq2 • 61 views
modified 4 weeks ago by Michael Love25k • written 4 weeks ago by erin.gill8140
Answer: DESeq2: Paired multifactor test with batch effect - one or more variables in des
0
4 weeks ago by
Michael Love25k
United States
Michael Love25k wrote:

I can't easily see what's going on in the colData, but if you are comparing patients to their own baseline and those are nested within batch, you don't need to add batch. You've already done the controlling when you compare to their own baseline. Likewise, when patients are compared to their own baseline, one can't add sex as a main effect, because it's already controlled at the patient level, and patients are nested within obviously.


text:
<img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=iA1Pi1a8Dy00ym" style="display:none" height="1" width="1" alt="" />
You are reading an older version of this FlexBook® textbook: CK-12 Algebra I Concepts Go to the latest version.

# 6.9: Graphs of Absolute Value Equations

Difficulty Level: At Grade Created by: CK-12
Estimated7 minsto complete
%
Progress
Practice Graphs of Absolute Value Equations
Progress
Estimated7 minsto complete
%

What if you were given an absolute value function like y=|x8|\begin{align*}y=|x-8|\end{align*}? How could you graph this function? After completing this Concept, you'll be able to make a table of values to graph absolute value functions like this one.

### Guidance

Now let’s look at how to graph absolute value functions.

#### Example A

Consider the function y=|x1|\begin{align*}y=|x-1|\end{align*}. We can graph this function by making a table of values:

x\begin{align*}x\end{align*} y=|x1|\begin{align*}y=|x-1|\end{align*}
-2 y=|21|=|3|=3\begin{align*}y=|-2-1|=|-3|=3\end{align*}
-1 y=|11|=|2|=2\begin{align*}y=|-1-1|=|-2|=2\end{align*}
0 y=|01|=|1|=1\begin{align*}y=|0-1|=|-1|=1\end{align*}
1 y=|11|=|0|=0\begin{align*}y=|1-1|=|0|=0\end{align*}
2 y=|21|=|1|=1\begin{align*}y=|2-1|=|1|=1\end{align*}
3 y=|31|=|2|=2\begin{align*}y=|3-1|=|2|=2\end{align*}
4 y=|41|=|3|=3\begin{align*}y=|4-1|=|3|=3\end{align*}

You can see that the graph of an absolute value function makes a big “V”. It consists of two line rays (or line segments), one with positive slope and one with negative slope, joined at the vertex or cusp.

We’ve already seen that to solve an absolute value equation we need to consider two options:

1. The expression inside the absolute value is not negative.
2. The expression inside the absolute value is negative.

Combining these two options gives us the two parts of the graph.

For instance, in the above example, the expression inside the absolute value sign is x1\begin{align*}x-1\end{align*}. By definition, this expression is nonnegative when x10\begin{align*}x-1 \ge 0\end{align*}, which is to say when x1\begin{align*}x \ge 1\end{align*}. When the expression inside the absolute value sign is nonnegative, we can just drop the absolute value sign. So for all values of x\begin{align*}x\end{align*} greater than or equal to 1, the equation is just y=x1\begin{align*}y=x-1\end{align*}.

On the other hand, when x1<0\begin{align*}x-1 < 0\end{align*} — in other words, when x<1\begin{align*}x < 1\end{align*} — the expression inside the absolute value sign is negative. That means we have to drop the absolute value sign but also multiply the expression by -1. So for all values of x\begin{align*}x\end{align*} less than 1, the equation is y=(x1)\begin{align*}y=-(x-1)\end{align*}, or y=x+1\begin{align*}y=-x+1\end{align*}.

These are both graphs of straight lines, as shown above. They meet at the point where x1=0\begin{align*}x-1=0\end{align*} — that is, at x=1\begin{align*}x=1\end{align*}.

We can graph absolute value functions by breaking them down algebraically as we just did, or we can graph them using a table of values. However, when the absolute value equation is linear, the easiest way to graph it is to combine those two techniques, as follows:

1. Find the vertex of the graph by setting the expression inside the absolute value equal to zero and solving for x\begin{align*}x\end{align*}.
2. Make a table of values that includes the vertex, a value smaller than the vertex, and a value larger than the vertex. Calculate the corresponding values of y\begin{align*}y\end{align*} using the equation of the function.
3. Plot the points and connect them with two straight lines that meet at the vertex.

#### Example B

Graph the absolute value function y=|x+5|\begin{align*}y=|x+5|\end{align*}.

Solution

Step 1: Find the vertex by solving x+5=0\begin{align*}x + 5 = 0\end{align*}. The vertex is at x=5\begin{align*}x = -5\end{align*}.

Step 2: Make a table of values:

x\begin{align*}x\end{align*} y=|x+5|\begin{align*}y=|x+5|\end{align*}
-8 y=|8+5|=|3|=3\begin{align*}y=|-8+5|=|-3|=3\end{align*}
-5 y=|5+5|=|0|=0\begin{align*}y=|-5+5|=|0|=0\end{align*}
-2 y=|2+5|=|3|=3\begin{align*}y=|-2+5|=|3|=3\end{align*}

Step 3: Plot the points and draw two straight lines that meet at the vertex:

#### Example C

Graph the absolute value function: y=|3x12|\begin{align*}y=|3x-12|\end{align*}

Solution

Step 1: Find the vertex by solving 3x12=0\begin{align*}3x - 12 = 0\end{align*}. The vertex is at x=4\begin{align*}x = 4\end{align*}.

Step 2: Make a table of values:

x\begin{align*}x\end{align*} y=|3x12|\begin{align*}y=|3x-12|\end{align*}
0 y=|3(0)12|=|12|=12\begin{align*}y=|3(0)-12|=|-12|=12\end{align*}
4 y=|3(4)12|=|0|=0\begin{align*}y=|3(4)-12|=|0|=0\end{align*}
8 y=|3(8)12|=|12|=12\begin{align*}y=|3(8)-12|=|12|=12\end{align*}

Step 3: Plot the points and draw two straight lines that meet at the vertex.

Watch this video for help with the Examples above.

### Vocabulary

• The absolute value of a number is its distance from zero on a number line.
• |x|=x\begin{align*}|x|=x\end{align*} if x\begin{align*}x\end{align*} is not negative, and |x|=x\begin{align*}|x|=-x\end{align*} if x\begin{align*}x\end{align*} is negative.
• An equation or inequality with an absolute value in it splits into two equations, one where the expression inside the absolute value sign is positive and one where it is negative. When the expression within the absolute value is positive, then the absolute value signs do nothing and can be omitted. When the expression within the absolute value is negative, then the expression within the absolute value signs must be negated before removing the signs.
• Inequalities of the type |x|<a\begin{align*}|x| can be rewritten as “a<x<a\begin{align*}-a < x < a\end{align*}.”
• Inequalities of the type |x|>b\begin{align*}|x|>b\end{align*} can be rewritten as “x<b\begin{align*}x < -b\end{align*} or x>b\begin{align*}x > b\end{align*}.”

### Guided Practice

Graph the absolute value function: y=3|x4|\begin{align*}y=3|x-4|\end{align*}

Solution

Step 1: Find the vertex by solving x4=0\begin{align*}x-4 = 0\end{align*}. The vertex is at x=4\begin{align*}x = 4\end{align*}.

Step 2: Make a table of values:

x\begin{align*}x\end{align*} y=3|x4|\begin{align*}y=3|x-4|\end{align*}
0 y=3|04|=3|4|=34=12\begin{align*}y=3|0-4|=3|-4|=3\cdot 4=12\end{align*}
4 y=3|44|=3|0|=30=0\begin{align*}y=3|4-4|=3|0|=3\cdot 0=0\end{align*}
8 y=3|84|=3|4|=34=12\begin{align*}y=3|8-4|=3|4|=3\cdot 4=12\end{align*}

Notice this is the same table as Example C. The function y=3|x4|\begin{align*}y=3|x-4|\end{align*} is equivalent to the function y=|3x12|.\begin{align*}y=|3x-12|.\end{align*}[/itex]. This is because positive numbers can be factored out, or distributed into the absolute value function.

Step 3: Plot the points and draw two straight lines that meet at the vertex.

### Practice

Graph the absolute value functions.

1. y=|x+3|\begin{align*}y=|x+3|\end{align*}
2. y=|x6|\begin{align*}y=|x-6|\end{align*}
3. y=|4x+2|\begin{align*}y=|4x+2|\end{align*}
4. y=|56x|\begin{align*}y=|5-6x|\end{align*}
5. y=|2x1|\begin{align*}y=|2x-1|\end{align*}
6. y=3|2x7|\begin{align*}y=3|2x-7|\end{align*}
7. y=0.05|x1.25|\begin{align*}y=0.05|x-1.25|\end{align*}
8. y=12|x+10|\begin{align*}y=\frac{1}{2}|x+10|\end{align*}
9. y=x34\begin{align*}y= \left | \frac{x}{3}-4 \right |\end{align*}
10. y=2x25\begin{align*}y= -2\left | \frac{x}{2}-5 \right |\end{align*}

## Date Created:

Oct 01, 2012

Jan 31, 2016
Files can only be attached to the latest version of Modality


text:
# Herbrand structure

For a language $\mathcal{L}$, define the Herbrand universe to be the set of closed terms (alternatively ground terms) of $L$.

A structure $\mathfrak{M}$ for $\mathcal{L}$ is a Herbrand structure if the domain of $\mathfrak{M}$ is the Herbrand universe of $\mathcal{L}$. This fixes the domain of $\mathfrak{M}$, and so each Herbrand structure can be identified with its interpretation, leading to the alternative nomenclature of Herbrand interpretation.

A Herbrand model of a theory $T$ is a Herbrand structure which is a model of $T$.

Title Herbrand structure HerbrandStructure 2013-03-22 14:33:13 2013-03-22 14:33:13 iwnbap (1760) iwnbap (1760) 4 iwnbap (1760) Definition msc 03B10 HerbrandModel HerbrandInterpretation HerbrandsTheoremFirstOrderLogic HerbrandModel HerbrandInterpretation HerbrandUniverse


text:
$$\left(2-x^2\right)^{x^2-3\sqrt{2}x+4} = 1$$
Extension: What if $x$ is permitted to be a complex number?


text:
# Tag Info

0

The ABL beam director system is, or at least was, available in schematic form somewhere on the LockheedMartin website. To answer your specific question: the mirrors in the system are highly developed to withstand high-energy laser beams without damage. The coatings are quite specialized and the substrates are designed for efficient heat-sinking. Even ...

1

Provided that there is nothing for the photon to interact with (i.e. we look at it in vacuum), the mean free path will be infinite; that is, it will continue travelling forever in a given direction. There's nothing which will stop the photon's path. Hence, it will go arbitrarily far. Whether you have a single photon or a laser, the answer won't change. The ...

0

So long as your lens diameter at every plane of interest (stops) is larger than, e.g., the $1/e^4$ diameter, you'll maintain a nice gaussian beam shape. -- at least, assuming a nondiverging source beam. Beyond that, I fear you'll want to get hold of Zemax or equivalent to see exactly what happens to your beam shape.

0

Newton's first law states a particle will have constant velocity unless an external force acts upon it. The photon has no mass, but nonetheless the first law still holds true in the case of light. When a ray of light is projected, (say) from the surface of Earth to outside in space. The condition is that, there is no obstruction to it till infinity ...

3

The answer depends on many factors, but here are the basic bits of physics that play: The power and wavelength of the laser The reflectivity of the surface (function of wavelength of the laser) The size of the focal spot The thickness of the sheet The thermal conductivity of the sheet The reflectivity of the copper is a particularly important one. If you ...

1

Well it all depends on what assumptions you are able and willing to make. For a start you can work out how much of the laser light is reflected. The reflected power will be something like (for normal incidence) $$\frac{P_{r}}{P_i} = \frac{(\eta_m - \eta_{vac})^{2}}{(\eta_{vac} + \eta_m)^2},$$ where $\eta_{vac}=377$ Ohms and $\eta_m$ is the impedance of the ...

0

There are so many variables here i think its nearly impossible to give an answer like how thick is the lazer, how far away is the lazer how reflective is the surface of the metal ......... the more variables there are the harder something is to predict if you wanted an answer it would be much more practical to get one by doing the experinment, probably not ...

0

The distance that a particle can travel is partly set by its mass. If the particle has a mass less than something like 7 eV, then it could cross the universe without attenuation.

0

Whether it be a beam or ray of light, photons will keep traveling until they are absorbed. Photons can't stop because they travel at a constant velocity, the speed of light, i.e., they can't accelerate or decelerate. However, their wavelengths change over time due do the expansion of the universe, i.e, their wavelengths get larger and loose energy as such ...

4

One small addition to the other answers: While it is indeed true that the light will never stop if it doesn't hit anything, it will however get red shifted, and thus become less energetic, due to the expansion of the universe. For example, the cosmic microwave background consists of photons which were emitted back when the atoms formed. However, back then ...

2

A "ray of light" must be respelled as "photon" because here we are talking physics. Between a single photon and a laser beam, in this case, there is no difference. Every photon will continue his travel until stopped, every single photon is "indistinguible" from others (in the sense that they are no different intrinsecally). The photons of a laser beam are ...

2

A ray of light or a laser beam will not stop until it reaches an obstruction. If there is no obstruction, light will NEVER stop. It has no end.

8

Note that it is correct that a photon can travel an infinite distance in an infinite time, but it can not reach any desired point in the universe. This is caused by the expansion of the universe, which also leads to the fact that we can not receive information outside of the observable universe.

12

Theoretically, the photon (or the beam of photons, there really isn't a difference) can go an infinite distance, traveling all the while at a speed $c$. Since photons contain energy, $E=h\nu$, then energy conservation requires the photon to only be destroyed via interaction (e.g., absorption in an atom). There is nothing that could make the photon simply ...

1

Given that you are measuring laser attenuation $\frac{I}{I_0}$ vs. concentration $c$, it is almost certain that you are studying laser attenuation in order to see the Beer-Lambert Law in action (as Chris White alludes to in a comment): $log_{10}\frac{I_0}{I}=\epsilon cL$ "Seeing how much power is lost" is exactly how a UV/Vis spectrophotometer calculates ...

1

Looks like the Astigmatism is measured from the diodes surface as per Stephern Blake's answer. The fast axis divergence is measured from the diodes surfaces and then the astigmatism is the position of the beam source point of the lens behind the diode surface. The fast axis beam waist must be on the diodes surface at Py and the slow axis beam waist at Px. ...

0

You might want to do it if you are studying single photon physics, or testing (say) photo-amplifiers.

20

A photon will travel "at the speed of light" until obstructed. From the speed, and elapsed time, you can calculate how far the light will travel. Laser light consists of more than one photon "in phase", which has exactly the same property in this respect, as a solitary photon.

1

Your proposed setup is pretty close, except that it will also/mainly be sensitive to the classical (non-quantum) fluctuations in the power of the laser. The setup could be made more quantum-ey by adding a beamsplitter and an extra photodetector. Specifically, you have a laser, a 50:50 beamsplitter, and 2 detectors (one at each output port of the ...

2

My impression is the beam is not Gaussian at all, as the beam divergence in two orthogonal planes differs dramatically.

2

What effect are you looking for: Mr. Wizard, Rube Goldberg, or MacGyver? For a clean "Mr. Wizard" effect, use the cloud chamber that others have suggested. This has the simplest hardware setup of the three: put your radiation source by your cloud chamber, point your camera at it, and you're done. But the software will be considerably more difficult than the ...

10

To add to Nathaniel's Answer because (1) it is a good answer and (2) I get nervous recommending radioactive materials handling to anybody I don't know: I would really think about the cloud chamber idea, especially since you're a software guy with a math background. It would need to be inside a darkened container, but you could run a webcam to show what is ...

31

An alternative way to generate random numbers, that truly is quantum, and also quite easy: put a small radioactive source near a Geiger counter. Radioactive decay is a truly random event in the quantum sense, and is basically not subject to thermal noise at all. For maximum visual impact, replace the Geiger counter with a cloud chamber. That way you can ...

0

After thinking about it, I think that perhaps spacing several pinholes by half of the wavelength would filter out any signals traveling in the wrong direction. You would loose a huge amount of energy, so finding a way of (maybe) reflecting the radio waves, until their phase and direction line up, would mitigate the loss. The reason I say maybe is that I'm ...

11

If I understood correctly, what you are trying to build is a hardware based random number generator, where you want to use some quantum mechanics-based mechanism to supply the randomness. I'm no experimentalist, thus, take my comments with a grain of salt. Your suggestion is to use Schottky noise from a illuminated photodiode. I believe that it's a pretty ...

4

A population inversion can only be achieved when the probability of spontaneous emission is small; so usually a single spontaneously emitted photon will give rise to stimulated emission and this sets up the laser action. However, if two photons were by chance spontaneously emitted simultaneously, then two modes could start to form in the laser cavity - one ...

1

Your are not describing stimulated emission, but spontaneous emision. In such a case, when an electron is excited from a lower to a higher energy level, it will not stay that way forever. An electron in an excited state may decay to a lower energy state which is not occupied, according to a particular time constant characterizing that transition. When such ...

5

The ${\rm sech}$ pulse is, in Kerr effect nonlinear optical mediums, an Optical Soliton. This means that it is the particular time variation such that the tendency of the pulse to spread out in time owing to linear dispersion is exactly counterbalanced by the nonlinear effect that tends to confine pulses in time. This balance is a stable one in a Kerr ...

Top 50 recent answers are included


text:
# Two Plus Two Equals Four Until You Redefine Addition

Like everything else, the Babylon Bee had fun with this:

In a mathematics lesson delivered to her kindergarten class Tuesday, local teacher and closed-minded bigot Becky Delatorre reportedly insisted that two plus two equals four, all the time, to the exclusion of all other numbers, no matter how anyone feels about it.

Well…we turn to the famous Russian mathematician Israel Gelfand’s Lectures on Linear Algebra (Dover Books on Mathematics), who at the start makes this definition:

Breaking it down, in the italics he makes a definition of what a vector space is.  At the core of that definition is what linear algebra (which itself is at the core of numerical methods, computer simulations, etc.) is all about: everything that happens is basically scalar addition (which is what the kindergarten teacher in the Bee was trying to teacher her bratty students) and scalar multiplication, and lots of it for large models.

That definition made, Gelfand sets forth eight (8) rules for these two operations to follow in order to be valid.  At this point, Gelfand puts in the kicker:

It is not an oversight on our part that we have not specified how elements of $R$ are to be added or multiplied by numbers.  Any definitions of these operations are acceptable as long as the axioms listed above are satisfied.  Whenever this is the case we are dealing with an instance of a vector space.

What he is saying is this: for a valid vector space, we can redefine addition and multiplication as long as it meets the eight rules!  An example of how that works is here.

This is an interesting twist in mathematics that, mercifully, doesn’t have much practical application.  But I suppose it’s possible to shut up (or put to sleep, either result works) a class of unruly kindergartners with the eight rules.  And having endured stuff like this makes attacking Bill Clinton’s Eucharistic Theology even more fun.

Better stick with $2 + 2 = 4$