I have been trying to create an expression to calculate brick and glass prices.
I'm working with a, b and c
so the price is $30m^2 for bricks and $20m^2 for glass
A and B are walls C is a round window radius
A = 3m (not m^2)
B = 2m (not m^2)
C = 1m (not m^2)
I believe that my expression (a*b)*30 – (c^2*20) works but how can I turn this into a java script function that in future I could use in a calculator to calculate prices etc...
Bit of a newbie with java script.
thanks all!
I believe the following function cost(a,b,c) should do what you want, assuming I've understood the question:
function cost(a,b,c) {
return (a * b * 30) - (Math.PI * Math.pow(c,2) * 20)
}
This returns 117.16814692820414 given the parameters a = 3, b = 2 and a = 1.
An example of the cost function in use would be:
var price = cost(3,2,1);
Related
I have a moving graphic whose velocity decays geometrically every frame. I want to find the initial velocity that will make the graphic travel a desired distance in a given number of frames.
Using these variables:
v initial velocity
r rate
d distance
I can come up with d = v * (r0 + r1 + r2 + ...)
So if I want to find the v to travel 200 pixels in 3 frames with a decay rate of 90%, I would adapt to:
d = 200
r = .9
v = d / (r0 + r1 + r2)
That doesn't translate well to code, since I have to edit the expression if the number of frames changes. The only solution I can think of is this (in no specific language):
r = .9
numFrames = 3
d = 200
sum = 1
for (i = 1; i < numFrames; i++) {
sum = sum + power(r, i);
}
v = d / sum;
Is there a better way to do this without using a loop?
(I wouldn't be surprised if there is a mistake in there somewhere... today is just one of those days..)
What you have here is a geometric sequence. See the link:
http://www.mathsisfun.com/algebra/sequences-sums-geometric.html
To find the sum of a geometric sequence, you use this formula:
sum = a * ((1 - r^n) / (1 - r))
Since you are looking for a, the initial velocity, move the terms around:
a = sum * ((1-r) / (1 - r^n))
In Java:
int distanceInPixels = SOME_INTEGER;
int decayRate = SOME_DECIMAl;
int numberOfFrames = SOME_INTEGER;
int initialVelocity; //this is what we need to find
initialVelocity = distanceinPixel * ((1-decayRate) / (1-Math.pow(decayRate, NumberOfFrames)));
Using this formula you can get any one of the four variables if you know the values of the other three. Enjoy!
According to http://mikestoolbox.com/powersum.html, you should be able to reduce your for loop to:
F(x) = (x^n - 1)/(x-1)
I want to create (approximately) the double sigmoid in the shown figure as
a function in terms of the parameters X,Y,Z, a,b,c and d.
Any idea? Thanks.
This question seems to have gone ignored, so try something like this:
k = 1 # adjust this for "sharpness"
s(x) = (tanh(k * x) + 1) / 2
f(x) = X + (Y-X) * s(x-b) + (Z-Y) * s(x-c)
Here's an example plot.
I would like to know an algorithm for smooth damp or as some people call it, tween. I would like it in Lua preferably but anything will help.
I have tried watching unity tutorials but can't transfer the code without a algorithm to substitute for the smooth damp function.
If I understand the question correctly, you're looking for an easing function. There is a Lua library that provides a set of easing functions on GitHub: https://github.com/EmmanuelOga/easing
An example would be:
local function inOutQuad(t, b, c, d)
t = t / d * 2
if t < 1 then
return c / 2 * pow(t, 2) + b
else
return -c / 2 * ((t - 1) * (t - 3) - 1) + b
end
end
Where t = time, b = begin value, c = change in value, and d = duration.
More information on these easing functions is available directly from Robert Penner here (this is where the function above is derived from): http://www.robertpenner.com/easing/
I would like to ask your help for finding the reason why when I use the function envelope, my arguments are not accepted, but defined "unused arguments".
The data I'm using are ppp without marks and I would like to create a L function graph with simulated data and my data.
Here the code for my ppp data:
map2008MLW = ppp(xy2008_BNGppp$x, xy2008_BNGppp$y, window = IoM_polygon_MLWowin)
And then:
L2008 = Lest(map2008MLW,correction="Ripley")
OP = par(mar=c(5,5,4,4))
plot(L2008, . -r ~ r, ylab=expression(hat("L")), xlab = "d (m)"); par(OP)
L2008$iso = L$iso - L$r
L2008$theo = L$theo - L$r
Desired number of simulations
n = 9999
Desired p significance level to display
p = 0.05
And at this point the envelope function doesnt seem very happy:
EL2008 = envelope(map2008MLW[W], Lest, nsim=n, rank=(p * (n + 1)))
Error in envelope(map2008MLW[W], Lest, nsim = n, rank = (p * (n + 1))) :
unused arguments (nsim = n, rank = (p * (n + 1)))
It seems a generic error and I am not sure it is caused by the package spatstat. Please, help me in finding a solution to this, as I can't proceed with my analyses.
Thank you very much,
Martina
The argument rank should be nrank.
Also the relationship between the significance level and the argument nrank is not correct in the example. For a two-sided test, the significance level is alpha = 2 * nrank/(nsim+1), so nrank= alpha * (nsim+1)/2.
You have chosen a significance level of 0.95 but I assume you mean 0.05. So with nsim=9999 you want nrank=0.05 * 10000/2 = 250 to get a test with significance level 0.05.
Such a large number of simulations (9999) is unnecessary in this kind of application. Monte Carlo tests are valid with small values of nsim. In your example I would normally use nsim=39 and nrank=1.
See Chapter 10 of the spatstat book.
I am doing an AI using Minimax for dots and boxes. After the most of the work, I try some different evaluation function to find the most suitable one. But I get confused with the evaluation function one(below), for it make some stupid moves(like the third edge of a box when there are boxes who have all four edges unmade), and use the same evaluation like function two don't make that errors. And that is contradictory with this answer .
And this is function one for dots and boxes:
//System.out.println("in evaluate" );
if (node.ai.isTurn) {
value = 4*node.ai.score - node.man.score * 2 + 0.5 * s2 - 0.75 * s3 ;
}else {
value = 4*node.ai.score - node.man.score * 2 - 0.5 * s2 + 0.75 * s3 ;
}
//System.out.println(value);
return value;
And function two:
value = 4*node.ai.score - node.man.score * 2 + 0.5 * s2 - 0.75 * s3 ;
So could anyone tell me should the evaluation function be different in max turn and min turns. And any suggestions are appreciated.