Magic numbers in NR spline function - spline

Can someone explain the magic numbers, which are used in the code here?
http://www.arcetri.astro.it/irlab/library/recipes/bookcpdf/c3-3.pdf
y2[1] = -0.5;
u[1]=(3.0/(x[2]-x[1]))*((y[2]-y[1])/(x[2]-x[1])-yp1);
Why -0.5 and 3.0?
u[i]=(6.0*u[i]/(x[i+1]-x[i-1])-sig*u[i-1])/p;
Why 6?
Thanks for any help.

Related

wxMaxima: understanding ratcoef

Ran into the following behaviour from ratcoef that I don't understand, and was hoping someone could help clarify what's happening.
ratcoef(3*sqrt(x)+5/sqrt(x),x,1/2);
> 3
as epected. However,
ratcoef(x^(3/2)+3*sqrt(x)+5/sqrt(x),x,1/2);
> 0
and yet changing the first power from 3/2 to 3 gives:
ratcoef(x^(3)+3*sqrt(x)+5/sqrt(x),x,1/2);
> 3
The documentation clearly says to not use ratcoef for negative coefficients, but I can't see how the limitation would explain these results. Any suggestions would be very much appreciated!

Sets in LINGO Programming

I need help on Lingo programming.I have a mixed integer programming to solve it using sets in Lingo.One of the constraints is:
S(i,k,w) >= m(i,j) * X(i,t), for i=1,...,I; j=1,...,J; t=1,..,T; k=t+K(j,w)-1,..,t+K(j,w)+S(j)-2; w=1,..,W.
Here m(i,j), K(j,w) and S(j) are parameters.The problem is i do not know how to enter index k using sets in Lingo.Any help would be highly appreciated.

NSInteger 1 when multiplied by 0.05f returns 0.0500000007

A float problem in iOS when indexPath.row=1
Float32 value=0.05*indexPath.row;
it returns value=0.0500000007 but it should be 0.05. How to fix this??
Welcome to floating point errors.
The easiest way to fix this is just to round the number after multiplying.
You can read more about why this is happening on this random website I found on Google.

Issue programming a math equation in Objective-C?

I am trying to solve the following equation in my program:
7.7^2 x 0.012^2/(0.2145 x 1.67^(16/3))
That should equal : 0.002582 (this is verified w/ google & scientific calculator)
This is the code that I am using
CGFloat eX1 = pow(7.7, 2) * pow(0.012, 2)/(0.2145 * pow(1.67, (16/3)));
NSLog(#"%f",eX1);
And even though, I believe my code should give me the same results, it's actually giving me:0.002679
What am I doing wrong? What can I do to obtain the correct answer?
Change (16/3) to (16.0/3.0). Otherwise 16/3 results in 5, not 5.33333349.
And you have 7.2 instead of 7.7 at the start.

Tweening a value in Lua

How'd I go about this one? I want to tween a value from one to another in x time. While also taking into account that it'd be nice to have an 'ease' at the start and end.
I know, I shouldn't ask really, but I've tried myself, and I'm stuck.
Please assume that to cause a delay, you need to call function wait(time).
One simple approach that might work for you is to interpolate along the unit circle:
To do this, you simply evaluate points along the circle, which ensures a fairly smooth movement, and ease-in as well as ease-out. You can control the speed of the interpolation by changing how quickly you alter the angle.
Assuming you're doing 1-dimensional interpolation (i.e. a simple scalar interpolation, like from 3.5 to 6.9 or whatever), it might be handy to use Y-values from -π/2 to π/2. These are given by the sine function, all you need to do is apply suitable scaling:
angle = -math.pi / 2
start = 3.5
end = 6.9
radius = (end - start) / 2
value = start + radius + radius * math.sin(angle)
I'm not 100% sure if this is legal Lua, didn't test it. If not, it's probably trivial to convert.
You may look at Tweener ActionScript library for inspiration.
For instance, you may borrow necessary equations from here.
If you need further help, please ask.