Looking for algebraic primitive function solver code for math - math

I want to solve primitive functions algebraic for math class. I have been looking around and have found a lot of websites that have this function, but not any open source code!
The basic functionality is to have a function, and the be able to calculate it's primitive function and get the result back as an algebraic expression.
eg.
input: f(x) = cos(x)
output: F(x) = sin(x)
Are there code out there to solve this problem? I just need a template for my own code. And so the language isn't really of any concern.
Thanks for any help!
I have looked around on github and googled but haven't found anything!

Related

LCP(linear complementary problem) implementation in Java

I currently have an issue with a new project, because I need a solution for a LCP. I know there are
algorithms like Lemke etc. But each of them seems to be written in C++ or Python(using numpy).
I am not really able to implement an algorithm by myself, because I'm not completely familiar with all the math behind it.
So my question is if there is any LCP solver for Java which I can just use by calling something like
SolveLCP(Matrix M, Vector q, Vector w, Vector z)
for computing w and z from M and q ?
I found an algorithm at
https://www.geometrictools.com/GTE/Mathematics/LCPSolver.h
which seems to work pretty good, but unfortunately it's C++ and I failed to convert it into java(actually I use kotlin). My version has the correct results sometimes, but not every time compared with the C++ implementation.
I implemented it in kotlin, you can find it here:
https://github.com/mihisg/LCPSolver_Kotlin/tree/main
I would really appreciate it if someone could help finding the errors. I think I did something wrong with representing all those pointers, but in fact, it only works sometimes.

2D optimize() in R

I would like to use optimize() to find parameters of 2 dimensional mixed normal distribution but I don't know how to use the function.
I have the density function:
mixdnorm2<-function(x,y,p,mu11,mu12,s11,s12,rho1,mu21,mu22,s21,s22,rho2){
dnorm2<-function(x,y,m1,m2,s1,s2,r){
U<-c(x-m1,y-m2)
S<-matrix(c(s1^2,s1*s2*r,s1*s2*r,s2^2),2,2,byrow = T)
f<-1/(2*pi*sqrt(det(S)))*exp(-0.5%*%t(U)%*%solve(S)%*%U)
return(f)
}
f<-p*dnorm2(x,y,m11,m12,s11,s12,rho1)+(1-p)*dnorm2(x,y,m21,m22,s21,s22,rho2)
return(f)
}
but I don't know what to do with it.
optimize(mixdnorm2...)
Please do you know, how to use the function? I couldn't find anything about the problem so I'll glad for any advice :)
The optimize function is only for 1 dimension. The optim function is the one to use for 2 or more dimensions. So look up the help page for optim.
For some reason the help page for optimize does not mention optim, though the help page for optim does mention optimize.
There are also some packages that provide additional optimization functions (search on CRAN).

Maple graphing inaccuracy

I am not used to using Maple, so this question may be fairly basic.
However, I cannot find anything helpful on the internet.
I am currently using Maple 13.
I need to draw the graph or find the solution of the following function:
f(x)=arccos(cos((1/273)*(2*Pi*10)*t)*cos(2*Pi*t*(1/365))+cos(6*Pi*(1/180))*sin((1/273)*(2*Pi*t*10))*sin(2*Pi*t*(1/365)))
And using the "plot" method in Maple, I tried to draw the graph, and as you can see, the function is periodic, so I expected the graph to be so. However, the graph was not periodic at all.
Also, using the "fsolve" method, I tried to find the root of the equations, only to find out the disappointing result: "0.", the most trivial solution of all.
I figured out that the reason for the error might be in the function itself, or maybe it's just the floating point representation, since no computer code can handle an irrational number exactly.
Is there any way to handle the numbers and/or the sin, cos, arccos functions more accurate to make the outcome get better?

Lua alternative to optim()

I'm currently looking for a lua alternative to the R programming languages; optim() function, if anyone knows how to deal with this?
http://numlua.luaforge.net/ looks interesting but doesn't seem to have minimization. The most promising lead seems to be a Lua wrapper for GSL, which has a variety of multidimensional minimization algorithms included.
With derivatives
- BFGS (method="BFGS" in optim) and two conjugate gradient methods (Fletcher-Reeves and Polak-Ribiere) which are two of the three options available for method="CG" in optim.
Without derivatives
- the Nelder-Mead simplex (method="Nelder-Mead", the default in optim).
More specifically, see here for the Lua shell documentation covering minimization.
I agree with #Zack that you should try to use existing implementations if at all possible, and that you might need a little bit more background knowledge to know which algorithms will be useful for your particular problems ...
R's implementation of optim isn't actually written in R. If you type "optim" with no parentheses at the prompt, it'll dump out the definition of the function, and you can see that after some error checking and argument shuffling it invokes an .Internal routine (coded in C and/or Fortran) to do all the real work.
So your best bet is to find a C library for mathematical optimization -- sorry, I have no recommendations -- and wrap that into Lua. I doubt anyone has written native-Lua code for this, and I would not recommend trying to code it yourself; doing mathematical optimization efficiently is still an active domain of basic research, and the best-so-far algorithms are decidedly nontrivial to implement.

How to describe a MATLAB function using mathematical notation?

Basically I have created two MATLAB functions which involve some basic signal processing and I need to describe how these functions work in a written report. It specifically requires me to describe the algorithms using mathematical notation.
Maths really isn't my strong point at all, in fact I'm quite surprised I've even been able to develop the functions in the first place. I'm quite worried about the situation at the moment, it's the last section of writing I need to complete but it is crucially important.
What I want to know is whether I'm going to have to grab a book and teach myself mathematical notation in a very short space of time or is there possibly an easier/quicker way to learn? (Yes I know reading a book should be simple enough, but maths + short time frame = major headache + stress)
I've searched through some threads on here already but I really don't know where to start!
Although your question is rather vague, and I have no idea what sorts of algorithms you have coded that you are trying to describe in equation form, here are a few pointers that may help:
Check the MATLAB documentation: If you are using built-in MATLAB functions, they will sometimes give an equation in the documentation that describes what they are doing internally. Some examples are the functions CONV, CORRCOEF, and FFT. If the function is rather complicated, it may not have an equation but instead have links to some papers describing the algorithm, which may themselves have equations for the algorithm. An example is the function HILBERT (which you can also find equations for on Wikipedia).
Find some lists of common mathematical symbols: Some standard symbols used to represent common mathematical operations can be found here.
Look at some sample pseudocode to see how it's done: For algorithms you yourself have coded up, you'll have to write them out in equation or pseudocode form. A paper that I've used often in my work is Templates for the Solution of Linear Systems, and it has some examples of pseudocode that may be helpful to you. I would suggest first looking at the list of symbols used in that paper (on page iv) to see some typical notations used to represent various mathematical operations. You can then look at some of the examples of pseudocode throughout the rest of the document, such as in the box on page 8.
I suggest that you learn a little bit of LaTeX and investigate Matlab's publish feature. You only need to learn enough LaTeX to write mathematical expressions. Then you have to write Matlab comments in your source file in LaTeX, but only for the bits you want to look like high-quality maths. Finally, open the Matlab editor on your .m file, and select File | Publish.
See Very Quick Intro to LaTeX and check your Matlab documentation for publish.
In addition to the answers already here, I would strongly advise using words in addition to forumlae in your report to describe the maths that you are presenting.
If I were marking a student's report and they explained the concepts of what they were doing correctly, but had poor or incorrect mathematical notation to back it up: this would lose them some marks, but would hopefully not impede my understanding of the hard work they've put in.
If they had poor/wrong maths, with no explanation of what they meant to say, this could jeapordise my understanding of their entire project and cost them a passing grade.
The reason you haven't found any useful threads is because most of the time, people are trying to turn maths into algorithms, not vice versa!
Starting from an arbitrary algorithm, sometimes pseudo-code, along with suitable comments, is the clearest (and possibly only) representation.

Resources