Search Results

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

Page 106/137 | < Previous Page | 102 103 104 105 106 107 108 109 110 111 112 113  | Next Page >

  • What we call this kind of chaining in C#

    - by Thinking
    Can you please tell me what kind of construct in C# is this. Code Golf: Numeric equivalent of an Excel column name C.WriteLine(C.ReadLine() .Reverse() .Select((c, i) => (c - 64) * System.Math.Pow(26, i)) .Sum()); Though I am new to C# (only two months exp so far), but since the time I have joined a C# team, I have never seen this kind of chaining. It really attracted me and I want to learn more about it. Please give some insight about this.

    Read the article

  • Putting $$s in the middle of an `equation` environment: why doesn't Latex complain?

    - by Charles Stewart
    I was surprised that the Latex code from a recent question didn't throw up any errors, and even more surprised on further investigation, that Crowley's explanation seems to be true. My intuition about the \begin{equation} ... \end{equation} code is clearly off, what's really going on? Consider this, slightly adapted code: \begin{equation} 1: e^{i\pi}+1=0 $$ 2: B\"ob $$ 3: e=mc^2 \end{equation} This seems to prove that Crowley's explanation of such code, namely that "What that code says to LaTeX is begin equation, end it, begin it again, typeset definition of tangens and end the equation" is right: lines 1&3 can only be typeset in maths mode, line 2 only in text mode. Shouldn't Latex see that the \end{equation} is ending a display math that wasn't started by the \begin{equation}?

    Read the article

  • Type parameterization in Scala

    - by horatius83
    So I'm learning Scala at the moment, and I'm trying to create an abstract vector class with a vector-space of 3 (x,y,z coordinates). I'm trying to add two of these vectors together with the following code: package math class Vector3[T](ax:T,ay:T,az:T) { def x = ax def y = ay def z = az override def toString = "<"+x+", "+y+", "+z+">" def add(that: Vector3[T]) = new Vector3(x+that.x, y+that.y, z+that.z) } The problem is I keep getting this error: error: type mismatch; found : T required: String def add(that: Vector3[T]) = new Vector3(x+that.x, y+that.y, z+that.z) I've tried commenting out the "toString" method above, but that doesn't seem to have any effect. Can anyone tell me what I'm doing wrong?

    Read the article

  • execute javascript before return in php

    - by user354051
    I do have a custom php script that validates captcha code and sends an email. If php script is sending a mail successfully then it returns "true". This is done by: if(!$Error){ echo "true"; exit; } Before returning true, I would like to execute a jQuery command that should refresh the captcha image. I shouldn't be doing this is client side as it might be risky from spammers point of view. To refresh the captcha image, The command is: jQuery('#captcha').attr('src', ('php/captcha/captchaimage_show.php?' + Math.random())); I need to call this command from within php scripts before return any results by "echo" Prashant

    Read the article

  • jQuery sibling selector?

    - by Brett
    Hi, I have a table which I'm trying to do a pricing list, that auto-computes the tax component.. I'm getting the value from price_1, applying a math cal, and saving it to tax_1. I could read the number of the end of the id, but hopefully there is a cleaner way with jQuery. E.g. I would have a lot of fields like.. price_1 price_2 price_3 tax_1 tax_2 tax_3 etc... I can use the following code to call jQuery on change of a price, and get the value of that price. How do I update the tax field next to it? should I use a sibling selector or something?? $('#pricing').delegate("input", "change", function(){ $(this).val() /* the value of the price */; })

    Read the article

  • php, get an end date based on start date and number of months

    - by mike
    Hi! I need to calculate an end date based on todays date and a number of months. For example, todays date 04/01/2010 and the number of months is 6. Are there any functions I can use to do some math that would return "10/01/2010"? Also, I think it's important to note that I am storing the result in MySQL as a "DATETIME" so I guess I would have to do something with the time as well... ??? Thanks!

    Read the article

  • Values of Variables Matrix NumPy

    - by Max Mines
    I'm working on a program that determines if lines intersect. I'm using matrices to do this. I understand all the math concepts, but I'm new to Python and NumPy. I want to add my slope variables and yint variables to a new matrix. They are all floats. I can't seem to figure out the correct format for entering them. Here's an example: import numpy as np x = 2 y = 5 w = 9 z = 12 I understand that if I were to just be entering the raw numbers, it would look something like this: matr = np.matrix('2 5; 9 12') My goal, though, is to enter the variable names instead of the ints.

    Read the article

  • set div position to fixed after scrolling 100px?

    - by user1481850
    I tried to use the following function in order to set the div's position to 100 px from top after scrolling 100 px. <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(window).scroll(function(){ $("#header").css("top",Math.max(0,100-$(this).scrollTop())); }); </script> <div class="header" style="position:fixed;top:100px;background-color:red">something</div> it is not working(the div stick to it's fixed position). it seems that the function is not relating to the div. what is my problem ?

    Read the article

  • A 4-byte Unsigned Int for Sql Server 2008?

    - by Jeff Meatball Yang
    I understand there are multiple questions about this on SO, but I have yet to find a definitive answer of "yes, here's how..." So here it is again: What are the possible ways to store an unsigned integer value (32-bit value or 32-bit bitmap) into a 4-byte field in SQL Server? Here are ideas I have seen: 1) Use a -1*2^31 offset for all values Disadvantages: need to perform math on the values before reading/writing/aggregating. 2) Use 4 tinyint fields Disadvantages: need to concatenate values to perform any operations 3) Use binary(4) Disadvantages: actually uses 4 + 2 bytes of space

    Read the article

  • Javascript game with css position

    - by newb125505
    I am trying to make a very simple helicopter game in javascript and I'm currently using css positions to move the objects. but I wanted to know if there was a better/other method for moving objects (divs) when a user is pressing a button here's a code i've got so far.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Game 2 helicopter</title> <script type="text/javascript"> function num(x){ return parseInt(x.replace(/([^0-9]+)/g,'')); } function getPos(x, y){ var inum=Math.floor(Math.random()*(y+1-x)) + x; inum=inum; return inum; } function setTop(x,y){ x.style.top = y+'px'; } function setBot(x,y){ x.style.bottom = y+'px'; } function setLeft(x,y){ x.style.left = y+'px'; } function setRight(x,y){ x.style.right = y+'px'; } function getTop(x){ return num(x.style.top); } function getBot(x){ return num(x.style.bottom); } function getLeft(x){ return num(x.style.left); } function getRight(x){ return num(x.style.right); } function moveLeft(x,y){ var heli = document.getElementById('heli'); var obj = document.getElementById('obj'); var poss = [20,120,350,400]; var r_pos = getPos(1,4); var rand_pos = poss[r_pos]; xleft = getLeft(x)-y; if(xleft>0){ xleft=xleft; } else{ xleft=800; setTop(x,rand_pos); } setLeft(x,xleft); setTimeout(function(){moveLeft(x,y)},10); checkGame(heli,obj); } var heli; var obj; function checkGame(x,y){ var obj_right = getLeft(x) + 100; var yt = getTop(y); var yb = (getTop(y)+100); if(getTop(x) >= yt && getTop(x) <= yb && obj_right==getLeft(y)){ endGame(); } } function func(){ var x = document.getElementById('heli'); var y = document.getElementById('obj'); alert(getTop(x)+' '+getTop(y)+' '+(getTop(y)+200)); } function startGame(e){ document.getElementById('park').style.display='block'; document.getElementById('newgame').style.display='none'; heli = document.getElementById('heli'); obj = document.getElementById('obj'); hp = heli.style.top; op = obj.style.top; setTop(heli,20); setLeft(heli,20); setLeft(obj,800); setTop(obj,20); moveLeft(obj,5); } function newGameLoad(){ document.getElementById('park').style.display='none'; document.getElementById('newgame').style.display='block'; } function gamePos(e){ heli = document.getElementById('heli'); obj = document.getElementById('obj'); var keynum; var keychar; var numcheck; if(window.event){ // IE keynum = e.keyCode; } else if(e.which){ // Netscape/Firefox/Opera keynum = e.which; } keychar = String.fromCharCode(keynum); // up=38 down=40 left=37 right=39 /*if(keynum==37){ //left tl=tl-20; db.style.left = tl + 'px'; } if(keynum==39){ //right //stopPos(); tl=tl+20; db.style.left = tl + 'px'; }*/ curb = getTop(heli); if(keynum==38){ //top setTop(heli,curb-10); //alert(curb+10); } if(keynum==40){ //bottom setTop(heli,curb+10); //alert(curb-10); } } function endGame(){ clearTimeout(); newGameLoad(); } </script> <style type="text/css"> .play{position:absolute;color:#fff;} #heli{background:url(http://classroomclipart.com/images/gallery/Clipart/Transportation/Helicopter/TN_00-helicopter2.jpg);width:150px;height:59px;} #obj{background:red;width:20px;height:200px;} .park{height:550px;border:5px solid brown;border-left:none;border-right:none;} #newgame{display:none;} </style> </head> <body onload="startGame();" onkeydown="gamePos(event);"> <div class="park" id="park"> <div id="heli" class="play"></div> <div id="obj" class="play"></div> </div> <input type="button" id="newgame" style="position:absolute;top:25%;left:25%;" onclick="startGame();" value="New Game" /> </body> </html>

    Read the article

  • converting char array into one int

    - by user1762517
    I can't use atoi, need to do it digit by digit.. How do I save it in a int.. given a char* temp put it all in one int.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int main () { char* temp = "798654564654564654"; int i = 0; for (i = 0; i < strlen(temp); i++) { printf("%d", temp[i] - 48); } printf("\n"); }

    Read the article

  • Is my code really not unit-testable?

    - by John
    A lot of code in a current project is directly related to displaying things using a 3rd-party 3D rendering engine. As such, it's easy to say "this is a special case, you can't unit test it". But I wonder if this is a valid excuse... it's easy to think "I am special" but rarely actually the case. Are there types of code which are genuinely not suited for unit-testing? By suitable, I mean "without it taking longer to figure out how to write the test than is worth the effort"... dealing with a ton of 3D math/rendering it could take a lot of work to prove the output of a function is correct compared with just looking at the rendered graphics.

    Read the article

  • Calculate Spearman's Rank Correlation Coefficient

    - by Arvigeus
    I'm trying to calculate correlations using this method. However, when I do the math by hand, I get one result, and when I do it with R - cor(dt, use="complete.obs", method="spearman") - I get totally different thing. Example data below: --------------------------------- AnswerPosID.1007 AnswerPosID.1008 --------------------------------- 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 --------------------------------- Manual result: 0.799777530589544; R cor: -0.07142857

    Read the article

  • Newbie programmer looking for a fun, small project (pref. C++/Python)

    - by Francisco P.
    Hello everyone, I have some experience in Scheme and C++ (read: a semester of each) I know the very basics of Python (used it for physics simulations with the Visual Python module). Can you recommend me some fun and small (i.e. don't take much time) projects on either Python or C++? I have no real preferences, just that it is fun :P Thanks for your time! PS: I've tried projecteuler and python challenge. Euler is good, but more about math than coding, and py challenge just didn't work for me.

    Read the article

  • How to column-ify an output from a certain program?

    - by mbaitoff
    I have a program that generates and outputs a sequence of simple sample math homework tasks, like: 1 + 1 = ... 3 + 3 = ... 2 + 5 = ... 3 + 7 = ... 4 + 2 = ... a sequence can be quite long, and I'd like to save space when this sequence is printed by converting it as follows: 1 + 1 = ... 3 + 7 = ... 3 + 3 = ... 4 + 2 = ... 2 + 5 = ... that is, wrapping the lines into the two or more columns. I was expecting the column linux utility to do the job using the -c N option witn N=2, however, it still outputs the lines in one column whatever the N is. How would I do the column-ifying of the sequence of lines?

    Read the article

  • Parallel Processing Simulation in Javascript

    - by le_havre
    Hello, I'm new to JavaScript so forgive me for being a n00b. When there's intensive calculation required, it more than likely involves loops that are recursive or otherwise. Sometimes this may mean having am recursive loop that runs four functions and maybe each of those functions walks the entire DOM tree, read positions and do some math for collision detection or whatever. While the first function is walking the DOM tree, the next one will have to wait its for the first one to finish, and so forth. Instead of doing this, why not launch those loops-within-loops separately, outside the programs, and act on their calculations in another loop that runs slower because it isn't doing those calculations itself? Retarded or clever? Thanks in advance!

    Read the article

  • Can't set element ID in JavaScript, it's always undefined

    - by Dylaan Alith
    Hi, I want to have a function that generates ID's on the fly for a given jquery object, if it doesn't have one already. These ID's should then be used in future requests. I came up with the code below, but it doesn't work. The ID's are never set. The commented out alert statement below always return undefined. I always pass code like $(this) or $(options.el) as a parameter to substitute 'el'. Initially, the elements do not have explicitly ID set in HTML. Any help would be appreciated, here's the code: getElementId: function(el) { if(undefined == el.attr('id')) { el.attr('id',"anim-"+Math.random().toString().substr(2)); } // alert(el.attr('id')); return el.attr('id'); },

    Read the article

  • Amazon EC2 multiple servers share session state

    - by Theofanis Pantelides
    Hi everyone, I have a bunch of EC2 servers that are load balanced. Some of the servers are not sharing session, and users keep getting logged in and out. How can I make all the server share the one session, possibly even using a partitionresolver solution public class PartitionResolver : System.Web.IPartitionResolver { private String[] partitions; public void Initialize() { // create the partition connection string table // web1, web2 partitions = new String[] { "192.168.1.1" }; } public String ResolvePartition(Object key) { String oHost = System.Web.HttpContext.Current.Request.Url.Host.ToLower().Trim(); if (oHost.StartsWith("10.0.0") || oHost.Equals("localhost")) return "tcpip=127.0.0.1:42424"; String sid = (String)key; // hash the incoming session ID into // one of the available partitions Int32 partitionID = Math.Abs(sid.GetHashCode()) % partitions.Length; return ("tcpip=" + partitions[partitionID] + ":42424"); } } -theo

    Read the article

  • Accommodating null values in a list?

    - by h259bws
    Hi, I'm new to Java and Groovy and am running into trouble with the following Groovy script. I created this whittled down version of a larger script to facilitate debugging. The script is iterating through a list trying to calc a running total of the values of all objects in the list. Some or all of these objects' values may be null. Script import org.apache.commons.lang.math.NumberUtils class Field { def name def value } def fields = [ new Field(name:'Annuities %', value:75), new Field(name:'Other %', value:null), ] //def totalFunding = fields.inject(0) {int total, Field myField - // total + NumberUtils.toInt(myField.value,0) as Integer def totalFunding = fields.inject(0) {int total, Field myField - total + myField?.value as Integer } It gets this error: Exception thrown: java.lang.NullPointerException java.lang.NullPointerException at Script3$_run_closure1.doCall(Script3:15) at Script3.run(Script3:14) What is the correct way to accomodate null values? Thanks, Betsy

    Read the article

  • How do I indicate that a class doesn't support certain operators?

    - by romeovs
    I'm writing a class that represents an ordinal scale, but has no logical zero-point (eg time). This scale should permit addition and substraction (operator+, operator+=, ...) but not multiplication. Yet, I always felt it to be a good practice that when one overloads one operator of a certain group (in this case the math operators), one should also overload all the others that belong to that group. In this case that would mean I should need to overload the multiplication and division operators also, because if a user can use A+B he would probable expect to be able the other operators. Is there a method that I can use to throw an error for this at compiler time? The easiest method would be just no to overload the operators operator*, ... yet it would seem appropriate to add a bit more explaination than operator* is not know for class "time". Or is this something that I really should not care about (RTFM user)?

    Read the article

  • How do I generate a random time interval and add it to a mysql datetime using php?

    - by KeenLearner
    I have many rows in mysql table with datetime's in the format of: 2008-12-08 04:16:51 etc I'd like to generate a random time interval of anywhere between 30 seconds, and 3 days and add them to the time above. a) how do I generate a random time between 30 and 3 days? b) how do I add this time to the date time format above? I imagine i need to do a loop to pull out all the info, do the math in php, and then update the row... Any ideas?

    Read the article

  • android, find the nearest location without going through all the locations

    - by Marwan
    I am building a taxi dispatching app first: I need the passenger app to show the nearest taxis, now I know how to do that in code but in my way I have to go through all the taxis locations(in database on server) and calculate the distance from the passenger location and get the lowest ones - I don't want to do this because there will be a lot of taxis and going through all of them and making some math is kind of pain on the server- is there a way to get the nearest ones without going through all of them? second: what the best database to use - first, should it be sql or non-sql - I need a very robust database, because there will be a lot of updates (I mean the passengers locations added then deleted when arriving to destination && the taxis location changes frequently) finally: I will use RubyOnRails to do the server side and json as data transfer format, do you have a recommendation to me on something better? Thanks

    Read the article

  • Given a number N, find the number of ways to write it as a sum of two or more consecutive integers

    - by hilal
    Here is the problem (Given a number N, find the number of ways to write it as a sum of two or more consecutive integers) and example 15 = 7+8, 1+2+3+4+5, 4+5+6 I solved with math like that : a + (a + 1) + (a + 2) + (a + 3) + ... + (a + k) = N (k + 1)*a + (1 + 2 + 3 + ... + k) = N (k + 1)a + k(k+1)/2 = N (k + 1)*(2*a + k)/2 = N Then check that if N divisible by (k+1) and (2*a+k) then I can find answer in O(N) time Here is my question how can you solve this by dynamic-programming ? and what is the complexity (O) ? P.S : excuse me, if it is a duplicate question. I searched but I can find

    Read the article

  • detecting returned errors with $.post

    - by sova
    I'm using $.post to send a query to a JSP which returns some awesome data for me. If the query is malformed, however, the page returns with "error on page" and an HTTP Status of 500 Internal Server Error in jQuery, how can I detect this error so I can tell the user of the failure? runQuery : function () { $.post( admin_stats.runQueryURL, { buster : Math.random, statsQuery: admin_stats.getQuery(), jsp: 'admin_statsQuery' }, admin_stats.handleStatsQuery, "html" ); the returned data is an HTML table which is sufficient for this project at the moment. Also: totally open to criticism if this is ugly or not the way I should be doing things =)

    Read the article

  • Run java with highest security setting

    - by Ankiov Spetsnaz
    I'm currently writing an in house coding challenge web application and I am wondering if there is any other security precaution I would need to have other than below java option at runtime. java -Djava.security.manager=default Basically, challenges would be more of single threaded math and algorithm focused. So I would need to enable basic data structure objects and disable any file, sockets, threading or any thing that might be not so important. Based on my quick search turning on security manager as above seems to be a solution but since this is a security related I would like to be sure before it goes alive. Is there anything else I could do more?

    Read the article

< Previous Page | 102 103 104 105 106 107 108 109 110 111 112 113  | Next Page >