text:
# Shortest time to meet

Three runners are located at the corners of an equilateral triangle, 100 meter a side. They run to a point inside the triangle and their goal is to do it as fast as possible. If they run at the same speed the natural point is the middle of the triangle. The challenge is to devise the meeting point if their speeds are 3, 4, and 5 meters per second respectively.

• I presume the puzzle is to find the point so that they all arrive there at the same time? – xnor Jun 2 at 4:41
• To get the shortest time you can show that they need to arrive at the same time. – Moti Jun 2 at 7:36

Now that you've specified that you want a geometric construction...

The basic idea here is that we'll flip the problem. Instead of directly constructing the point inside the triangle, we'll consider the following alternate problem:

Given three concentric circles of radii 3, 4, and 5. construct an equilateral triangle, each of whose vertices lie on a different one of these circles.

If we construct such a triangle $$\triangle DEF$$, then the center of the circles $$O$$ would be a point 3, 4, and 5 units from $$D$$, $$E$$, and $$F$$, in some order. This is the point we want, and then we simply need to transfer the point over to the original triangle by mapping the two triangles using a dilation, a rotation, and a translation.

So here's our three circles. Choose an arbitrary point $$A$$ on the outermost circle.

Now here's the clever idea of the day. Suppose our desired equilateral triangle is $$\triangle ABC$$, with $$A$$ on the outermost circle, $$B$$ on the second circle, and $$C$$ on the innermost circle. Then the point $$C$$ is what you get when you rotate $$B$$ 60 degrees around $$A$$. It follows that if I rotate the entire second circle around $$A$$, it will intersect the innermost circle at $$C$$. But that means I'm done!

We rotate the second circle 60 degrees counter-clockwise about $$A$$:

Mark the intersection point with the innermost circle:

Then constructing the last point is easy:

The observant reader will note that depending on what direction I choose to rotate the circle, or which intersection point I mark, there could be other equilateral triangles that satisfy the conditions. From some brief thought, I believe there are 4 in total, two of which work because $$O$$ is inside the triangle, whereas the other two do not because $$O$$ would lie outside said triangle for those constructions.

Anyways, we have our magic point inside a dummy triangle, so transfer it over and you're done.

• Very nice. I can see that it is "equilateral":) Not the way I had in mind - actually more elegant than mine. I hope you see the value in delaying my "award"! The only thing missing is, how the 60 degrees rotation translates it with a different way the rotating by 70? Why ABC is 60? – Moti Jun 10 at 16:06
• It seems that you do not see the difference between a construction and a proof. You need to have a set of statements that result mathematically the conclusion that BAC = 60. When you get have the proof I will accept the solution. – Moti Jun 17 at 18:50
• @Moti I'm going to restate the proof I've been giving you: Suppose the equilateral triangle $\triangle ABC$ exists on those three circles satisfying our conditions. Then since $B$ rotated 60 degrees around $A$ will give $C$, rotating the set of possible points for $B$ (the middle circle) 60 degrees around $A$ will necessarily intersect the set of possible points for $C$ (the inner circle) exactly at $C$. Thus $A$ and $C$ are two correct vertices of an equilateral triangle satisfying our conditions, and the proof that $B$ is constructed correctly is trivial from the two green circles. – greenturtle3141 Jun 18 at 0:06
• I believe that I understand your claims. You should start your proof by stating that BAC by definition is 60. Than you continue by stating that you rotate all the structure by 60 - showing the rotated triangle ,may be with the two circles demonstrating that the order of creating the intersection is important. – Moti Jun 18 at 2:07

I'm not sure what exactly you want but here you go:

Suppose the equilateral triangle is $$\triangle ABC$$. Suppose further that the 5 m/s runner starts at $$A$$, the 4 m/s runner starts at $$B$$, and the 3 m/s runner starts at $$C$$. Then the point where the runners need to meet is the unique point $$P$$ satisfying:

• $$AP = \dfrac{500}{\sqrt{25+12\sqrt{3}}}$$
• $$BP = \dfrac{400}{\sqrt{25+12\sqrt{3}}}$$
• $$CP = \dfrac{300}{\sqrt{25+12\sqrt{3}}}$$

We can draw circles centered at $$A$$, $$B$$, $$C$$ with the above radii to verify that they are concurrent:

This also shows that this is a perfectly constructable, well-defined point. Your question does not specify to what degree we must define this point, so I'll leave it like this.

I will now prove that the above distances are the desired.

We are essentially solving for $$x$$ in the following diagram:

Rotate the entire diagram 60 degrees clockwise around $$B$$:

Because we rotated 60 degrees, $$\angle PBP' = 60^\circ$$. But then $$\triangle PBP'$$ is equilateral, so $$PP' = 4x$$.

We conclude that $$\angle P'PC$$ must be right, so $$\angle BPC = 90+60 = 150^\circ$$. By the Law of Cosines on $$\triangle BPC$$:

$$100^2 = 16x^2 + 9x^2 + 12\sqrt{3}x^2$$

Solving gives $$\boxed{x = \dfrac{100}{\sqrt{25+12\sqrt{3}}}}$$, as desired.

• This is a solution but I am looking for a more elegant one without the need of higher level of knowledge in trigonometry - basic Euclidian approach. – Moti Jun 7 at 5:33
• But this WAS a very basic Euclidean approach. I don't use any "advanced" trigonometry until the very end with the Law of Cosines. How exactly do you want us to define this point? Multiple correct answers were given, I don't really think you should just expect us to guess the method you're thinking of because simplicity is subjective. – greenturtle3141 Jun 7 at 13:02
• You use trig - Law of Cosine. There is a way to prove this with basic diagrams. – Moti Jun 7 at 19:21
• @Moti Prove what? – greenturtle3141 Jun 7 at 19:49
• To show a way/proof where the ratio can be any - a, b, c. Your approach using trig extension to the general case will be way too complicated. – Moti Jun 7 at 19:56

Well, maybe there's a more puzzleriffic solution to this, but here's my go with a compass and a straightedge, because why not. :-)

I'm not going to bother with spoiler tags, since this answer is kind of long, and just seeing a couple of the first images in not going to spoil anything for anyone. Also, this method feels a bit.. forceful, there's probably a neater way to do all this. But anyway.

Because naming things is hard, I chose A as the runner with speed 4, B's speed is 5, and C's speed is 3.

We'll want to find the points which the runners would reach at the same time. We'll do that by plotting such loci (Oo, Latin!) pairwise, and then finding the intersection(s) of those plots.

Let's start by drawing a circle with radius 4 around A, and another with radius 5 around B. As long as those circles intersect, the actual units don't matter. I tried to pick something that gives a halfway readable diagram. Let's name the points where those circles intersect D and E. If the runners A and B would choose either of those points, they would obviously arrive at the same time.

Next, we choose one of those points (E), and consider the angle $$\angle$$AEB:

We want one more point whose distance is at the desired ratio of "4 from A, 5 from B". We could do that by choosing another length unit, and drawing two more circles at A and B, but instead of that, we can also bisect the angle $$\angle$$AEB to find point I, and then use the angle bisector theorem to show that point I splits the segment AB at the desired proportions: line EI will bisect the angle $$\angle$$AEB if and only if the ratio $$\frac{\mid\text{AI}\mid}{\mid\text{BI}\mid}$$ is equal to to the ratio $$\frac{\mid\text{AE}\mid}{\mid\text{BE}\mid}$$, which is, by our construction, $$\frac{4}{5}$$.

Now we have three points, E, I and D, all located so that their distance from A is 4/5 of their distance from B. Thus we can construct (using perpendicular bisectors of EI and ID, not shown) a circle through those points. This is called a Circle of Apollonius, and by its construction, we know that all points on this circle share the property that their distance from A is 4/5 of their distance from B. In other words, all points that runners A and B would reach at the same time lie exactly on the circle $$\circ$$EID.

Then we can just repeat the procedure for B and C with circle size ratio 5:3, and we'll find the second Apollonian circle through J, O and K:

And now we can see that the two Apollonian circles intersect twice, at P and Q. P is inside the triangle, so that's going to be our spot:

Since we want to be thorough, let's add the third Apollonian circle for A and C (at ratio 4:3) to confirm that it too passes through P (and Q).

This should be trivially true, since P (or for that matter, Q) is on both of the earlier Apollonian circles, meaning that runners A and B would reach it simultaneously, and also that runners B and C would reach it simultaneously. The third Apollonian circle plots all the the points that runners A and C would reach simultaneously, so by the transitivity of "simultaneity", P (and Q) should obviously be on the third circle, too.

How nice, it all worked out as expected! So there we have it, the runners should meet at P.

(If they chose to meet at Q instead, they would all arrive at the same time there, too. However, that would take a lot longer.)

All images plotted with the excellent GeoGebra tool, and screenshotted from there.

• So complicated - will take me some time to digest... – Moti Jun 2 at 7:25
• There is way simpler way without the need to know about Circle of Apollonius (is it easy to prove it? - did not try) – Moti Jun 2 at 7:34
• @Moti, yeah, that's often the problem with using just a compass and straightedge; it would be a lot easier to find point I by saying "starting at A, go $44.44..$ metres towards B", but it's kind of the whole point of the exercise to show that it can be done without using such superfluous tools as a tape measure :-) – Bass Jun 2 at 7:36
• You did not need to do it that way - you can use different circles -) I can email you the elegant solution with basic geometry tools. – Moti Jun 2 at 7:38
• @Moti no need, we'll see if someone else can come up with it, and if they don't, you can post it as a self-answer after a couple of days. – Bass Jun 2 at 7:39

There is a little dilemma with this question;

since there are two targets A would like to go, to which direction should A move to meet with B and C? and visa versa.?

which forces you assume something like;

They know their own speed and decide where to meet which will be shortest distance to meet for sure since they move straight all the time.

or

they have to check others' location at any time they move and move towards between two distance which will be some other kind of hard geometry question in my opinion.

So I will go for the first one first,

This is a question to find a point inside a triangle where

the distance from A (5), B (4) and C (3) will be 5x, 4x and 3x respectively.

or

so it becomes a pure geometry question but the answer is

For the second case the answer will be something like:

but geometrically a better way to show and proof is needed. It takes maybe a little more than first one but the shortest will be for sure the first one.

• It is not a tracking problem - they know the speed and task and can coordinate between them. – Moti Jun 7 at 5:37

This is a solution, but it assumes that we have time to do some coordination with the runners before running towards the critical point.

Label the vertices A, B, and C. Get the 4m/s runner to run towards (and beyond) point B from point A, and the 3m/s runner to run away from the 4m/s runner (or away from point A) from point B (it may help to first use a straightedge to mark a line for the runners to follow). Mark the point that they meet. Now do the same thing again, except this time the 3m/s runner should run towards the 4m/s runner. You should now have two points. It should be fairly easy to draw a circle that has those points as it's diameter (you might want to find the midpoint first, then it's easy to mark the circle with a compass).
Now repeat this whole process with the 3m/s runner starting from point B, and the 5x runner from point C, this time, the 3m/s runner always running towards the 5x. The point of intersection of the two circles that are marked that lies inside the equilateral triangle should be the correct point for all the runners to run towards. (each runner starts from the same point that they started from in all of the trial runs)
Here is a diagram, showing how each part is constructed:

note that:

this solution also uses the circle of Apollonius, but more directly

Is this to be considered a satisfactory answer?

• No need for Apollonius - basic Euclidian. – Moti Jun 7 at 5:36


text:
# PHP OPCodes Cached with APC - part 1

## October 21, 2009

There are many caching system in use to optimize the execution of PHP script on busy web/database servers. Today we will focus on the OPcode caching method using APC.

#### Before we start… what is an OPcode?

The OPcode is an executable code generated each time a PHP script is interpreted and compiled. Each time you visit a webpage, the webserver (apache for example) would generate an OPcode of the PHP script serving your request. They are therefore simply C data structure which are interpreted by the PHP Virtual Machine (Zend Engine).

Now you can imagine, generating the OPcode can be a drain on the server and quite useless if the code does not change often. This is where the OPcode caching system comes into play; but before we go on, let’s see some OPcode example using the Vulcan Logic Disassembler.

First, we create a file test.php in which we will execute a unix ls -l command

test.php - <? system(“ls -l”); ?>

wrk01:/var/www# php -d vld.active=1 test.php Branch analysis from position: 0 Return found filename:       /var/www/test.php function name:  (null) number of ops:  4 compiled vars:  none

## line     #  op                           fetch          ext  return  operands

2     0  SEND_VAL                                                 ‘ls+-l’ 1  DO_FCALL                                      1          ‘system’ 4     2  RETURN                                                   1 3* ZEND_HANDLE_EXCEPTION

Now let’s try a simple ( echo “hello world!” )

wrk01:/var/www# php -d vld.active=1 test.php Branch analysis from position: 0 Return found filename:       /var/www/test.php function name:  (null) number of ops:  3 compiled vars:  none

## line     #  op                           fetch          ext  return  operands

2     0  ECHO                                                     ‘hello+world%21’ 4     1  RETURN                                                   1 2* ZEND_HANDLE_EXCEPTI

In our first example, we had 4 OPcodes and in our second, 3 OPCodes… while 3,4 makes no difference whatsoever, it would be interesting to estimate how many OPcodes, an application such as WordPress generates :-). But as you guessed, the more opcodes to generate, the longer the execution process would take, leading to slow performance.

#### Now what is APC ?

APC stands for Alternative PHP Cache; what it does, is to simply cache those OPcodes into a memory by providing a locking mechanism and a suite of routines to add newer cache, remove expired data cache and pull out the OPcode cache from memory. It also provides you within its framework API to see stats on which OPcodes are cached, which script have been executed, which ones have missed to be cached etc..

APC has also been developed like a Zend Extension, thus it is possible to just implement it in your current PHP install as a module. Furthermore it requires no script side modification as APC is transparent to your PHP developers.

Before we go on, let’s install APC

On Debian

wrk01:~# apt-get install php-apc

You can also install it using PECL

wrk01:~# pecl install apc

Now APC is enabled with the default values and settings. Let’s spend some time now discussing the Locking Type mechanism used by APC, as it will allow us to explore furthermore APC.

APC Support

enabled

Version

3.0.19

MMAP Support

Enabled

no value

Locking type

Revision

$Revision: 3.154.2.5$

As we see in our phpinfo() output, APC is currently using the “pthread mutex Locks”. It is important to keep in mind that, they are other Locking mechanism available as the “Inter-Process Control”, the “Linux Futext” and Spin locks.

Why having a Locking Mechanism? Because APC caches the OPcodes into shared memory, it is important to control access modification to those cache by other processes and thus protect data integrity.

In the second part of this post, I will go over on how to tweak and configure APC using the APC configuration “apc.ini” file.

If you recall, I said earlier that APC was transparent to the PHP developers; while that is true, it isn’t limited to it. As a matter of fact, APC allows you to store variables, results of SQL queries directly into the cache. This is therfore refered as the User Data Cache.

#### User Data Cache

Let’s imagine, you have a wordress blog with more than 1000 posts and well you wish to provide diverse statistics over those 1000 posts such as “number of comments, number of votes etc…”. If your stat script would query your database each time someone visits your site to gather the stats, it could easily result in a bottleneck if you are having more than 1000+ users at once visiting your blog. The ideal would be to therefore cache the stat results into cache.

The following APC function allow you to directly manipulate the APC cache.

Info

1. array apc_cache_info ([ string $cache_type [, bool$limited ]] )
2. array apc_sma_info ([ bool $limited ] ) Insertion 1. bool apc_store ( string$key , mixed $var [, int$ttl ] )
2. bool apc_add ( string $key , mixed$var [, int $ttl ] ) 3. bool apc_compile_file ( string$filename )

Retrieve data

1. mixed apc_fetch ( string $key ) Deletion 1. bool apc_delete ( string$key )
2. bool apc_clear_cache ([ string $cache_type ] ) Quick Example of APC User Data Cache We assume that we have a function called gatherStats() which queries the database and returns a value such as the number of posts. The variable stocking the number of posts is$myStats and we want to cache that variable for 30mn. We will be using 2 APC functions bool apc_store ( string $key , mixed$var [, int $ttl ] ) and mixed apc_fetch ( string$key )

if (!$myStats = apc_fetch(‘myStats’)) {$myStats = gatherStats();

apc_store(‘myStats’,\$myStats,1800);

}

We first check if the key myStats exists in the APC cache using the apc_fetch boolean function, if it doesn’t we query our database and stock the value in the cache using the apc_store function.

I hope that was informative, I will be writing Part 2 soon which will tackle the general configuration and tweaking of APC.

Cheers,

format: plain


text:
## File: mChoice.Rd

package info (click to toggle)
hmisc 4.2-0-1
 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 \name{mChoice} \alias{mChoice} \alias{format.mChoice} \alias{print.mChoice} \alias{summary.mChoice} \alias{as.character.mChoice} \alias{as.double.mChoice} \alias{inmChoice} \alias{match.mChoice} \alias{[.mChoice} \alias{print.summary.mChoice} \alias{is.mChoice} \alias{Math.mChoice} \alias{Ops.mChoice} \alias{Summary.mChoice} \title{Methods for Storing and Analyzing Multiple Choice Variables} \description{ \code{mChoice} is a function that is useful for grouping variables that represent individual choices on a multiple choice question. These choices are typically factor or character values but may be of any type. Levels of component factor variables need not be the same; all unique levels (or unique character values) are collected over all of the multiple variables. Then a new character vector is formed with integer choice numbers separated by semicolons. Optimally, a database system would have exported the semicolon-separated character strings with a \code{levels} attribute containing strings defining value labels corresponding to the integer choice numbers. \code{mChoice} is a function for creating a multiple-choice variable after the fact. \code{mChoice} variables are explicitly handed by the \code{describe} and \code{summary.formula} functions. \code{NA}s or blanks in input variables are ignored. \code{format.mChoice} will convert the multiple choice representation to text form by substituting \code{levels} for integer codes. \code{as.double.mChoice} converts the \code{mChoice} object to a binary numeric matrix, one column per used level (or all levels of \code{drop=FALSE}. This is called by the user by invoking \code{as.numeric}. There is a \code{print} method and a \code{summary} method, and a \code{print} method for the \code{summary.mChoice} object. The \code{summary} method computes frequencies of all two-way choice combinations, the frequencies of the top 5 combinations, information about which other choices are present when each given choice is present, and the frequency distribution of the number of choices per observation. This \code{summary} output is used in the \code{describe} function. \code{in.mChoice} creates a logical vector the same length as \code{x} whose elements are \code{TRUE} when the observation in \code{x} contains at least one of the codes or value labels in the second argument. \code{match.mChoice} creats an integer vector of the indexes of all elements in \code{table} which contain any of the speicified levels \code{is.mChoice} returns \code{TRUE} is the argument is a multiple choice variable. } \usage{ mChoice(\dots, label='', sort.levels=c('original','alphabetic'), add.none=FALSE, drop=TRUE) \method{format}{mChoice}(x, minlength=NULL, sep=";", \dots) \method{as.double}{mChoice}(x, drop=FALSE, ...) \method{print}{mChoice}(x, quote=FALSE, max.levels=NULL, width=getOption("width"), ...) \method{as.character}{mChoice}(x, ...) \method{summary}{mChoice}(object, ncombos=5, minlength=NULL, drop=TRUE, ...) \method{print}{summary.mChoice}(x, prlabel=TRUE, ...) \method{[}{mChoice}(x, ..., drop=FALSE) match.mChoice(x, table, nomatch=NA, incomparables=FALSE) inmChoice(x, values) is.mChoice(x) \method{Summary}{mChoice}(..., na.rm) } \arguments{ \item{na.rm}{ Logical: remove \code{NA}'s from data } \item{table}{ a vector (mChoice) of values to be matched against. } \item{nomatch}{ value to return if a value for \code{x} does not exist in \code{table}. } \item{incomparables}{ logical whether incomparable values should be compaired. } \item{...}{ a series of vectors } \item{sort.}{ By default, choice codes are sorted in ascending numeric order. Set \code{sort=FALSE} to preserve the original left to right ordering from the input variables. } \item{label}{ a character string \code{label} attribute to attach to the matrix created by \code{mChoice} } \item{sort.levels}{ set \code{sort.levels="alphabetic"} to sort the columns of the matrix created by \code{mChoice} alphabetically by category rather than by the original order of levels in component factor variables (if there were any input variables that were factors) } \item{add.none}{ Set \code{add.none} to \code{TRUE} to make a new category \code{'none'} if it doesn't already exist and if there is an observations with no choices selected. } \item{drop}{ set \code{drop=FALSE} to keep unused factor levels as columns of the matrix produced by \code{mChoice} } \item{x}{ an object of class \code{"mchoice"} such as that created by \code{mChoice}. For \code{is.mChoice} is any object. } \item{object}{ an object of class \code{"mchoice"} such as that created by \code{mChoice} } \item{ncombos}{ maximum number of combos. } \item{width}{ With of a line of text to be formated } \item{quote}{ quote the output } \item{max.levels}{max levels to be displayed} \item{minlength}{ By default no abbreviation of levels is done in \code{format} and \code{summary}. Specify a positive integer to use abbreviation in those functions. See \code{\link{abbreviate}}. } \item{sep}{ character to use to separate levels when formatting } \item{prlabel}{ set to \code{FALSE} to keep \code{print.summary.mChoice} from printing the variable label and number of unique values } \item{values}{ a scalar or vector. If \code{values} is integer, it is the choice codes, and if it is a character vector, it is assumed to be value labels. } } \value{ \code{mChoice} returns a character vector of class \code{"mChoice"} plus attributes \code{"levels"} and \code{"label"}. \code{summary.mChoice} returns an object of class \code{"summary.mChoice"}. \code{inmChoice} returns a logical vector. \code{format.mChoice} returns a character vector, and \code{as.double.mChoice} returns a binary numeric matrix. } \author{ Frank Harrell \cr Department of Biostatistics \cr Vanderbilt University \cr \email{f.harrell@vanderbilt.edu} } \seealso{ \code{\link{label}} } \examples{ options(digits=3) set.seed(3) n <- 20 sex <- factor(sample(c("m","f"), n, rep=TRUE)) age <- rnorm(n, 50, 5) treatment <- factor(sample(c("Drug","Placebo"), n, rep=TRUE)) # Generate a 3-choice variable; each of 3 variables has 5 possible levels symp <- c('Headache','Stomach Ache','Hangnail', 'Muscle Ache','Depressed') symptom1 <- sample(symp, n, TRUE) symptom2 <- sample(symp, n, TRUE) symptom3 <- sample(symp, n, TRUE) cbind(symptom1, symptom2, symptom3)[1:5,] Symptoms <- mChoice(symptom1, symptom2, symptom3, label='Primary Symptoms') Symptoms print(Symptoms, long=TRUE) format(Symptoms[1:5]) inmChoice(Symptoms,'Headache') levels(Symptoms) inmChoice(Symptoms, 3) inmChoice(Symptoms, c('Headache','Hangnail')) # Note: In this example, some subjects have the same symptom checked # multiple times; in practice these redundant selections would be NAs # mChoice will ignore these redundant selections meanage <- N <- numeric(5) for(j in 1:5) { meanage[j] <- mean(age[inmChoice(Symptoms,j)]) N[j] <- sum(inmChoice(Symptoms,j)) } names(meanage) <- names(N) <- levels(Symptoms) meanage N # Manually compute mean age for 2 symptoms mean(age[symptom1=='Headache' | symptom2=='Headache' | symptom3=='Headache']) mean(age[symptom1=='Hangnail' | symptom2=='Hangnail' | symptom3=='Hangnail']) summary(Symptoms) #Frequency table sex*treatment, sex*Symptoms summary(sex ~ treatment + Symptoms, fun=table) # Check: ma <- inmChoice(Symptoms, 'Muscle Ache') table(sex[ma]) # could also do: # summary(sex ~ treatment + mChoice(symptom1,symptom2,symptom3), fun=table) #Compute mean age, separately by 3 variables summary(age ~ sex + treatment + Symptoms) summary(age ~ sex + treatment + Symptoms, method="cross") f <- summary(treatment ~ age + sex + Symptoms, method="reverse", test=TRUE) f # trio of numbers represent 25th, 50th, 75th percentile print(f, long=TRUE) } \keyword{category} \keyword{manip} \concept{multiple choice}


text:
Kan418 Posts: 4, Reputation: 1 New Member #1 Jul 17, 2009, 03:32 AM
evaluate the following limits
lim x2(squared) - 6x + 8 / 2x2(squared) - 32
x-4 (the - is an arrow)
 iLLyriC Posts: 36, Reputation: 1 Junior Member #2 Jul 17, 2009, 05:52 AM
the easiest way is always L'ohspitals Rule:
Take the derivative of the numerator and denominator and substitute x, in this case:

lim (x^2 - 6x +8)/2x^2 - 32 = lim (2x -6)/4x = 2/16 = 1/2
x->4
 ebaines Posts: 12,132, Reputation: 1307 Expert #3 Jul 17, 2009, 08:47 AM
Originally Posted by iLLyriC
the easiest way is always L'ohspitals Rule:
Take the derivative of the numerator and denominator and substitute x, in this case:

lim (x^2 - 6x +8)/2x^2 - 32 = lim (2x -6)/4x = 2/16 = 1/2
x->4
Right, except 2/16 = 1/8, not 1/2.
 iLLyriC Posts: 36, Reputation: 1 Junior Member #4 Jul 17, 2009, 02:01 PM
Originally Posted by ebaines
Right, except 2/16 = 1/8, not 1/2.
LoL, thanks for correcting
 galactus Posts: 2,271, Reputation: 282 Ultra Member #5 Jul 17, 2009, 02:14 PM
$\lim_{x\to 4}\frac{x^{2}-6x+8}{2x^{2}-32}$

If I may, L'Hopital is not needed in this case. But it works OK.

We are only dealing with a rational function.

Notice we can factor:

$\lim_{x\to 4} \;\ \frac{(x-4)(x-2)}{2(x-4)(x+4)}=\lim_{x\to 4} \;\ \frac{(x-2)}{2(x+4)}=\frac{1}{8}$
 Kan418 Posts: 4, Reputation: 1 New Member #6 Jul 20, 2009, 03:08 AM
Thank you Galactus.

 Question Tools Search this Question Search this Question: Advanced Search

## Check out some similar questions!

Evaluate the following if f(x)=2x-1 f(x+1) [ 1 Answers ]

Where can I go to evaluate son if he is gifted? [ 2 Answers ]

I have a 2nd grader son he is 8 years old and he is attending to private school. My son always complaint that he gets bored in class and he finish his class work first than all the classmates. My son have 90 and 100 in all his exams. Also my son is very smart. When he have test he not even study...

Evaluate the following limit. [ 1 Answers ]

Evaluate the following limit:- xlnx where (x approuch to 0) I tried to answer this question by l'hopital rule and got 1 as the answer... is it correct? please need to know if I solved it correctly or not :confused:and how to...

Evaluate the following integral [ 1 Answers ]

e^2x (1+e^2x)^3 dx in front to the "e" is the "s" like sign

Evaluate the following integral [ 1 Answers ]

1. 32(x^2+1)^7 dx in front to the bracket is the "s" like sign at the top is 1 and at the bottom 0 thank you


text:
## Latex - Long division by examples (updated with a fix for the gap)

Here is the first example of long division. You can run it on the website (or a website you prefer):

https://latexbase.com (currently no login is needed)

If you have latex installed on your computer, that would be best since it can be faster and you will have more control.

A code that barely works is here, if you are not patient enough, you can skip this and go all the way near the end:

The output should be looks like this, but with a gap to the right of the radical sign.

You may use arraystretch to adjust the space. The above picture shows the result of a stretch by a factor of1.1.

A nice fix with the complete latex code, with comments(removed system genereated strings, so it can compile without errors now):

It has 8 columns, n=8 (see the comments in the code and the reference link). The output should be looks like this:

As an exercise, modify the above code to get the output as in thhe following picture:


text:
# How to fix this numbering in section? [duplicate]

Is there any way in which I can either hide the 5.1 and 5.1.1? So I can directly use what I set to the right

I would need to do this hiding only for specific subsections /subsubsections

• Try `\section*{<Your section title>}` instead of `\section{<Your section Title>}` After that look for the usage `\addcontentsline{toc}{section}{<Your toc -table of contents- content>}` if you need to add the specific sections in the table of contents – koleygr Sep 20 '20 at 20:32
• Perfect, that \section* was exactly what I was needing. Thanks guys – F0l0w Sep 20 '20 at 21:06


text:
# Retransforming coefficients back to original scale in regression when input is scaled in different ways(minmax, standardize, log etc)

While working on an regression problem i came across this issue where as scaling the data in different ways moves us away drastically from the real simulated parameter values.

The only way in which i was able to get the model to approach the real simulated values was to leave the data as it is without scaling it. This is not doable in my scenario though so i need to dig deeper into this.

I.e I need to be sure about how to retransform the parameters back to its original scale.

Lets have a look at the transformations i am interest in.

So the real function which we are trying to approximate is thought of having an data-generation-process assimulating:

$$y_t = e^{lt} * e^{st} * x_{t1}^{b_{t1}} * x_{t2}^{b_{t2}} \; \; (1)$$

where as $$lt$$ is the trend, $$st$$ the seasonality, $$x_{t1}, x_{t2}$$ the regressors and $$0<=b_{t1}<=1,\; 0<=b_{t2}<=1$$ their exponents

Now lets say we choose to do an very simple scaling operation on our inputdata for the regressors and the output.

$$y_{t}' = e^{lt} * e^{st} * x_{t1}'^{b_{t1}} * x_{t2}'^{b_{t2}} \;\; (2)$$

where as: $$y_{t}' = y_t /y_{t}mean\;\;$$, $$x_{t1}' = x_{t1} / x_{t1}mean \;\;$$, $$x_{t2}' = x_{t2} / x_{t2}mean$$

Now we perform the regression and retrieve $$b_{t1}, b_{t2}$$ how are we supposed to scale them back to the original scale so we are able to plug them back into equation $$(1)$$?

Now lets look at the second example which is more interesting.

First of we log-transform equation $$(1)$$ which gives us: $$log(yt) = lt + st + b_{t1}*log(x_{t1}) + b_{t2} * log(x_{t2}) \;\;(3)$$

Lets say i normalize the output and regressor-input of the logged $$x's and y's$$giving us:

$$log(y_{t})' = \frac{log(y_{t}) - log(y_{t})min}{log(y_t)max - log(y_t)min}, \; log(x_{t1})' = \frac{log(x_{t1}) - log(x_{t1})min}{log(x_t1)max - log(x_t1)min}, \;\;$$

$$log(x_{t2})' = \frac{log(x_{t2}) - log(x_{t2})min}{log(x_t2)max - log(x_t2)min}$$

and plug these into equation $$(3)$$ at their respective position.

How am i supposed to retransform their corresponding/(exponents) coefficients to they can be interpreted in equation $$(1)$$?


text:
# Healthcare for all

1. Jul 29, 2009

### vectorcube

I am not sure why anyone would oppose universal healthcare. They have it in Europe, and the more advanced countries in Asia. There are alot of people who are uninsured in the US. It is quite painful to me to see anyone would leave to his/her own disease if they have no money to pay their health insurence. I open mind to hear arguments from the opposing side.

Last edited: Jul 29, 2009
2. Jul 29, 2009

### Cyrus

Because there are people out there who believe in more than the sound bite catch phrase (1) "universal healthcare". We don't have the money to pay for it (2). Not everyone deserves healthcare (3).

Last edited: Jul 29, 2009
3. Jul 29, 2009

### Pengwuino

Interesting that you were the one to say that...

4. Jul 29, 2009

### Cyrus

Don't worry, you made the list of people not to get healthcare.

5. Jul 29, 2009

### Pengwuino

Then you'll probably need to get doped up on morphine if you took the time to research and realize this happens even in nations with "universal healthcare". Do you realize per capita, the US spends the most on health care in the world? The US health care system needs major fixes, but spouting some, as cyrus puts it, sound bite that politicians use to garner votes is irresponsible and childish.

6. Jul 29, 2009

### maverick_starstrider

I suggest a global piggy bank for health care. I'd put in 5 cents. Anyone else?

7. Jul 29, 2009

### TheStatutoryApe

Last edited by a moderator: May 4, 2017
8. Jul 29, 2009

### Cyrus

I'll pass.

9. Jul 29, 2009

### vectorcube

You see. Here is where i disagree. I think everyone deserve healthcare. I don t agree you could partition people into two camps( when it comes to saving lifes).

10. Jul 29, 2009

### vectorcube

So you are saying there are countries with universal healthcare, but are not insuring everyone in their country? which countries?

I do hope the politician would fix the problem. I am not sure why it is irresponsible if it is a real problem that need to be fixed. What is the argument againist healthcare?

Last edited: Jul 29, 2009
11. Jul 29, 2009

### vectorcube

It is better than none.

12. Jul 29, 2009

### vectorcube

Last edited by a moderator: May 4, 2017
13. Jul 29, 2009

### cristo

Staff Emeritus
What do you mean by "deserves"? Why wouldn't you think that everyone should be entitled to healthcare?

14. Jul 29, 2009

Staff Emeritus
Well, it's Cyrus being Cyrus.

The problem is "entitled to healthcare" is not a black and white concept. What level of healthcare are people entitled to? Minimal care? Basic care? Where do you draw the line for the entitlement? How do you deal with finite resources?

15. Jul 29, 2009

### vectorcube

I just don t buy the finite resource reasoning. Countries in western europe is able to do it. So can we. I don t like how you partition people to those that receive minimal, or most expensive healhcare, because you cant compare the worth of a life. When it comes the basic necessities of life, and well being, everyone should have the best healthcare.

16. Jul 29, 2009

### cristo

Staff Emeritus
You should be entitled to all the healthcare you need. Bluntly put, if something is wrong with me, and there is a way to fix it, then I should be entitled to it.

Draw the line for who is entitled, or draw the line for what they are entitled to?

Now that's just living in a dream world; plus you don't define "best". I live in western europe (UK). You shouldn't be under the impression that nationalised healthcare treats 100% of the population. Sure, you could have pretty much any procedure done on the NHS, but the waiting time is pretty long. Thus, the "best" healthcare is still correlated with wealth (obviously), but there aren't people who miss out on healthcare because they can't afford it.

17. Jul 29, 2009

### Hootenanny

Staff Emeritus
Unfortunately, our (UK) healthcare system doesn't work particularly well. The UK is meant to have free healthcare, yet we have to pay for some services and all of our prescriptions. There have also been cases where patients have paid for treatments not available on the NHS (National Health Service), and then been refused standard treatments on the NHS with the reasoning that if they can afford to pay for one treatment, they should pay for all their treatments.

Another downside to the NHS is that we pay for the NHS through our income tax, which means that if you opt for health insurance you still have to pay tax towards the NHS.

18. Jul 29, 2009

Staff Emeritus
Suppose you (and 100 other people) need a new liver, and there are 10 available. Who gets them?

19. Jul 29, 2009

### TheStatutoryApe

???
They are thousands year old oaths taken by doctors.

20. Jul 29, 2009

### cristo

Staff Emeritus
Well there would be some sort of priority list taking into account things like risk of death without a new liver, likelihood of patient to care for new liver, amount of time waiting, etc..


text:
# Sorting and summation of a spreadsheet

I am working on a sorted data file, so there does not need to be any sorting logic. I find unique values, feed them into an array, then use the worksheetfunction.sum to get totals for a field.

Is this as efficient as I could be, or are there some things I'm not seeing and should?

The "Items" sheet is where a number of accounts are stored (in the thousands). The user cuts and pastes the data from another spreadsheet It is sorted by account, and each line all the columns are identical except for the totals, and the first coloumn which contains the account number.

I collect an array of account numbers, then cycle through the array to find the first instance, and continue down until I find the last instance. Populate a second array with the contents of all cells in that row (up to the last column with a header, then get a sum of the totals, and overwrite that element of the array.

When completed, I drop the entire array made from the items sheet into the summary sheet.

Option Explicit

Sub makeSummary()

Dim inws As Worksheet
Dim outws As Worksheet

Dim fndRange As Range
Dim zell As Range

Dim firstRow As Integer
Dim lastRow As Integer
Dim colctr As Integer
Dim totalCol As Integer
Dim LastCol As Integer

Dim ctr As Long
Dim arrBound As Long

Dim distVals() As String
Dim newRows() As String

' Initialize variables
Set inws = Sheets("Items")
Set outws = Sheets("Summary_Sheet")
outws.Cells.Clear
Set fndRange = Range(GetLast(3, inws.Cells))
LastCol = fndRange.Column
lastRow = fndRange.Row
Set fndRange = Nothing

'populate the header columns in the output worksheet.
For ctr = 1 To LastCol
outws.Cells(1, ctr) = inws.Cells(1, ctr).Value
Next ctr

' redim array, and populate with unique SFC values
ReDim distVals(1)
distVals(1) = inws.Cells(2, 1)
For ctr = 2 To lastRow
If inws.Cells(ctr, 1).Value <> distVals(UBound(distVals)) Then
ReDim Preserve distVals(UBound(distVals) + 1)
distVals(UBound(distVals)) = inws.Cells(ctr, 1).Value
End If
Next ctr

'Get upper bound of search array and use it to set max row value of newrows array
arrBound = UBound(distVals)
ReDim newRows(1 To arrBound, 1 To LastCol)

'build array,
For ctr = 1 To arrBound
Set fndRange = inws.Cells.Find(distVals(ctr), lookat:=xlPart, LookIn:=xlFormulas)
firstRow = fndRange.Row
lastRow = fndRange.Row
Do Until inws.Cells(lastRow + 1, 1) <> distVals(ctr)
lastRow = lastRow + 1
Loop
'fill row
For colctr = 1 To LastCol
newRows(ctr, colctr) = inws.Cells(firstRow, colctr)
Next colctr
'Get total of totals in SFC
newRows(ctr, 5) = WorksheetFunction.Sum(Range(inws.Cells(firstRow, 5), inws.Cells(lastRow, 5)))
Next ctr

'clean up of destination sheet
With outws
.Columns("E").NumberFormat = "_($* #,##0.00_);_($* (#,##0.00);_(\$* ""-""??_);_(@_)"
'excel doesn't recognize the numbers as numbers unless you multiply by 1 and drop the value back down.
zell.Value = zell.Value * 1
Next zell
.Calculate
End With

End Sub

Function GetLast(choice As Long, rng As Range)
' 1 = GetLast row
' 2 = GetLast column
' 3 = GetLast cell

Dim ReturnRng As Range

Set ReturnRng = rng.Find(What:="*", After:=rng.Cells(1), lookat:=xlPart, LookIn:=xlFormulas, _
SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False)

If Not ReturnRng Is Nothing Then
With ReturnRng
Select Case choice
Case 1
GetLast = .Row
Case 2
GetLast = .Column
Case 3
Case Else
End Select
End With
End If
End Function

• Almost, I provided you with the finishing touch. Welcome to Code Review :-) – Mast Sep 29 '16 at 15:30
• Hey Richard, can you expand a bit on the context of your work. What is your data, where does it come from, where does it go to, what is the outcome you're trying to achieve? The more we know about what your requirements and constraints are, the better we can tailor advice to your specific situation. – Kaz Sep 29 '16 at 15:33
• If I'm understanding correctly, you could just create a dictionary of account numbers and use it to find totals for each unique entry in the dictionary, yes? – Raystafarian Oct 3 '16 at 18:29
• @Raystafarian I'll give that a try, thank you. – Don Thermidor_Lobster Mobster Oct 3 '16 at 18:48
• If I did understand correctly, I provided an example below. If I misunderstood - apologies! – Raystafarian Oct 3 '16 at 20:31

### Quick Things

First, it's good practice to indent all of your code that way Labels will stick out as obvious.

Second, Worksheets have a CodeName property - View Properties window (F4) and the (Name) field (the one at the top) can be used as the worksheet name. This way you can avoid Dim inws as Worksheet, set inws = Sheets"Items" and instead just use Items.

Comments - "code tell you how, comments tell you why". The code should speak for itself, if it needs a comment, it might need to be made more clear. If not, the comment should describe why you're doing something rather than how you're doing it. Here are a few reasons to avoid comments all together.

Integers - integers are obsolete. According to msdn VBA silently converts all integers to long.

### Naming

Your variable names leave a lot to be desired. It's pretty easy to use descriptive names and characters are mostly free, so things like

ctr = columnCounter or rowCounter or even just counter.

Also, Standard VBA naming conventions have camelCase for local variables and PascalCase for other variables and names. So inws should be inWS or inWorksheet or sourceWorksheet.

Right now things like zell and distVals don't really tell me anything at all about what I should be expecting them to do.

### Function

Function GetLast - it's your prerogative, but I think it's unneeded. If you did want you keep it, it would be better as

Private Function GetLast(ByVal choice as Long, ByVal rng as Range) as Long

Right now you're passing ByRef, which isn't best practice and you don't have a return type defined. You can return a row number, column number or address (string?). That can lead to errors down the line if you change what you're looking for and expect the wrong type back. Personally,

Dim lastRow As Long
lastRow = Sheet.Cells(Rows.Count, 1).End(xlUp).Row
Dim lastColumn As Long
lastColumn = Sheet.Cells(1, Columns.Count).End(xlToLeft).Column

Would work fine for me. And you could eliminate all of

Set fndRange = Range(GetLast(3, inws.Cells))
LastCol = fndRange.Column
lastRow = fndRange.Row
Set fndRange = Nothing

### Arrays

Dim distVals() As String
Dim newRows() As String
ReDim distVals(1)
distVals(1) = inws.Cells(2, 1)
For ctr = 2 To lastRow
If inws.Cells(ctr, 1).Value <> distVals(UBound(distVals)) Then
ReDim Preserve distVals(UBound(distVals) + 1)
distVals(UBound(distVals)) = inws.Cells(ctr, 1).Value
End If
Next ctr

'Get upper bound of search array and use it to set max row value of newrows array
arrBound = UBound(distVals)
ReDim newRows(1 To arrBound, 1 To LastCol)

I think what's happening here is that you initialize the array, then populate it one cell at a time, assuming that your data is in some sort of order because you're checking only the last element for duplicates, right? That is a lot of redimming and isn't needed. A dictionary could help with that by eliminating duplicates for you

Dim valueDictionary As Object
Set valueDictionary = CreateObject("Scripting.Dictionary")
For counter = 2 To lastRow
valueDictionary(Cells(counter, 2).Value) = 1
Next

Now arrBound = UBound(distVals) is just valueDictionary.Count

Now, your newRows array is a little confusing to me. Why not just build an array, maybe like this -

    Dim mySummedArray As Variant
ReDim mySummedArray(1 To valueDictionary.Count, 1 To 2)
ReDim arr(1 To valueDictionary.Count, 1 To 2)
counter = 1
Dim key As Variant
For Each key In valueDictionary.keys
mySummedArray(i, 1) = key
i = i + 1
Next
For counter = 1 To valueDictionary.Count
mySummedArray(counter, 1) = valueDictionary.keys(counter)
Next
Dim indexValue As String
Dim arrayIndex As Long
For counter = 1 To lastRow
indexValue = Cells(counter, 1)
arrayIndex = FindInArray(indexValue, mySummedArray)
mySummedArray(arrayIndex, 2) = mySummedArray(arrayIndex, 2) + Cells(counter, 2)
Next

Using

Private Function FindInArray(ByVal indexValue As String, ByVal arrayToSearch As Variant) As Long
Dim i As Long
For i = LBound(arrayToSearch) To UBound(arrayToSearch)
If StrComp(indexValue, arrayToSearch(i, 1), vbTextCompare) = 0 Then
FindInArray = i
Exit For
End If
Next
End Function

Essentially you end up with a 2D array of unique values paired with their sum. But maybe that's not what you're doing? If not, sorry, but maybe the approach is still useful.