I used matlab, the built-in solve function is amazing.
It takes a set of strings with x,y,z or anything in it, and solve any nonlinear system of equations with almost all possible solutions.
Like:
x^2 + y^3 = 2
sin(y) * diff(log (x)) = 3
It can solve this and give all solutions.....
How can I do this? I know Newton's Law and Secant, but to give all solutions seem too hard. Is there any lib out there? Java or C++
You can use MATLAB itself with C++ using MATLAB Engine or MATLAB Coder
Related
I have 3 points [x0 y0], [x1 y1], [x2 y2] with strict conditional x0<x1<x2, y0<y1<y2. All this points lay on some exponentional functions y=ae^(bx)+c. I need to find a,b,c... It's not possible to solve system of 3 equations precisely, therefore I need to approximate it. Is there some math library in java that will help me solve this problem? I find something similar on mathcad
https://help.ptc.com/mathcad/en/index.html#page/PTC_Mathcad_Help/exponential_regression.html but not find in java.
Other way - how to solve system of 3 equations and 3 values approximately.
ae^(bx_0)+c=y_0
ae^(bx_1)+c=y_1
ae^(bx_2)+c=y_2
You have to solve a system of non-linear equations, for which only an approximate solution is possible but can be done using the Newton Raphson's Multivariate method.
The algorithm is, quite frankly, a notational pain but you can go through it here -
http://fourier.eng.hmc.edu/e176/lectures/NM/node21.html.
What is happening essentially is you have a function whose derivative lead you to an 'equilibrium' from an initial random point (which you guess as a possible root)
If you are not willing to write the code yourself this repo can give you a starter of sorts - https://github.com/prasser/newtonraphson.
But AFAIK, no ready library exists for this purpose. You can use Wolfram's Mathematica or MATLAB/OCTAVE for ready libraries though.
That said, here are a few other (more complicated) things you can look into
https://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm
https://www1.fpl.fs.fed.us/optimization.html
http://icl.cs.utk.edu/f2j/
http://optalgtoolkit.sourceforge.net/
http://scribblethink.org/Computer/Javanumeric/index.html
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_l_bfgs_b.html
Hope this helps!
I'm working with ImageJ. I have two arrays of points (i.e it[ ], cmx[ ]) and what I want is to adjust this to a sine function. I've been working with CurveFitting but I don't understand it very well. I also am having issues with UserFunction.
Is there an easier approach to this? If you have examples I would appreciate it.
The following Groovy script is an example of running curve fitting on three data points:
import ij.measure.CurveFitter;
xData = [0,1,2];
yData = [3.1, 5.1, 6.9];
cv = new CurveFitter((double[]) xData.toArray(), (double[]) yData.toArray());
cv.doFit(CurveFitter.STRAIGHT_LINE);
println (cv.getResultString());
I'm not sure if CurveFitter allows fitting to trigonometric functions, there doesn't seem to be this option in the available fitting types. You might try a high-degree polynomial fitting instead.
You can also ask on the ImageJ forum or mailing list regarding the implementation details of the CurveFitter class.
I'm looking for a Java library to solve this problem:
We know X is sparse(most of it's entries are zero), so X can be recovered by solving this:
variable X;
minimize(norm(X,1)+norm(A*X - Y,2));
It's a MATLAB code, matrix A and vector Y are known and I want the best X.
I saw JOptimizer, but I couldn't use it. (Doesn't have good documentation or examples).
What you need is a reasonably good LP Solver.
Possible Java LP Solver Options
Apache Commons (Math) Simplex Solver.
See this blog post.
If you have access to CPLEX (not-free), its Java API would work great.
Also, you can look into SuanShu, a Java numerical and statistical library
lpSolve has a Java wrapper which can do the job.
Finally, JOptimizer is indeed a good option. Not sure if you looked at this example.
Hope at least one of those help.
As far as I can tell, you're trying to solve a binary integer program for feasibility
Ax = b, x in {0,1}.
I'm not completely sure, but it seems that you might be interested in the optimization problem
min 1'*x
s.t. Ax = b, x in {0,1}
where 1 is a vector of 1's of the same dimension as x.
The feasibility problem may be in practice much easier than the optimization problem - it all depends on a particular A and b.
If you can get a license of either CPLEX or Gurobi (if you're an academic), these are excellent integer programming solvers with good Java API's. If you don't have access to these, lpsolve may be a good option.
As far as I can tell, JOptimizer will not solve your problem since your variables are integers (although I have never used JOptimizer).
To solve convex optimization problems in java you can use the following library https://github.com/erikerlandson/gibbous
I'm trying to port a Matlab code to Java and C++.
It's quite straightforward however I find a function that is more than simple operations, it numerically evaluates integral:
lungh=quad('normpp',0,1,[],[],x1,x2,x3,x4,x5,x6,x7,y1,y2,y3,y4,y5,y6,y7);
Here x1,...,x8 and y1,...,y7 are simple numbers.
First of all, how do this parameters are interpreted? How does this function work?
I think that 0 and 1 are the bounds of the integral...but what about the others?? Especially 'normpp' and []?
I read the quad help but I didn't understand how it works with such an amount of parameters.
The second problem is: Do exist a java and a C++ libraries that offer these function?
I would prefer to do it directly in Java and C++ without calling Matlab.
Thanks!
In C there is a very nice library : The Gnu Scientific Library (GSL).
Here is a link to the Numerical integration page of the GSL :
GSL
The use of this library in a C++ project is straight forward.
I think the function gsl_integration_qag is a good choice to replace the matlab quad function.
I want to write a java program to calculate integral with three-point Gauss.
How to calculate result of every function that is string?
For example want to calculate F(x) = x^4 + cos(x) + e^2x
Evaluating a string is not an easy task by itself.
You have to write your own Interpreter with Lexer and a Parser.
You can consider to use thirdparty libraries for mathematical functions parsing and execution. I've never used any one of them. Simple googling reveals this:
JbcParser
JepParser
I'm sure there are a couple of others around...
Hope this helps