approximation

Approximate position on circle for n points

为君一笑 提交于 2019-12-25 05:33:51
问题 I am struggling with the following problem: I am given n points and a radius and I have to place them on a circle as symmetrical as possible. Currently, I used something like this: float theta = 360.0f / n; int i = 0; for (Word w : e.getValue()) { double newX = Math.sin(theta * i) * RADIUS + I_OFFSET_X; double newY = Math.cos(theta * i) * RADIUS + I_OFFSET_Y; mxCell v2 = (mxCell) graph.insertVertex(parent, null, w.getValue(), newX, newY, OW_WIDTH, OW_HEIGHT,"shape=ellipse"); graph.insertEdge

Fixed point approximation of 2^x, with input range of s5.26

流过昼夜 提交于 2019-12-24 08:03:54
问题 How can I implement 2^x fixed-point arithmetic s5.26 and input values is in range [-31.9, 31.9] using the minimax polynomial approximation for exp2() How to generate the polynomial using Sollya Tool mentioned in the following link Power of 2 approximation in fixed point 回答1: Since fixed-point arithmetic generally does not include an "infinity" encoding representing overflowed results, any implementation of exp2() for an s5.26 format will be limited to inputs in the interval (-32, 5),

In what situation would a taylor series for a polynomial be necessary?

橙三吉。 提交于 2019-12-24 01:17:11
问题 I'm having a hard time understanding why it would be useful to use the Taylor series for a function in order to gain an approximation of a function, instead of just using the function itself when programming. If I can tell my computer to compute e^(.1) and it will give me an exact value, why would I take an approximation instead? 回答1: Taylor series are generally not used to approximate functions. Usually, some form of minimax polynomial is used. Taylor series converge slowly (it takes many

Simple approximation of Inverse Incomplete gamma function

醉酒当歌 提交于 2019-12-22 10:12:29
问题 How could one approximate Inverse Incomplete gamma function Г(s,x) by some simple analytical function f(s,Г)? That means write something like x = f(s,Г) = 12*log(123.45*Г) + Г + 123.4^s . (I need at least ideas or references.) 回答1: You can look at the code in Boost: http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/math_toolkit/special/sf_gamma/igamma.html and see what they're using. EDIT: They also have inverses: http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and

bin packing with overlapping objects

杀马特。学长 韩版系。学妹 提交于 2019-12-21 02:59:08
问题 I have some bins with different capacities and some objects with specified size. The goal is to pack these objects in the bins. Until now it is similar to the bin-packing problem. But the twist is that each object has a partial overlap with another. So while object 1 and 2 has sizes s1 and s2, when I put them in the same bin the filled space is less than s1+s2. Supposing that I know this overlapping value for each pair of objects, is there any approximation algorithm like the ones for

approximation methods

狂风中的少年 提交于 2019-12-21 02:48:08
问题 I attached image: (source: piccy.info) So in this image there is a diagram of the function, which is defined on the given points. For example on points x=1..N. Another diagram, which was drawn as a semitransparent curve, That is what I want to get from the original diagram, i.e. I want to approximate the original function so that it becomes smooth. Are there any methods for doing that? I heard about least squares method, which can be used to approximate a function by straight line or by

float strange imprecision error in c [duplicate]

帅比萌擦擦* 提交于 2019-12-19 11:19:05
问题 This question already has answers here : Is floating point math broken? (31 answers) Closed 4 years ago . today happened to me a strange thing, when I try to compile and execute the output of this code isn't what I expected. Here is the code that simply add floating values to an array of float and then print it out. The simple code: int main(){ float r[10]; int z; int i=34; for(z=0;z<10;z++){ i=z*z*z; r[z]=i; r[z]=r[z]+0.634; printf("%f\n",r[z]); } } the output: 0.634000 1.634000 8.634000 27

will this sinus approximation be faster than a shader CG sinus function?

£可爱£侵袭症+ 提交于 2019-12-13 04:48:38
问题 I have some functions that are not really sines but they are a lot quicker than conventional processing, they are simple parabole functions. Will this be faster on a graphics processor than the built-in graphics sinus function: float par (float xx){////// sinus approximation half xd =((fmod(abs(xx), 2.4)) - 1.2); if ( fmod (abs(xx) , 4.8) > 2.4) { xd=(-xd*xd)+2.88;} else {xd = xd*xd;} xd = -xd*0.694444444+1; if ( (xx<0) ) { xd=-xd;} return xd; } 回答1: MAIN ANSWER There is absolutely no way

OpenCv round after division

喜夏-厌秋 提交于 2019-12-13 00:34:23
问题 Looking at the following code Blue = channel[0]; Green = channel[1]; Red = channel[2]; Mat G = (Green + Blue) / 2; where Red Green and Blue are the channels of an image. Where the sum of Green and Blue is odd, sometimes it make a round and sometimes a "fix". For example for a Green pixel with value 120 and Blue 45, the G value is 82 (so that it takes just the integer part of 82,5). While in another case where the Green is 106 and the Blue is 33 i get the value 70 for that element of G (so

Using approx in dplyr

一笑奈何 提交于 2019-12-12 20:15:32
问题 I'm trying to do a linear approximation for each id in the data frame between year using point x . dplyr seems like an appropriate option for this, but I can't get it to work because of an error: Error: incompatible size (9), expecting 3 (the group size) or 1 Sample code: library(dplyr) dat <- data.frame(id = c(1,1,1,2,2,2,3,3,3), year = c(1,2,3,1,2,3,1,2,3), x = c(1,NA,2, 3, NA, 4, 5, NA, 6)) # Linear Interpolation dat %>% group_by(id) %>% mutate(x2 = as.numeric(unlist(approx(x = dat$year, y