NDSolve::dvlen: The function [Theta][t] does not have the same number of arguments as independent variables

please help me to see what wrong with my code?

s = NDSolve({(m*g*
   Sin((Theta)(t))) - (m*(r''(t) - r (((Theta)'(t))^2))) == 
k (r(t) - 14),  g*Cos((Theta)(t)) == 
r(t) (Theta)''(t) + 2*r'(t) (Theta)'(t), (Theta)'(0) == 0, 
 r'(0) == 0}, {r, (Theta)}, {t, 0, 60}, {k, 0, 2000})

i want to solve this two equation to find equation of r(t). I’ve already set up m and g

java – Counting the number of unique IP addresses in a very large file. Follow-Up #1

It’s a follow-up question.
A previous version
of this code has been posted on Code Review about 2 weeks ago.

What was done after the last review

In fact, the entire application is rewritten from scratch. Here
is current version with tests and JavaDoc.

I tried to split the application into small classes that have only one responsibility and can be re-used and extended.

The main approach to solve a problem has not changed. I still put one value in accordance with each ip and set a bit with the corresponding index in the bit array. The required amount of memory remained the same about 550-600 MB. The speed has increased, now I am practically limited to the performance of my hard disk. It is still assumed that only valid IPs will be in the file.

I deleted all JavaDoc comments from code examples, because they occupy more space than the code itself.

FixedSizeBitVector

I wrote a simple implementation of the bit array that allows you to store N bits with indexes from 0 to N-1. There are
three operations are supported: set bit, examine bit’s value, and get the number of all the set bits.
getCapacity() method used for testing and may be useful in other cases.

I do not bring the BitVector interface due to its primitiveness and simplicity.

package chptr.one;

public class FixedSizeBitVector implements BitVector {

    public static final long MIN_CAPACITY = 1L;
    public static final long MAX_CAPACITY = 1L << 32;

    private final long capacity;
    private final int() intArray;
    private long cardinality;

    public FixedSizeBitVector(long capacity) {
        if (capacity < MIN_CAPACITY || capacity > MAX_CAPACITY) {
            throw new IllegalArgumentException("Capacity must be in range (1.." + MAX_CAPACITY + ").");
        }
        int arraySize = 1 + (int) ((capacity - 1) >> 5);
        this.intArray = new int(arraySize);
        this.capacity = capacity;
    }

    private void checkBounds(long bitIndex) {
        if (bitIndex < 0 || bitIndex >= capacity) {
            throw new IllegalArgumentException("Bit index must be in range (0.." + (capacity - 1) + ").");
        }
    }

    @Override
    public void setBit(long bitIndex) {
        checkBounds(bitIndex);
        int index = (int) (bitIndex >> 5);
        int bit = 1 << (bitIndex & 31);
        if ((intArray(index) & bit) == 0) {
            cardinality++;
            intArray(index) |= bit;
        }
    }

    @Override
    public boolean getBit(long bitIndex) {
        checkBounds(bitIndex);
        int index = (int) (bitIndex >> 5);
        int bit = 1 << (bitIndex & 31);
        return (intArray(index) & bit) != 0;
    }

    @Override
    public long getCapacity() {
        return capacity;
    }

    @Override
    public long getCardinality() {
        return cardinality;
    }
}

UniqueStringCounter

This class implements the counter of unique lines in the input Iterable<String> sequence. The counter uses BitVector
implementation. To work, it is required that the input sequence has a final number of possible string-values and this
amount did not exceed the maximum capacity of the bit vector used.

It also requires a hash function that puts a String and a long in an unambiguous match.

package chptr.one;

import javax.validation.constraints.NotNull;
import java.util.Objects;
import java.util.function.ToLongFunction;

public class UniqueStringCounter {

    private final Iterable<String> lines;
    private final ToLongFunction<String> hashFunction;
    private final BitVector bitVector;
    private long linesProcessed;

    public UniqueStringCounter(@NotNull Iterable<String> lines,
                               long capacity,
                               @NotNull ToLongFunction<String> hashFunction) {

        Objects.requireNonNull(lines);
        Objects.requireNonNull(hashFunction);
        this.lines = lines;
        this.hashFunction = hashFunction;
        this.bitVector = new FixedSizeBitVector(capacity);
    }

    public long count() {
        for (String line : lines) {
            long value = hashFunction.applyAsLong(line);
            bitVector.setBit(value);
            linesProcessed++;
        }
        return bitVector.getCardinality();
    }

    public long getLinesProcessed() {
        return linesProcessed;
    }
}

IpStringHashFunction

Hash function to convert a String to a long value. This function must generate a unique value for each unique line,
the collisions are not allowed.

I tested several options for the conversion of IP-String in the long-value and came to the conclusion that they all work around at the same speed that the InetAddress. I do not see the reasons to write my own implementation when the speed of the library function is completely satisfied.

The processing of exceptions really is not needed here, because according to the terms of the task, I am guaranteed that there will be only valid IP. I had to make this processing since otherwise I can’t use this function as a parameter for UniqueStringCounter.

package chptr.one;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.function.ToLongFunction;

public class IpStringHashFunction implements ToLongFunction<String> {

    @Override
    public long applyAsLong(String value) {
        long result = 0;
        try {
            for (byte b : InetAddress.getByName(value).getAddress())
                result = (result << 8) | (b & 255);
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        return result;
    }
}

BufferedReaderIterable

A simple adapter that allows you to work with BufferedReader as with Iterable. I could not come up with a better way
to send the contents of the file in UniqueStringCounter, which expects to the Iterable<String> as parameter.

package chptr.one;

import javax.validation.constraints.NotNull;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;

public class BufferedReaderIterable implements Iterable<String> {

    private final Iterator<String> iterator;

    public BufferedReaderIterable(@NotNull BufferedReader bufferedReader) {
        Objects.requireNonNull(bufferedReader);
        iterator = new BufferedReaderIterator(bufferedReader);
    }

    public Iterator<String> iterator() {
        return iterator;
    }

    private static class BufferedReaderIterator implements Iterator<String> {

        private final BufferedReader bufferedReader;

        private BufferedReaderIterator(BufferedReader bufferedReader) {
            this.bufferedReader = bufferedReader;
        }

        @Override
        public boolean hasNext() {
            try {
                return bufferedReader.ready();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String next() {
            String line;
            try {
                line = bufferedReader.readLine();
                if (line == null) {
                    try {
                        bufferedReader.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return line;
        }
    }
}

IpCounterApp

The main class of the application. Accepts the file name in the -file parameter.

package chptr.one;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;

public class IpCounterApp {

    private static String parseFileName(String() args) {
        Objects.requireNonNull(args, "No arguments found. Use -file file-name to processing file.");
        if (args.length == 2 || "-file".equals(args(0))) {
            return args(1);
        }
        return null;
    }

    public static void main(String() args) {
        String fileName = parseFileName(args);
        if (fileName == null) {
            System.err.println("Wrong arguments. Use -file file-name to processing file.");
            return;
        }

        Path filePath = Paths.get(fileName);
        if (!Files.exists(filePath)) {
            System.err.printf("File %s does not exists.n", filePath);
            return;
        }

        try {
            System.out.printf("Processing file: %sn", filePath);
            long startTime = System.nanoTime();
            BufferedReader bufferedReader = Files.newBufferedReader(filePath);
            Iterable<String> strings = new BufferedReaderIterable(bufferedReader);
            UniqueStringCounter counter = new UniqueStringCounter(strings, 1L << 32, new IpStringHashFunction());
            long numberOfUniqueIp = counter.count();
            long linesProcessed = counter.getLinesProcessed();
            long elapsedTime = System.nanoTime() - startTime;
            System.out.printf("Unique IP addresses: %d in total %d.n", numberOfUniqueIp, linesProcessed);
            System.out.printf("Total time: %d milliseconds.n", elapsedTime / 1_000_000);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Why do I ask the new Review?

In previous question
I received a few excellent answers and one excellent bug report. I tried to take into account so many comments as I
could. I also tried to reconsider my approach to the design of classes. I am interested in mostly three questions:

  • How are my new classes are suitable for re-use and extension? What other abstractions can be allocated here and should
    it be done?
  • What should I do with error processing? I know that now it is bad. I just try to fall as early as possible.
  • And most importantly. Do I move in the right direction? I am a newbie in programming and get an overview for my code is
    the only way to learn how to write a quality and understandable code.

Table/list: find the last real number element of each row to constitute a list

I have a list (Table), mostly composed of real numbers. The list also contains some non-real elements. The list is similar to the following (but much much larger):

{{0.11011887269, 0.02087291466, 0.02082444233, 0.02083704779, 
  0.02084940959, 0.02086181292, 0.02087425501, 0.02088673503, 
  0.02089925331, 0.02091181001, 0.02092440529, 0.02093703933, 
  0.02094971232, 0.02096242441, test1(18, 15)}, {0.10941526373, 
  0.017604005802, 0.017549654594, 0.017558686829, test1(19, 5), 
  test1(19, 6), test1(19, 7), test1(19, 8), test1(19, 9), 
  test1(19, 10), test1(19, 11), test1(19, 12), test1(19, 13), 
  test1(19, 14), test1(19, 15)}, {0.10890647143, 0.014986243752, 
  0.014927392616, 0.014934004368, test1(20, 5), test1(20, 6), 
  test1(20, 7), test1(20, 8), test1(20, 9), test1(20, 10), 
  test1(20, 11), test1(20, 12), test1(20, 13), test1(20, 14), 
  test1(20, 15)}}

I would like to construct a single row or column list that preserves the last real number element of each row of the above list. For example, with the above table, the resulting list should contain only 3 elements as:

{0.02096242441, 0.017558686829, 0.014934004368}

How can this resulting list be automatically constructed from the original one?

inverse – How to get x value where area under curve is some number?

My goal is to get x value where area under the curve (from the x ~ infinity) is about 0.05. But the code which I have tried shows errors. How to correct it?

Solve(!(
*SubsuperscriptBox(((Integral)), (x), ((Infinity)))(
*FractionBox((
*SuperscriptBox((E), ((-x)/2)) 
*SuperscriptBox((x), (3/2))), (3 
*SqrtBox((2 (Pi))))) (DifferentialD)x)) == 0.05, x)

Unprotect number constants

1 is not a valid symbol name. Set says that it is a raw object. How much do I need to break to make 1 a symbol, so that 1=stuff;1 evaluates to stuff?

Of course this is never useful in practice, and I imagine any way of doing it would need two kernel restarts just to wash away the dirty. I’m just curious, unless it’s built straight into the kernel.

analytic number theory – What’s the average order of the reduction of a section of an elliptic curve

Suppose $E$ is an elliptic curve over $mathbb Q$ and $x in E(mathbb Q)$ is not torsion. We can reduce $x pmod p$ for a prime $p$ of good reduction and it will have some order $n_p$ in the group $E(mathbb F_p)$. Has there been any work on the asympotitcs of the average of $n_p$ for $p < X$ as $X to infty$?

More generally, suppose $x,y in E(mathbb Q)$ are two linearly independent sections and let them generate subgroups $G_x(p),G_y(p) subset E(mathbb F_p)$ for a prime of good reduction. Have the asymptotics of the average of $G_x(p)cap G_y(p)$ been studied?

This question seems tangentially related.

linux – enough free pages but high number of major page faults and page reclaims

We find that for some servers io disk read is very high. We also notice that there are many major page faults on those servers. But we checked the /proc/zoneinfo, there are enough free pages. Here is the content of /proc/zoneinfo:

pages free     3913507
        min      11333
        low      14166
        high     16999
        scanned  0
        spanned  16777216
        present  16777216
        managed  16507043
    nr_free_pages 3913507

We also use “perf” to monitor the event of “mm_filemap_delete_from_page_cache”. Here is the result of perf:

7fff81189dd0 __delete_from_page_cache ((kernel.kallsyms))
        7fff8119b771 __remove_mapping ((kernel.kallsyms))
        7fff8119c8e8 shrink_page_list ((kernel.kallsyms))
        7fff8119d45a shrink_inactive_list ((kernel.kallsyms))
        7fff8119df55 shrink_lruvec ((kernel.kallsyms))
        7fff8119e376 shrink_zone ((kernel.kallsyms))
        7fff8119e880 do_try_to_free_pages ((kernel.kallsyms))
        7fff8119ed6c try_to_free_pages ((kernel.kallsyms))
        7fff816ac515 __alloc_pages_slowpath ((kernel.kallsyms))
        7fff811932d5 __alloc_pages_nodemask ((kernel.kallsyms))
        7fff811d7a68 alloc_pages_current ((kernel.kallsyms))
        7fff811e27f5 new_slab ((kernel.kallsyms))
        7fff811e40fc ___slab_alloc ((kernel.kallsyms))
        7fff816adaf1 __slab_alloc ((kernel.kallsyms))
        7fff811e609b kmem_cache_alloc ((kernel.kallsyms))
        7fff812778ed proc_alloc_inode ((kernel.kallsyms))
        7fff812234d0 alloc_inode ((kernel.kallsyms))
        7fff81225771 new_inode_pseudo ((kernel.kallsyms))
        7fff812257d9 new_inode ((kernel.kallsyms))
        7fff8127bc1e proc_pid_make_inode ((kernel.kallsyms))
        7fff812800e5 proc_fd_instantiate ((kernel.kallsyms))
        7fff8127c54c proc_fill_cache ((kernel.kallsyms))
        7fff812802dd proc_readfd_common ((kernel.kallsyms))
        7fff812803f5 proc_readfd ((kernel.kallsyms))
        7fff8121c246 vfs_readdir ((kernel.kallsyms))
        7fff8121c665 sys_getdents ((kernel.kallsyms))
        7fff816c2715 system_call_fastpath ((kernel.kallsyms))
               bab95 __getdents64 (/usr/lib64/libc-2.17.so)

It seems that os is carrying on page reclaim. But I don’t know since there are enough free pages, why could page reclaim ocurr?

combinatorics – Number of ways a committe can be formed

In how many ways can a committee of four be formed from 10 men (including Richard)
and 12 women (including Isabel and Kathleen) if it is to have two men and two women

a) Isabel refuses to serve with Richard,

b) Isabel will serve only if Kathleen does, too

My Thoughts :
a) Total number of ways to select 4 people = 22C4 now for part a) I just need to deduct the
pairs where Isabel and Richard are both in the committe which = 20C2

I am not sure how to proceed with part (b) and if part (a) is entirely correct

Script Linux Bash, print grep output based on number of words in line

I’m trying to write a scirpt for the bash shell. I’m given 4 parameters:

  1. path of a directory
  2. extension of a file
  3. a word
  4. a number

I have to look for all files and files of subdirectories of the path, for files with the given extension. Then, look in the files for the lines matching the word given, but only if the number of words in the line is bigger or equal to the number provided.
For example:
If localDirectory has: image.png script.sh text.txt.
And text.txt has:

This is a text file
It contains many words
This is an example for a simple text file

Then give the command: ./example.sh localDirectory txt text 7
I should output: This is an example for a simple text file.

For now, my script looks like this:

if [ "$#" -ne 4 ];
then
  echo "Not enough parameters"
  exit 1
fi
find $1 -name "*.$2" -exec grep -wi $3  {} ;

And it works just fine for the first 3 goals, I just don’t know how to filter now the result such that the line has a greater or equal number of words as $4.

I could of course create a new file and output there, and then read from it and print only the relevant lines, but I would rather do this without creating new files.

I’m very new to shell scripting.

Any ideas?

I am developing a plugin, in it user can specify that timer will run for like 30 minutes for a number of times

User can set that timer will be shown for 30 minutes at for example 1200 hrs on 17th April. and after that 30 minutes timer will run again for 30 minutes for like 5 times(number of times specified by the admin). In this regard any help will be appreciated. I have built the remaining logic of the plugin but I can’t manage the timer. I can run it on frontend but it gets disturbed when user refreshes it. I need it so that timer keeps running on server whether a user is loading the website or not and if a user refreshed page timer does not restarts. Thanks.