Search Results

Search found 3425 results on 137 pages for 'polynomial math'.

Page 48/137 | < Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >

  • Calculating a parabola: What am I doing wrong? [closed]

    - by Nils
    I was following this thread and copied the code in my project. Playing around with it turns out that it seems not to be very precise. Recall the formula: y = ax^2 + bx +c Since the first given point I have is at x1 = 0, we already have c=y1 . We just need to find a and b. Using: y2 = ax2^2 + bx2 +c y3 = ax3^2 + bx3 +c Solving the equations for b yields: b = y/x - ax - cx Now setting both equations equal to each other so b falls out y2/x2 - ax2 - cx2 = y3/x3 - ax3 - cx3 Now solving for a gives me: a = ( x3*(y2 - c) + x2*(y3 - c) ) / ( x2*x3*(x2 - x3) ) (is that correct?!) And then using again b = y2/x2 - ax2 - cx2 to find b. However so far I haven't found the correct a and b coeffs. What am I doing wrong?

    Read the article

  • PHP: Trying to come up with a "prev" and "next" link

    - by fwaokda
    I'm displaying 10 records per page. The variables I have currently that I'm working with are.. $total = total number of records $page = whats the current page I'm displaying I placed this at the top of my page... if ( $_GET['page'] == '' ) { $page = 1; } //if no page is specified set it to `1` else { $page = ($_GET['page']); } // if page is specified set it Here are my two links... if ( $page != 1 ) { echo '<div style="float:left" ><a href="index.php?page='. ( $page - 1 ) .'" rev="prev" >Prev</a></div>'; } if ( !( ( $total / ( 10 * $page ) ) < $page ) ) { echo '<div style="float:right" ><a href="index.php?page='. ( $page + 1 ) .'" rev="next" >Next</a></div>'; } Now I guess (unless I'm not thinking of something) that I can display the "Prev" link every time except when the page is '1'. How can make it where the "Next" link doesn't show on the last page though?

    Read the article

  • How long would this have to go on for...

    - by Pieman
    I have the Pi formulae -Well one of them... 1 - 1/3 + 1/5 - 1/7 etc. How long would it take to get to like 1000 S.F correct? -Well, not how long, how big would the denominator be? -I have it updating 4 times in one refresh: http://zombiewrath.com/pi.php So the section above would be done in one refresh, then 7 to 13 in another etc. Answer this maths question please :) Also how can I get the 10,002 length variable onto 'seperate lines'? -I want it to fill 100% screen width -no scrolling needed (well downwards only)

    Read the article

  • Print all ways to sum n integers so that they total a given sum.

    - by noghead
    Im trying to come up with an algorithm that will print out all possible ways to sum N integers so that they total a given value. Example. Print all ways to sum 4 integers so that they sum up to be 5. Result should be something like: 5 0 0 0 4 1 0 0 3 2 0 0 3 1 1 0 2 3 0 0 2 2 1 0 2 1 2 0 2 1 1 1 1 4 0 0 1 3 1 0 1 2 2 0 1 2 1 1 1 1 3 0 1 1 2 1 1 1 1 2

    Read the article

  • Calculating percent "x/y * 100" always results in 0?

    - by Patrick Beninga
    In my assignment i have to make a simple version of Craps, for some reason the percentage assignments always produce 0 even when both variables are non 0, here is the code. import java.util.Random; Header, note the variables public class Craps { private int die1, die2,myRoll ,myBet,point,myWins,myLosses; private double winPercent,lossPercent; private Random r = new Random(); Just rolls two dies and produces their some. public int roll(){ die1 = r.nextInt(6)+1; die2 = r.nextInt(6)+1; return(die1 + die2); } The Play method, this just loops through the game. public void play(){ myRoll = roll(); point = 0; if(myRoll == 2 ||myRoll == 3 || myRoll == 12){ System.out.println("You lose!"); myLosses++; }else if(myRoll == 7 || myRoll == 11){ System.out.println("You win!"); myWins++; }else{ point = myRoll; do { myRoll = roll(); }while(myRoll != 7 && myRoll != point); if(myRoll == point){ System.out.println("You win!"); myWins++; }else{ System.out.println("You lose!"); myLosses++; } } } This is where the bug is, this is the tester method. public void tester(int howMany){ int i = 0; while(i < howMany){ play(); i++; } bug is right here in these assignments statements winPercent = myWins/i * 100; lossPercent = myLosses/i* 100; System.out.println("program ran "+i+" times "+winPercent+"% wins "+ lossPercent+"% losses with "+myWins+" wins and "+myLosses+" losses"); } }

    Read the article

  • Why do we need to estimate the true position in Kalman filters?

    - by Kalla
    I am following a probably well-known tutorial about Kalman filter here From these lines of code: figure; plot(t,pos, t,posmeas, t,poshat); grid; xlabel('Time (sec)'); ylabel('Position (feet)'); title('Figure 1 - Vehicle Position (True, Measured, and Estimated)') I understand that x is the true position, y is measured position, xhat is estimated position. Then, if we can compute x (this code: x = a * x + b * u + ProcessNoise;), why do we need to estimated x anymore?

    Read the article

  • Scale 2D coordinates and keep their relative euclidean distances intact?

    - by eiaxlid
    I have a set of points like: pointA(3302.34,9392.32), pointB(34322.32,11102.03), etc. I need to scale these so each x- and y-coordinate is in the range (0.0 - 1.0). I tried doing this by first finding the largest x value in the data set (maximum_x_value), and the largest y value in the set (minimum_y_value). I then did the following: pointA.x = (pointA.x - minimum_x_value) / (maximum_x_value - minimum_x_value) pointA.y = (pointA.y - minimum_y_value) / (maximum_y_value - minimum_y_value) This changes the relative distances(?), and therefore makes the data useless for my purposes. Is there a way to scale these coordinates while keeping their relative distances the intact?

    Read the article

  • How to map a long integer number to a N-dimensional vector of smaller integers (and fast inverse)?

    - by psihodelia
    Given a N-dimensional vector of small integers is there any simple way to map it with one-to-one correspondence to a large integer number? Say, we have N=3 vector space. Can we represent a vector X=[(int32)x1,(int32)x2,(int32)x3] using an integer (int48)y? The obvious answer is "Yes, we can". But the question is: "What is the fastest way to do this and its inverse operation?"

    Read the article

  • How do I improve this linear regression function?

    - by user558383
    I have the following PHP function that I'm using to draw a trend line. However, it sometimes plots the line below all the points in the scatter graph. Is there an error in my function or is there a better way to do it. I think it might be something to do with that with the line it produces, it treats all the residuals (the distances from the scatter points to the line) as positive regardless of them being above or below the line. function linear_regression($x, $y) { $n = count($x); $x_sum = array_sum($x); $y_sum = array_sum($y); $xx_sum = 0; $xy_sum = 0; for($i = 0; $i < $n; $i++) { $xy_sum+=($x[$i]*$y[$i]); $xx_sum+=($x[$i]*$x[$i]); } $m = (($n * $xy_sum) - ($x_sum * $y_sum)) / (($n * $xx_sum) - ($x_sum * $x_sum)); $b = ($y_sum - ($m * $x_sum)) / $n; return array("m"=>$m, "b"=>$b); }

    Read the article

  • Assigning XY positions to points based on a "weight" between them

    - by sanity
    I have a bunch of points in a graph, and for every pair of these points I have "weight" value indicating what their proximity should be, between -1 and 1. I want to choose XY coordinates for these points such that those that have a proximity of 1 are in the same position, and those with a proximity of -1 are distant from each-other. All points must reside within a bounded area. What algorithms should I investigate to achieve this?

    Read the article

  • This codes in Actionscript-2, Can anyone help me translate it into AS-3 please ?.......a newby pulli

    - by Spux
    this.createEmptyMovieClip('mask_mc',0); bg_mc.setMask(mask_mc); var contor:Number=0; // function drawCircle draws a circle on mask_mc MovieClip of radius r and having center to mouse coordinates function drawCircle(mask_mc:MovieClip):Void{ var r:Number = 20; var xcenter:Number = _xmouse; var ycenter:Number = _ymouse; var A:Number = Math.tan(22.5 * Math.PI/180); var endx:Number; var endy:Number; var cx:Number; var cy:Number; mask_mc.beginFill(0x000000, 100); mask_mc.moveTo(xcenter+r, ycenter); for (var angle:Number = Math.PI/4; angle<=2*Math.PI; angle += Math.PI/4) { xend = r*Math.cos(angle); yend = r*Math.sin(angle); xbegin =xend + r* A *Math.cos((angle-Math.PI/2)); ybegin =yend + r* A *Math.sin((angle-Math.PI/2)); mask_mc.curveTo(xbegin+xcenter, ybegin+ycenter, xend+xcenter, yend+ycenter); } mask_mc.endFill(); } // contor variable is used to hold if the mouse is pressed (contor is 1) or not (contor is 0) this.onMouseDown=function(){ drawCircle(mask_mc); contor=1; } // if the mouse is hold and moved then we draw a circle on the mask_mc this.onMouseMove=this.onEnterFrame=function(){ if (contor==1){ drawCircle(mask_mc); } } this.onMouseUp=function(){ contor=0; }

    Read the article

  • Local Variables take 7x longer to access than global variables?

    - by ItzWarty
    I was trying to benchmark the gain/loss of "caching" math.floor, in hopes that I could make calls faster. Here was the test: <html> <head> <script> window.onload = function() { var startTime = new Date().getTime(); var k = 0; for(var i = 0; i < 1000000; i++) k += Math.floor(9.99); var mathFloorTime = new Date().getTime() - startTime; startTime = new Date().getTime(); window.mfloor = Math.floor; k = 0; for(var i = 0; i < 1000000; i++) k += window.mfloor(9.99); var globalFloorTime = new Date().getTime() - startTime; startTime = new Date().getTime(); var mfloor = Math.floor; k = 0; for(var i = 0; i < 1000000; i++) k += mfloor(9.99); var localFloorTime = new Date().getTime() - startTime; document.getElementById("MathResult").innerHTML = mathFloorTime; document.getElementById("globalResult").innerHTML = globalFloorTime; document.getElementById("localResult").innerHTML = localFloorTime; }; </script> </head> <body> Math.floor: <span id="MathResult"></span>ms <br /> var mathfloor: <span id="globalResult"></span>ms <br /> window.mathfloor: <span id="localResult"></span>ms <br /> </body> </html> My results from the test: [Chromium 5.0.308.0]: Math.floor: 49ms var mathfloor: 271ms window.mathfloor: 40ms [IE 8.0.6001.18702] Math.floor: 703ms var mathfloor: 9890ms [LOL!] window.mathfloor: 375ms [Firefox [Minefield] 3.7a4pre] Math.floor: 42ms var mathfloor: 2257ms window.mathfloor: 60ms [Safari 4.0.4[531.21.10] ] Math.floor: 92ms var mathfloor: 289ms window.mathfloor: 90ms [Opera 10.10 build 1893] Math.floor: 500ms var mathfloor: 843ms window.mathfloor: 360ms [Konqueror 4.3.90 [KDE 4.3.90 [KDE 4.4 RC1]]] Math.floor: 453ms var mathfloor: 563ms window.mathfloor: 312ms The variance is random, of course, but for the most part In all cases [this shows time taken]: [takes longer] mathfloor Math.floor window.mathfloor [is faster] Why is this? In my projects i've been using var mfloor = Math.floor, and according to my not-so-amazing benchmarks, my efforts to "optimize" actually slowed down the script by ALOT... Is there any other way to make my code more "efficient"...? I'm at the stage where i basically need to optimize, so no, this isn't "premature optimization"...

    Read the article

  • Help with Collision of spawned object(postion fixed) with objects that there are translating on screen

    - by Amrutha
    Hey guys I am creating a game using Corona SDK and so coding it in Lua. So there are 2 separate functions, To translate the hit objects and change their color when they are tapped The link below is the code I am using to for the first function http://developer.anscamobile.com/sample-code/fishies Spawn objects that will hit the translating objects on collision. Alos on collision the spawned object disappears and the translating object bears a color(indicating the collision). In addition the size of this spawned object is dependent on i/p volume level. The function I have written is as follows: --VOICE INPUT CODE local r = media.newRecording() r:startRecording() r:startTuner() --local function newBar() -- local bar = display.newLine( 0, 0, 1, 0 ) -- bar:setColor( 0, 55, 100, 20 ) -- bar.width = 5 -- bar.y=400 -- bar.x=20 -- return bar --end local c1 = display.newImage("str-minion-small.png") c1.isVisible=false local c2 = display.newImage("str-minion-mid.png") c2.isVisible=false local c3 = display.newImage("str-minion-big.png") c3.isVisible=false --SPAWNING local function spawnDisk( event ) local phase = event.phase local volumeBar = display.newLine( 0, 0, 1, 0 ) volumeBar.y = 400 volumeBar.x = 20 --volumeBar.isVisible=false local v = 20*math.log(r:getTunerVolume()) local MINTHRESH = 30 local LEFTMARGIN = 20 local v2 = MINTHRESH + math.max (v, -MINTHRESH) v2 = (display.contentWidth - 1 * LEFTMARGIN ) * v2 / MINTHRESH volumeBar.xScale = math.max ( 20, v2 ) local l = volumeBar.xScale local cnt1 = 0 local cnt2 = 0 local cnt3 = 0 local ONE =1 local val = event.numTaps --local px=event.x --local py=event.y if "ended" == phase then --audio.play( popSound ) --myLabel.isVisible = false if l > 50 and l <=150 then --c1:setFillColor(10,105,0) --c1.isVisible=false c1.x=math.random( 10, 450 ) c1.y=math.random( 10, 300 ) physics.addBody( c1, { density=1, radius=10.0 } ) c1.isVisible=true cnt1= cnt1+ ONE return c1 elseif l > 100 and l <=250 then --c2:setFillColor(200,10,0) c2.x=math.random( 10, 450 ) c2.y=math.random( 10, 300 ) physics.addBody( c2, { density=2, radius=9000.0 } ) c2.isVisible=true cnt2= cnt2+ ONE return c2 elseif l >=250 then c3.x=math.random( 40, 450 ) c3.y=math.random( 40, 300 ) physics.addBody( c3, { density=2, radius=7000.0 , bounce=0.0 } ) c3.isVisible=true cnt3= cnt3+ ONE return c3 end end end buzzR:addEventListener( "touch", spawnDisk ) -- touch the screen to create disks Now both functions work fine independently but there is no collision happening. Its almost as if the translating object and the spawn object are on different layers. The translating object passes through the spawn object freely. Can anyone please tell me how to resolve this problem. And how can I get them to collide. Its my first attempt at game development, that too for a mobile platform so would appreciate all help. Also if I have not been specific do let me know. I'll try to frame the query better :). Thanks in advance.

    Read the article

  • Help with Collision of spawned object(postion fixed) with objects that there are translating on screen

    - by Amrutha
    Hey guys I am creating a game using Corona SDK and so coding it in Lua. So there are 2 separate functions, To translate the hit objects and change their color when they are tapped The link below is the code I am using to for the first function http://developer.anscamobile.com/sample-code/fishies Spawn objects that will hit the translating objects on collision. Alos on collision the spawned object disappears and the translating object bears a color(indicating the collision). In addition the size of this spawned object is dependent on i/p volume level. The function I have written is as follows, --VOICE INPUT CODE local r = media.newRecording() r:startRecording() r:startTuner() --local function newBar() -- local bar = display.newLine( 0, 0, 1, 0 ) -- bar:setColor( 0, 55, 100, 20 ) -- bar.width = 5 -- bar.y=400 -- bar.x=20 -- return bar --end local c1 = display.newImage("str-minion-small.png") c1.isVisible=false local c2 = display.newImage("str-minion-mid.png") c2.isVisible=false local c3 = display.newImage("str-minion-big.png") c3.isVisible=false --SPAWNING local function spawnDisk( event ) local phase = event.phase local volumeBar = display.newLine( 0, 0, 1, 0 ) volumeBar.y = 400 volumeBar.x = 20 -- volumeBar.isVisible=false local v = 20*math.log(r:getTunerVolume()) local MINTHRESH = 30 local LEFTMARGIN = 20 local v2 = MINTHRESH + math.max (v, -MINTHRESH) v2 = (display.contentWidth - 1 * LEFTMARGIN ) * v2 / MINTHRESH volumeBar.xScale = math.max ( 20, v2 ) local l = volumeBar.xScale local cnt1 = 0 local cnt2 = 0 local cnt3 = 0 local ONE =1 local val = event.numTaps --local px=event.x --local py=event.y if "ended" == phase then --audio.play( popSound ) --myLabel.isVisible = false if l > 50 and l <=150 then -- c1:setFillColor(10,105,0) -- c1.isVisible=false c1.x=math.random( 10, 450 ) c1.y=math.random( 10, 300 ) physics.addBody( c1, { density=1, radius=10.0 } ) c1.isVisible=true cnt1= cnt1+ ONE return c1 elseif l > 100 and l <=250 then --c2:setFillColor(200,10,0) c2.x=math.random( 10, 450 ) c2.y=math.random( 10, 300 ) physics.addBody( c2, { density=2, radius=9000.0 } ) c2.isVisible=true cnt2= cnt2+ ONE return c2 elseif l >=250 then c3.x=math.random( 40, 450 ) c3.y=math.random( 40, 300 ) physics.addBody( c3, { density=2, radius=7000.0 , bounce=0.0 } ) c3.isVisible=true cnt3= cnt3+ ONE return c3 end end end buzzR:addEventListener( "touch", spawnDisk ) -- touch the screen to create disks Now both functions work fine independently but there is no collision happening. Its almost as if the translating object and the spawn object are on different layers. The translating object passes through the spawn object freely. Can anyone please tell me how to resolve this problem. And how can I get them to collide. Its my first attempt at game development, that too for a mobile platform so would appreciate all help. Also if I have not been specific do let me know. I ll try to frame the query better :). Thanks in advance.

    Read the article

  • determine collision angle on a rotating body

    - by jorb
    update: new diagram and updated description I have a contact listener set up to try and determine the side that a collision happened at relative to the a bodies rotation. One way to solve this is to find the value of the yellow angle between the red and blue vectors drawn above. The angle can be found by taking the arc cosine of the dot product of the two vectors (Evan pointed this out). One of my points of confusion is the difference in domain of the atan2 function html canvas coordinates and the Box2d rotation information. I know I have to account for this somehow... SS below questions: Does Box2D provide these angles more directly in the collision information? Am I even on the right track? If so, any hints? I have the following javascript so far: Ship.prototype.onCollide = function (other_ent,cx,cy) { var pos = this.body.GetPosition(); //collision position relative to body var d_cx = pos.x - cx; var d_cy = pos.y - cy; //length of initial vector var len = Math.sqrt(Math.pow(pos.x -cx,2) + Math.pow(pos.y-cy,2)); //body angle - can over rotate hence mod 2*Pi var ang = this.body.GetAngle() % (Math.PI * 2); //vector representing body's angle - same magnitude as the first var b_vx = len * Math.cos(ang); var b_vy = len * Math.sin(ang); //dot product of the two vectors var dot_prod = d_cx * b_vx + d_cy * b_vy; //new calculation of difference in angle - NOT WORKING! var d_ang = Math.acos(dot_prod); var side; if (Math.abs(d_ang) < Math.PI/2 ) side = "front"; else side = "back"; console.log("length",len); console.log("pos:",pos.x,pos.y); console.log("offs:",d_cx,d_cy); console.log("body vec",b_vx,b_vy); console.log("body angle:",ang); console.log("dot product",dot_prod); console.log("result:",d_ang); console.log("side",side); console.log("------------------------"); }

    Read the article

< Previous Page | 44 45 46 47 48 49 50 51 52 53 54 55  | Next Page >