I am looking for an alternate function of scipy.special.expi() in julia. This function finds exponential integral Ei. More details can be found here: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.expi.html
Please suggest a solution to this issue.
Thanks in advance!
It looks like https://github.com/JuliaMath/SpecialFunctions.jl has an implementation.
As suggested by #Oscar, the equivalent alternative to scipy.special.expi() in julia can be implemented as follows:
using SpecialFunctions
#to find the exponential integral of x
expinti(x)
Related
I am solving the following simple linear program with pracma::linprog in R:
library(pracma)
cc=c(1)
A=as.matrix(-1)
b=c(1)
linprog(cc,A,b,maximize=FALSE)
The solution returned is x=0.
However, this solution is incorrect: a lower value of the linear program can clearly be obtained at x=-1.
I find that both Wolfram Alpha and Matlab return the correct solution.
Why does linprog return the wrong solution? Is there any way to correct this problem?
From ?linprog
This is a first version that will be unstable at times. For real
linear programming problems use package lpSolve
Which gives the same answer
lpSolve::lp(direction='min', cc,A,"<=",b)
Success: the objective function is 0
And from ?lp
Note that every variable is assumed to be >= 0!
PROBLEM: We have partial difference equation u(t): du/dt=sin(t); u(0)=0.
What numerical method should I use to solve the equation, how would i write an algorithm for u(1)?
I thought I could try finite difference method but I could use some guidance.
Please give a look at the ode function
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).
Julia-users: is there an equivalent to R's sample(x,y,prob=) to sample from a given set of values with weighted probabilities? The rand() function is equivalent to sample(x,y), but as far as I'm aware there's no option to add probability weights... Any help appreciated!
OK - done a bit more digging and wsample from the Distributions package seems to be the answer:
using Distributions
wsample(population, weights, n)
Next time I'll look harder before posting!
wsample exists also in the StatsBase.jl package (which I am not sure is a more recent addition compared to when the question was first answered)
If you go by StatsBase.jl you can also just use "sample":
using StatsBase
sample(population, Weights(weights), n)
In both packages you can also set a random number generator and whether to take with replacement for both functions too.
I've been searching on R help for a primitive function, because in my case I can't do it with integrate function, is there any way to find a primitive function (antiderivative)?
If it is a one-off, you can use a computer-algebra system (Maxima, Maple, Wolfram Alpha, etc.).
If you want to do it from R, you can use the Ryacas package.
For instance, yacas(expression(integrate(sin))) returns -Cos(x).
There is no analytical method to generate F where F'=f and f is known but you can always approximate a value for a specific bounds when the bounds is known using the trapezoid approximation for instance.