Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
 trendline option (excel) in matlab Here is a working solution: a = [15.5156,0.1995; 7.6003,0.2999; 9.4829,0.2592; 12.2185,0.2239; 23.4094,0.1811]; x = a(:, 1); y = a(:, 2); n = 2; % order of the fitted polynomial trendline p = polyfit(x, y, n); m = 1000; % number of trendline points (the larger the smoother) xx = linspace(min(x), max(x), m); yy = polyval(p, xx); figure; hold on; scatter(a(:,1), a(:,2)); plot(xx, yy, 'r-'); You can easily put the trendline calculator code into a separate function. Categories : Excel Solving a simple non-linear equation in Matlab I assume that x is a symbolic variable, while the vector z is numeric? So, something like this: syms x y; z = 1:5; solve(exp(x*max(z))/sum(exp(x*z))==y,x) which returns Warning: The solutions are parametrized by the symbols: z1 = RootOf(y*z^4 - z^4 + y*z^3 + y*z^2 + y*z + y, z) > In solve at 180 ans = log(z1) solve does give you a solution, just not an explicit one. It tells you that you have several solutions that are the roots of some polynomial. The more elements that z has (and depending on the specific values of z) the higher the order the polynomial will be. The roots of quadratics and cubics are easily found. Quartics (with constant coefficients) can also be factored. Some quintics can be too, but for higher orders, there are very few known analytical solutions for Categories : Matlab how to find non-linear equation parameters using a dataset I think the correct format should be: Y(X) = a [ b + (c * X^d)]^e A nice calculator is Wolfram Alpha, very detailed. Categories : Misc Templated linear equation system solver, C++ Take a look into Eigen: "Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms" http://eigen.tuxfamily.org/index.php?title=Main_Page Categories : C++ Solving a simple sparse linear system of equation using csparse: cs_cholsol Having never worked with csparse before, I skimmed the source code. When you call cs_spalloc() to create Operator, you are creating a triplet (indicated by setting the last parameter to 1). But, after the call to cs_copmress(), the result is no longer a triplet (you can detect this by checking the result and see that Operator->n is now -1 after compression). So, it is an error to traverse the matrix as if it were. You can use the cs_print() API to print your sparse matrix. As an aside, your code leaks memory, since the compressed matrix is a new allocation, and the original uncompressed matrix was not freed by cs_compress(). Categories : C++ Gradient descent does not return incorrect prediction for linear function In this line sum = sum + ((dot(theta', x(i, :)) - y(j)) * x(i,j)); you are using a wrong index of y, it should be y(i), as j is a dimension iterator, not the sample iterator. After the change theta = -1.5168e-07 1.0000e+00 Categories : Algorithm Excel VBA Modify Existing Equation if the formula is changed to =A1+A3+A5 then code could be: Range("B1").Formula = Range("B1").Formula & "+" & Range("A7").Address or, without dollar signs, Range("B1").Formula = Range("B1").Formula & "+" & Range("A7").Address(False, False) Added in response to OPs comment. If I assume the new cell is two rows above where the formula is, which is the currently the active cell: ActiveCell.Formula = Replace(ActiveCell.Formula, ")", "," & _ ActiveCell.Offset(-2, 0).Address(False, False) & ")") Adjust the value -2 as necessary. Categories : Excel Create a trendline via flot? Here is a trend line plugin for flot, but it may need some additional work: flot issue 270 (download link after the first post) Categories : Jquery How to apply power fit trendline in R or gnuplot? To give an example for curve fitting with gnuplot, consider the following data set data.txt: 0.5 0.8 2.4 9.3 3.2 37.9 4.9 68.2 6.5 155 7.8 198 The fit with a power law function may look like this: set termoption enhanced f(x) = a*x**b; fit f(x) 'data.txt' via a,b plot 'data.txt' with points title 'data points', f(x) with lines title sprintf('power fit curve f(x) = %.2f·x^{%.2f}', a, b) With the terminal settings set terminal pngcairo size 800,600 font ',12' this gives the result This is, of course, the most basic way to fit, the 'specialties' depend on your actual needs. Categories : R Incorrect date formating in Excel worksheet You may use this snippit to convert from excel serial date format protected static DateTime FromExcelSerialDate(int serialDate) { if (serialDate > 59) serialDate -= 1; //Excel/Lotus 2/29/1900 bug return new DateTime(1899, 12, 31).AddDays(serialDate); } Categories : C# Solving linear and non-linear regression for vectors Found a good solution: DLIB solves this problem quite well. There is an example here: http://dlib.net/least_squares_ex.cpp.html Note: if you need to use matrices, DLIB still requires data to be stored as vectors. That is, if you are solving Ab=c and A is a 3x3 matrix, parameter_vector in the example linked above has to be typedef matrix parameter_vector; or it won't compile. Categories : C++ different result in -webkit-linear-gradient and -moz-linear-gradient This generator should produce you the correct cross-browser code. You can use import from css button at the lower right corner of the generated css fieldset. For your code, this was the output: background: #696969; /* Old browsers */ background: -moz-linear-gradient(top, #696969 0%, #3d3d3d 50%, #292929 50%, #171717 100%); /* FF3.6+ */ background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#696969), color-stop(50%,#3d3d3d), color-stop(50%,#292929), color-stop(100%,#171717)); /* Chrome,Safari4+ */ background: -webkit-linear-gradient(top, #696969 0%,#3d3d3d 50%,#292929 50%,#171717 100%); /* Chrome10+,Safari5.1+ */ background: -o-linear-gradient(top, #696969 0%,#3d3d3d 50%,#292929 50%,#171717 100%); /* Opera 11.10+ */ background: -ms-linear-gradient(top, #696969 0%,#3 Categories : CSS Excel file created in Excel 2007 is not opening in Excel 2003 using c# If you make an Excel file programmatically and name it with the .xls extension from Excel 2007 or 2010, you may be making an Open XML (.xlsx) file unknowingly, as this is the default save format for those versions of Excel. Essentially, if you are hard coding the file name, you may be saving an .xlsx file with the .xls extension, which would explain why you can't open the files. Try renaming the files generated from Excel 2007 to the .xlsx extension and see if you can open them. Categories : C# Display Excel inside VB6 / VB.NET Form & work with Excel without excel menu As far as I can tell - this is not possible. The reason being that you cannot subclass the excel window in VBA. If you program outside of excel with VB.NET or VB6 it would be sort of possible, but would probably not work really good. If you only want to display some data from a sheet and perform some small actions on them, you could probably read the Data via the EPPLUS Library, display them as a datatable (EPPLUS can convert between datatable and excel files), perform your actions and save them to the file afterwards. But this would only work in VB.net Categories : Vb.Net Why do I keep getting zero in my equation? You might want to try int percent = (100*rateNum) / count; or use floating point for the math. Your value is being rounded down to zero and then never recovering. Categories : Java How this does equation simplify to As you have written it, I think the equation is wrong. Since * represents component wise multiplication: (rs, gs, bs) * (as, as, as) = as(rs, gs, bs) (rd, gd, bd) * (1-as, 1-as, 1-as) = (1-as)(rd, gd, bd) So: (rs, gs, bs) * (as, as, as) + (rd, gd, bd) * (1-as, 1-as, 1-as) = as(rs, gs, bs) + (1-as)(rd, gd, bd) Categories : C++ If equation has no roots Is it a program or a function? If it's a program, something that will be invoked by people, the right way is to output the phrase "No solutions" or something like that. Now, if it's a function that returns variable(s), the question is different. First, not all languages have a None as a possible numeric value; C/C++, for example, does not. Does the code solve any kind of equation? In that case, consider this. An equation may have multiple roots. That means you should somehow return a collection of roots. If there are no roots, an empty collection would be the right thing to return. Also, an equation may have an infinite number of roots (example: 0*x=0). Categories : Python PHP simple equation Change your if statement to: // security if($prv != 0 AND$prv != 2) { die("

Error

"); } With the OR it will always evaluate as true because when $prv == 0 it does not equal 2. Makes sense? Categories : PHP Using a value from a matrix as a multiplier in an equation? In MATLAB, apostrophes ('') define a string. If the name of your matrix is answer, you can refer to its second value by the command answer(2) as mentioned by @Schorsch. For more infos on vectors and matrices, you can check this site. Categories : Matlab Quadratic Equation program Lines of this form are suspect; if ( sqrt((b*b) - 4*a*c) > 0 ) as you will be calling sqrt on a negative. You should check the real case, for example, by doing this: if (b*b - 4*a*c > 0) I've also dropped the unnecessary brackets. * has higher precedence than -. Only call the sqrt function on a non-negative parameter. Categories : C++ How can I implement this equation in python? Before implementing your own statistical stuff, have you looked into SciPy? SciPy Stats has many modules implemented using NumPy (C written, so it's faster than Python, but callable from Python, with a Pythonic syntax). So maybe you don't need to write any code yourself. Categories : Python Solve equation with a set of points Since you have more points than unknown coefficients, you'll want to do a least squares fit. This calculation will give you the coefficients that minimize the mean square error between the function and all the points. So substitute your 50 points into the assumed equation and get 50 equations for 3 coefficients. This is easily expressed as a matrix: Ax = b where the unknown vector x are your coefficients. Premultiply both sides by the transpose of A and solve using a matrix solver. Start by plotting the data you have. The choice of equation you start with will make your job easier or harder. Are you certain about that leading term? If that wasn't appropriate, you could take the natural log of both sides and it's a simple linear equation. The leading term makes that harder to te Categories : Python Collision equation for two 3d objects Referencing http://en.wikipedia.org/wiki/Elastic_collision : for i in range (0, len(allObjects) ): mass1 = getVolume(allObjects[i],objMultiplySize) velocity1 = getVelocity(allObjects[i],originalTime,objMultiplySize) mass2 = getVolume(objSel[j],objMultiplySize) velocity2 = getVelocity(objSel[j],originalTime,objMultiplySize) v1new = velocity1; //just initialization v2new = velocity2; //just initialization v1new[0] = (velocity1[0] *( mass1-mass2) + 2*mass2*velocity2[0])/(mass1 + mass2); v2new[0] = (velocity2[0] *( mass2-mass1) + 2*mass1*velocity1[0])/(mass1 + mass2); v1new[1] = (velocity1[1] *( mass1-mass2) + 2*mass2*velocity2[1])/(mass1 + mass2); Categories : Python Difference Equation Blowing Up - C I notice that this line: k = (float)(i/(segmentsl-1)); is performing integer division. Since i #include #include int main(void){ int width, maxt; float rvalue; int i,t; float k; //Pull in initial data printf("Enter as integers without spaces: Number of Segments - Length, Number of Segments - time ,value "); scanf("%d,%d,%f", &width,&maxt,&rvalu Categories : C Add an equation into scatter plots in R The "ps"-object is being handled as an expression, i.e. not being evaluated. To get around this use bquote and .() legend(locator(1), legend= bquote("Linear model: "* R^2*.(ps)), text.col= "red",cex=1,bty="n") BTW the first version would be more compactly represented without the paste: legend(locator(1), expression(Linear~model*":"~ R^2 == 0.1234), text.col= "black",cex=1,bty="n") The only thing needing to be quoted is the semi-colon. Categories : R Showing mathjax equation one by one It seems working, but solution is not elegant. typesetMath(jQuery(".formula"),0); function typesetMath(formulas,ind){ MathJax.Hub.Queue(["Typeset",MathJax.Hub,formulas.get(ind)], function(){ jQuery(formulas.get(ind)).css("visibility","visible"); if(ind+1> syms u1 u2 f3 f4; >> K = magic(4); >> f = [2 3 f3 f4].'; >> u = [u1 u2 9 7].'; >> K*u - f ans = 16*u1 + 2*u2 + 116 5*u1 + 11*u2 + 143 9*u1 + 7*u2 - f3 + 138 4*u1 + 14*u2 - f4 + 142 In which I altered the formatting for clarity. From this we can see that if we define b = [-116 -143 -138 -142].'; A = [16 2 0 0 5 11 0 0 9 7 -1 0 4 14 0 -1]; Then we have an equation in standard form A*X = b where X = [u1 u2 f3 f4].' Then, it is a simple matter of >> X = A ans = -5.963855421686747e+000 % u1 -1.028915662650603e+001 % u2 +1.230120481927711e+00 Categories : Matlab SELECT *, sum() with equation only returns one row In MySQL you can include columns in the select that are not aggregated and not in the group by. Because your query has an aggregation function, MySQL recognizes it as an aggregation query, and only returns one row. Actually, you need to bring in the total value for a calculation on each row. Here is one way using a subquery in the select statement: SELECT *, (select sum(q6) as sumq6 from table where field2 = 'xxx') / (q1 * (q1 + q2 + q3 + q4 + q5 + q6) / 6) * 100) AS percent FROM table WHERE field2 = 'xxx' ORDER BY percent ASC; Here is another way, using a cross join: SELECT *, (sumq6 / (q1 * (q1 + q2 + q3 + q4 + q5 + q6) / 6) FROM table cross join (select sum(q6) as sumq6 from table where field2 = 'xxx') as const WHERE field2 = 'xxx Categories : Mysql How can I get this array equation to work? I assume your reuse of i is tripping up your loop. At the end of the loop, when for handles the i, it may have completely changed value. If var i = (+document.getElementById('if' + i).value)/12; sets i to some value greater than 24, the loop will terminate at the start of the next iteration due to the i <= 24 condition. Instead, use a different variable name for your loop index and the values in your computation. Categories : Javascript Need help porting this equation to java Your problem is inside Math.pow - you're multiplying your index value by a scalar each time. 4 * Math.pow(i, 3) And 3 * Math.pow(i, 2) Should fix it. Edit: And the integer division mentioned in other answers. Categories : Java +/- equation with a single textfield Because, You are performing addition with an array type variable.$assoc = mysql_fetch_assoc($sql); Here,$assoc is an array variable so try like this, $v_nu =$v_stk + \$assoc['v_stk']; Categories : PHP Why has changed both sides of equation in java? d=dataset You now have two variables that both refer to the same object. Unlike C++, Java never implicitly copies anything. If you want a separate copy of an object, you need to make one yourself. If the object implements Cloneable, you can do that using clone(). Categories : Java How can I solve this kind of equation in Maple? In (Eq. 1) it's not your syntax that's an issue. You have three unknowns {a,b,c} but only one equation. You simply do not have enough equations to determine {a,b,c} uniquely. Maple's solve function only returns an answer (if possible) if the number of variables equals the number of equations. In (Eq. 2) you use square brackets, which are used for ordered lists. The solve function requires a set of equations, which are indicated by curly braces. Again, you have three variables but only one equation. Same problem. If the equations are linear (which they aren't in your case), Maple can find a parameterization for the solutions in the case of an underdetermined system: http://www.maplesoft.com/support/help/Maple/view.aspx?path=solve/linear. Categories : Misc Custom equation solver error Here, the map which you are passing is not with the generic types. Hence, get() will always return an object, which is not an appropriate argument for parseInt() method. Changing the method signature to public boolean solve(String equation, Map< String ,String > gladMap) { should solve the errors. Categories : Java Write mathematical equation in flash You should consider using LaTeX2SWF library instead of trying to import Microsoft Equation directly. Example here If you can't download it, you can try something like this You should also convert all of your Math Equations from Microsoft format to LaTeX. There are a lot of automated programs and plugins, like this, but there are lots of others Categories : Actionscript How to fit equation of the form y=ao+a1logx+a2log(2/x) What toolboxes are available to you? The easiest way would probably be the cftool. (Type it into your command window) if you have the curve fitting toolbox. But polyfit should do as well. The main problem I see: Your coefficients are not independent of one another. Because log(2/x) is equal to log(2) - log(x) your equation becomes: y = ao + a1*log(x) + a2*log(2) - a2*log(x); which is equivalent to: y = bo + b1*log(x); Try that one. Categories : Matlab Wrong answer with equation in python Integer division. 4/3 evaluates to 1 as it is rounded down. Use 4.0 instead to force floating point arithmetic: >>> 4.0/3 * 6.67*1e-11*3.14*6378000*5515 9.822550047279998 or use Python 3, where floating point division is the default, or use from __future__ import division to achieve the same in Python 2: Python 2.7.5 (default, May 22 2013, 12:00:45) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from __future__ import division >>> 4/3 * 6.67*1e-11*3.14*6378000*5515 9.822550047279998 This behaviour is documented under the Binary arithmetic operators section: The / (division) and // (floor division) operators yield the quotient of their arguments. Categories : Python Program for the discriminant of a quadratic equation One problem I can see is with the following - return new complexNumber[]{ (-b + Math.sqrt(discriminant))/(2*a)}; the result of (-b + Math.sqrt(discriminant))/(2*a) is not a complexNumber. An array of complexNumber should have instance of complexNumber. Categories : Java