w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
'exact' numerical value after numerical optimization MATLAB
You're trying to store/use a number that cannot be represented exactly in an IEEE754 64-bit double-precision floating point number. I'm not sure how you got that number without using vpa() in the first place, since 64-bit double is Matlab's maximum of precision... You could use the multiple precision toolbox by Ben Barrowes, or HPF by John d'Errico, also from the FEX. You'll have to convert/construct to/from string if you want to store/load it to/from file. But I have to agree with John's comment there: The fact is, most of the time, if you can't do it with a double, you are doing something wrong so...why exactly are those 32-or-more digits important?

Categories : Matlab

Summing text inputs in which the number of inputs changes based on a for loop
You'll have to examine all input elements and examine their name, checking for the prefix "hous". For example: var sum = 0; var elts = document.getElementsByTagName('input'); for( var i=0; i<elts.length; i++ ) { var elt = elts[i]; if( elt.id && elt.id.indexOf( 'hous' ) === 0 ) sum += Number( elt.value ); } console.log( sum ); This solution doesn't need jQuery. See it in action here: http://www.codepen.io/anon/pen/xmrGu

Categories : PHP

Python User-Defined Global Variables Across Modules: Issues calling them when other modules are run
Running a module as a script does not count as importing it as a module. When the Functions_Practice_Main.py script imports Functions_Practice, and Functions_Practice imports Functions_Practice_Main, Python doesn't care that the code in Functions_Practice_Main.py is already running as the main script. Python will run it again to produce the module. How do you fix this? Well, there are several things you should do. First, avoid circular imports if at all possible. Instead of having Functions_Practice import Functions_Practice_Main, pass any data Functions_Practice needs from Functions_Practice_Main as function arguments. In Functions_Practice_Main: Functions_Practice.interactive_remainder_test(name) In Functions_Practice: def interactive_remainder_test(name): number = inputData(na

Categories : Python

Including admin parts in modules(bundles) in symfony2 ansd calling them from other modules and templates
I think you misunderstood what Symfony2 offers you. I'll try to explain some of them for your use case. What I understood You want to create an admin panel on your website. It's a common case. What to do You should create a bundle for this whole content. Like AdminBundle Step by step Let's look at a Symfony2 directory structure. Here's an excerpt. project/ app/ config/ config.yml parameters.yml cache/ AppKernel.php src/ Acme/ DemoBundle/ Controller/ Resources/ config/ public/ views/ AcmeDemoBundle.php vendor/ symfony/ autoload.php web/ .htaccess app.php a

Categories : Symfony2

Ambient declations for javascript modules that add fields to interfaces in other modules
If the item you are extending is an interface, they are open in TypeScript, so you can just add the extras like so: interface ExpressServerRequest { myAdditionalThing(): void; } There are ways of declaring pretty much anything, so if this isn't the trick for your case just post the exiting ExpressServerRequest and I'll update the example. The version of express.d.ts I checked on Definitely Typed has ExpressServerRequest as an interface.

Categories : Node Js

Configuring AngularJS modules - how does it affect the other modules in the app?
Here is what i think. Like any other angular $httpProvider is also singleton in nature which very well means any changes to it from any where including any module would affect other, or in other words changes are global.

Categories : Angularjs

What does it mean to have modules inside other modules in Ruby?
It is essentially namespacing. You could do the same thing with just module Fabrication::Syntax::Make. For whatever reason, nesting them is what most well-known gems/projects do, and for that unknown reason I do too. I would love to get some insight as to why people generally prefer nesting over the more direct method.

Categories : Ruby

Getting numerical value from edit box in MATLAB
You can get the value of the edit box with S = get(editBoxHandle, 'string'); If it's a numerical value, then convert it N = str2num(S); If you want to have only the digits within a string mixing letters and numbers, this code S = '123abc456xyz'; N = cell2mat(regexp(S, 'd+', 'match')); disp(N) gives N=123456 (from this SO answer).

Categories : Matlab

constraint on all numerical tables
You would need to create a separate constraint for each column in each table. You could potentially write a bit of dynamic SQL for this DECLARE l_sql_stmt VARCHAR2(1000); BEGIN FOR x IN (SELECT * FROM user_tab_columns WHERE data_type = 'NUMBER' AND table_name in (SELECT table_name FROM user_tables WHERE dropped = 'NO' ) LOOP l_sql_stmt := 'ALTER TABLE ' || x.table_name || ' ADD CONSTRAINT chk_' || x.table_name || '_' || x.column_name || ' CHECK( ' || x.column_name || ' > 0)'; EXECUTE IMMEDIATE l_sql_stmt; END LOOP; END; For every numeric column in every table in the current schema, this will attempt to create a check c

Categories : SQL

Git expects numerical timeout?
If something related to GitHub suddenly stop working, then it is probably linked to its status. 6:24 UTC A small percentage of repositories are currently unavailable while we perform maintenance. If it does persist though, then it could be related with some local configuration issue. For instance, check git status and git branch, making sure you are on a branch, and not in a detached HEAD mode. If git status mentions files to be committed (ie they have been added to the index but not yet registered ion a commit), do a git commit after your git add. If git branch doesn't return anything, then you need to follow "Git: How can I reconcile detached HEAD with master/origin?"

Categories : GIT

Meaning of a numerical ErrorMessage
cout << "MTB Error: " << message <<":"<<(unsigned int) e->Error()<< endl; cout isn't very good at displaying Unicode strings, it merely displays the string pointer value. Not useful of course, use wcout instead. And favor displaying the error code in hex. 0x80040154 is a very common COM error, "Class not registered". Thousands of questions about it already, you just need to get the COM server registered properly. Ask the vendor or author if you don't know how to do that.

Categories : C++

Converting Text Field to Numerical Value (Getting NaN)
val returns a string. Now, the way you're using those variables, they'll get automagically converted to numbers (although it's best practice to parse them yourself). One or the other of your values has a character in it that prevents the value from being automatically converted to a number; and then since that's NaN, any math involving it will be NaN. If you examine AmtX and AmyY in Firebug before using them, you should see whatever that character is. Again, parsing isn't the actual problem here, but you're using parseInt in exactly the wrong place (unless you were trying to use it to truncate the fractional portion of the number, in which case there are better choices). Here are the right places: var AmtX= parseInt($('#Apply_RequestedAdvanceAmtX_r').val(), 10); var AmtY= parseInt($("#A

Categories : Javascript

SAS Group by numerical value or convert to char
You're not getting distinct entries because it is ignoring your group by, because you didn't ask for any summary functions. SAS does not permit group by without a summary function (ie, sum(something) or count(something) or whatever), it converts it to order by. There's no explicit reason numeric wouldn't work for grouping. This is noted in the log with a NOTE, by the way. You can use distinct, as you suggested in the comments: proc sql; select distinct username, customercode from have; quit; That will give you a list of all username/customercode combinations. If you wanted to format it, you have to remove the $ - the $ in format does not mean "make this a character", which is what all formats do; it means "the original value pre-format was a character value". proc sql; create

Categories : Sas

Sorting strings with numerical digits in it
You can e.g make struct like this struct combined{ string alph; int numeral; }; put these in a c++ standard container and use the sort of algoritm with a user defined compare object.

Categories : C++

How to make numerical field name CLS compliant?
Ok, then try this. Open the xsd file. Right click on the table. Select configure. Assign an alias in the select statement. Update report. This link might help u out

Categories : C#

Numerical precision for difference of squares
The most precise way with floats is likely to compute both sin and cos using a single x87 instruction, fsincos. However, if you need to do the computation manually, it's best to group arguments with similar magnitudes. This means the second option is more precise, especially when cos_theta is close to 0, where precision matters the most. As the article What Every Computer Scientist Should Know About Floating-Point Arithmetic notes: The expression x2 - y2 is another formula that exhibits catastrophic cancellation. It is more accurate to evaluate it as (x - y)(x + y). Edit: it's more complicated than this. Although the above is generally true, (x - y)(x + y) is slightly less accurate when x and y are of very different magnitudes, as the footnote to the statement explains:

Categories : C++

Setting non-numerical list values
Actually li elements only accepts integers in their value attribute, so it's not possible solely through li's. Depending on your layout you could simply remove the list-style and prepend your own 'value' in a span before the rest of your content.

Categories : HTML

Formula to get the first cell with a numerical value from a selection?
You can simplify the last number formula by using LOOKUP, i.e. =LOOKUP(9.99999999999999E+307,B:B) and for the first number try this =INDEX(B:B,MATCH(1,INDEX(ISNUMBER(B:B)+0,0),0))

Categories : Excel

Numerical Integration; CUDA development
If I understand your problem correctly, you want to do numerical integration with multiple (1024) sets of inputs (a,b,c), and for each integral you need N sub-intervals. Let's call the number of sets of inputs M. If N is large enough (let's say > 10000) the first kernel sample you pasted could be good enough (invoking it M times for different set of inputs). Whether or not it utilizes all available device throughput depends on how complex your function is. I didn't get what exactly you do with the d_arr[] array? Normally for numerical integration you would want to sum it. Right? Are you summing up the results on CPU? Consider using atomicAdd (esp. if you are going to run your kernel on compute cap 3.0 and above gpus) or a parallel scan if you find atomicAdd not fast enough. If N is sm

Categories : Performance

Join two queries and use for numerical division
This should do it. SELECT SUM(TIME_TO_SEC(TIMEDIFF(od.created_at, oc.created_at))) / COUNT(*) AS `sec_per_call` FROM on_connected oc JOIN on_disconnected od ON od.call_id = oc.call_id WHERE oc.ext_num = 3205006 You don't need two subqueries, because the criteria in both are the same. You just need to divide the two aggregates. Also, count(TIME_TO_SEC(TIMEDIFF(od.created_at, oc.created_at))) doesn't really make sense. The COUNT() function just counts non-null values, there's no need to do complicated conversions like TIMEDIFF and TIME_TO_SEC in there. If you just want to know the number of calls, it's just the number of matching rows, which is COUNT(*). Actually, it can be simplified further. SUM/COUNT is just the average, and SQL has a built-in AVG function: SELECT AVG(TIME_TO_SE

Categories : Mysql

How do I search for documentation on numerical macros?
Google limits.h. Even better, look up this file on your system. Then, in Xcode (and other IDEs) code-completion is your friend; just start to type "int" and you'll see the list: INT16_MAX, INT16_MIN, ... On Xcode (in iOS project) I did not have to explicitly #include <limit.h> but you may have to do this first on other IDEs.

Categories : Objective C

sorting text data (like numbers) so the numerical value is followed
If you are using MySQL, you can do: order by field+0, field MySQL automatically does a conversion of the left-most characters in a string for an arithmetic operation. In other databases, this seems to be more difficult. In some, you can use REGEXP to replace a pattern (such as removing all characters after the first non-digit). Or, you might have to loop through the characters themselves, with something like: order by (case when left(field, 5) not like '[^0-9]' then cast(left(field, 5) as int) when left(field, 4) not like '[^0-9]' then cast(left(field, 4) as int) when left(field, 3) not like '[^0-9]' then cast(left(field, 3) as int) when left(field, 2) not like '[^0-9]' then cast(left(field, 2) as int) when left(field, 1) n

Categories : SQL

Rails Omniauth, set a numerical value only on first model creation
That's what first_or_initialize is! From Rails docs # Find the first user named Scarlett or create a new one with a particular last name. User.where(:first_name => 'Scarlett').first_or_create(:last_name => 'Johansson') # => <User id: 2, first_name: 'Scarlett', last_name: 'Johansson'> # Find the first user named Scarlett or create a new one with a different last name. # We already have one so the existing record will be returned. User.where(:first_name => 'Scarlett').first_or_create do |user| user.last_name = "O'Hara" end # => <User id: 2, first_name: 'Scarlett', last_name: 'Johansson'> find_or_create is complementary to first_or_initialize, the former persists the object. source

Categories : Ruby On Rails

Add email and numerical validation to jquery form
Check out this answer for validating your email field Email validation using jQuery Check out this answer for Zip Code validation ZIP Code (US Postal Code) validation To output to bootstrap warning message put something like the following instead of your alerts... $(body).prepend('<div class="alert alert-block alert-error fade in"><a class="close" data-dismiss="alert" href="#">&times;</a>You need to tell us something! Please enter your message!</div>');

Categories : Jquery

Give key names to an array with numerical keys
The answer here is to use array_combine($keys, $values); Note that the function will fail if the number of elements in the $keys and $values array are different.

Categories : PHP

Why am I getting an error when trying to convert "numerical" degrees to DMS using dd2dms()?
Your data might have some non-numeric entries buried somewhere, eg strings like "NA" or whatever. When R sees them, it assumes the whole column is character, which is probably then being converted into a factor. Note that: mode(f) for a factor f is numeric (since factors are internally stored as numbers). You want class(f). if x is a primitive vector, then sapply(x, mode) is needlessly complex. You want just mode(x).

Categories : R

Numerical Integral of large numbers in Fortran 90
This is probably an extended comment rather than an answer but here goes anyway ... As you've already observed Fortran isn't equipped, out of the box, with the facility for handling such large numbers as e^2000. I think you have 3 options. Use mathematics to reduce your problem to one which does (or a number of related ones which do) fall within the numerical range that your Fortran compiler can compute. Use Mathematica or one of the other computer algebra systems (eg Maple, SAGE, Maxima). All (I think) of these can be integrated into a Fortran program (with varying degrees of difficulty and integration). Use a library for high-precision (often called either arbitray-precision or multiple-precision too) arithmetic. Your favourite search engine will turn up a number of these for you,

Categories : Misc

Numerical Gradient in Matlab - Rounding Issues
If you work out the gradient of that Wolfe function, you come up with: if x<=0; dfx = 9 - 81*x.^8; dfy = 16*sign(y); elseif x>=abs(y); dfx = 5*0.5./sqrt(9*x.^2 + 16*y.^2)*9*2.*x; dfy = 5*0.5./sqrt(9*x.^2 + 16*y.^2)*16*2.*y; else dfx = 9; dfy = 16*sign(y); end So as you can see, the second component of the gradient for x<=0 is 16*sign(y), thus it is zero when y==0, +-16 otherwise. BTW, it doesn't look like the exact minimum lies at [-1 0], but rather at [-0.7598 0] = [-(1/9)^(1/8) 0]

Categories : Matlab

Show / Hide Multiple divs with out using a numerical value
You can add custom data attribute like data-value like this - Html : (same for other options) <option data-value='6' value="apatient6">6</option> Js : $(document).ready(function () { $('.formbox').hide(); $('#additional').change(function () { $('.formbox').hide(); for (i = 1; i <= parseInt($('option:selected',this).data('value')); i++) { $('#workshop' + i).show(); } }); }); Demo --> http://jsfiddle.net/PayBt/8/

Categories : Jquery

Differences in numerical behaviour between Scala versions
Sorry, can't post just a comment yet. What is the magnitude of the differences you're seeing, and what kind of calculation are you doing in your code? It may not be meaningful to ask which is correct, it's FP, after all. Could you try compiling your code with strictfp? Slight differences in code gen and optimization can result in differences in when/how often 80-bit intermediates are truncated to 64 -- assuming you're running on an x86 architecture. If you have access to hardware that doesn't have 80-bit fp registers you might try running both versions on that. Even then, simple expressions like LL + S1 + S2, where LL is much greater than S1 or S2, can give different results depending on the order of the adds.

Categories : Scala

Numerical integration when variable is lower limit
This is a more mathematical solution, but ( int_1^0 f(t) dt ) + ( int_0^x f(t) dt ) is equivalent to the negative of int_x^1 f(t) dt Thus, if you are able to find int_0^x f(t) dt, you should be ablue to find what you seek. Hopefully that helps. (Excuse any syntax errors, I am not familiar with the syntax. This is meant to be a mathematical solution, there may be better programmatical solutions) EDIT: As clarification, this was noted in a comment above (thanks to @Rody Oldenhuis for the clarification): "I believe it's a consequence of the fundamental theorem of calculus [FTC] that for any real-valued function f and limits a and b, int(f, a,b) == -int(f, b,a). So indeed, ... use flipud or fliplr on your f, find the limits and use cumtrapz, and don't forget the negative sign :)" In

Categories : Matlab

numpy gradient function and numerical derivatives
In np.gradient you should tell the sample distance. To get the same results you should type: plt.plot(x1,np.gradient(y(x1),1),'r--o') plt.plot(x2,np.gradient(y(x2),0.1),'b--o') plt.plot(x3,np.gradient(y(x3),0.01),'g--o') The default sample distance is 1 and that's why it works for x1. If the distance is not even you have to compute it manually. If you use the forward difference you can do: d = np.diff(y(x))/np.diff(x) If you are interested in computing central difference as np.gradient does you could do something like this: x = np.array([1, 2, 4, 7, 11, 16], dtype=np.float) y = lambda x: x**2 z1 = np.hstack((y(x[0]), y(x[:-1]))) z2 = np.hstack((y(x[1:]), y(x[-1]))) dx1 = np.hstack((0, np.diff(x))) dx2 = np.hstack((np.diff(x), 0)) d = (z2-z1) / (dx2+dx1)

Categories : Python

Numerical derivatives of an arbitrarily defined function
Install and load the numDeriv package. library(numDeriv) f <- function(x) { a <- x[1]; b <- x[2]; c <- x[3] sin(a^2*(abs(cos(b))^c)) } grad(f,x=1:3) ## [1] 0.14376097 0.47118519 -0.06301885 hessian(f,x=1:3) ## [,1] [,2] [,3] ## [1,] 0.1422651 0.9374675 -0.12538196 ## [2,] 0.9374675 1.8274058 -0.25388515 ## [3,] -0.1253820 -0.2538852 0.05496226 (My example is trivariate rather than bivariate, but it will obviously work for a bivariate function as well.) See the help pages for more information on how the gradient and especially Hessian computations are done.

Categories : R

Overloading comparison for double to allow for numerical error
No, you cannot overload operators for built-in types. No, changing the semantics of operators is (in general) not a good idea. You could either: Use comparison-functions (as you suggest yourself). Write a wrapper-class around a double member that has the operators you want.

Categories : C++

Plot numerical string values in matplotlib
edit: My matplotlib 1.2 can plot the string lists fine btw, there is no need for conversion to begin with, just plot them as they are. You can first convert them to a float32 Numpy array: x = ['1.34511','0.0234','-0.0890'] y = ['0.0987', '0.8763', '-0.0762'] x = np.array(x, dtype=np.float32) y = np.array(y, dtype=np.float32) plt.plot(x,y) Or use list comprehension to convert the values to a float: x = ['1.34511','0.0234','-0.0890'] y = ['0.0987', '0.8763', '-0.0762'] x = [float(val) for val in x] y = [float(val) for val in y] plt.plot(x,y)

Categories : Python

Is there a C# mathematics framework that can do numerical indefinite integration?
The indefinite integral is a family of functions, "F(x)+C", where F is any particular solution. Given a procedure for calculating a definite integral of f in any interval, you can pick F(x) as the definite integral from any abscissa to x. Given a way to calculate the definite integral of f in an interval, the indefinite integral function F that passes through the constraint point (u,v) is: F(x) = definite_integral(f, u, x) + v; On the other hand, if you want to avoid recalculating the integral for every point what you are actually looking for is a routine for solving the ordinary differential equation F'(x) = f(x) with the given constraint. Any decent library of numerical analysis should have several functions for solving ODEs.

Categories : C#

Input string does not match a numerical range
The input you get from gets is always a string, so it will never match a number range. To convert it to an integer, do this: cost = gets.to_i You can directly put it in case statement like so case gets.to_i

Categories : Ruby

Appropriate type for storing numerical data and be able to interpolate
You want to use sorted lists of X-Y pairs (List<Tuple<double,double>> would be an appropriate type for this). Let's assume you have two input lists, series1 and series2, which are sorted by X value, and you're checking series2 (and possibly interpolating) for the X values present in series1 (just as you state in the question). Because you need to check every coordinate in series1, there's a minimum complexity of O(n). The key to keeping this efficient is the fact that the lists are ordered, which means you don't have to search the entire series2 list for each X value in series1. You do this by keeping a pointer to the current item in series2, and moving it as you traverse series1. Here's pseudo-C# to show what I mean. var s2idx = 0; foreach(s1 in series1) { // go forward

Categories : C#

TeachingDemos: using etxtPlot with numerical results in loops
The reason that is happening is because it is assumed that you do not want the etxtPlot command to show up in the transcript or command history, so when that function is called it sets a variable that tells the workhorse internal function (that is called by the task manager) to skip outputting the commands and results temporarily. This works correctly outside of a loop because the suppression of the output only lasts for the call to etxtPlot and everything else is properly output. The problem comes when you do this in a loop, everything done in the loop is processed in a single step (see ?addTaskCallback for the details on how things are handled), so the suppressing of the command and output from etxtPlot ends up also suppressing the commands and output from everything else in the loop.

Categories : R

How to set a nvd3 axis to use strings instead of numerical values ?
You can pass in a format function that returns label. This is an API of d3js. var x_format = function(num) { if (num === 2.3) return "A"; else if (num === 5.6) return "B"; else if (num === 45.2) return "C"; }; var xAxis = d3.svg.axis() .scale(x) .orient("bottom") .tickFormat(x_format); Check out this example that I make for scatterplot. http://vida.io/documents/jSGz9TQEmzwMqQzhs {(A, 2.3), (B, 5.6), (C, 45.2) } Update: my answer with fixed value. Update: hybrid combination between line, bar, scatterplot: http://vida.io/documents/fN5FjsYaHaJSXEjz7

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.