There's a warning when I tried to do an integration with MATLAB!
syms z
int(exp(sin(z)),z)
Warning: Explicit integral could not be found.
The expression exp(sin(x)) does not have a known analytical formula for it's indefinite integral. Mathematica agrees with Matlab on this: http://m.wolframalpha.com/input/?i=Integral+e%5Esin%5Bx%5D+dx.
While you can't evaluate the indefinite integral, you can compute definite integrals numerically to an arbitrary precision.
Related
E,M,F,lambda,x are Matrix or vector. The equation is:
E*x+F+Transpose(M)*lambda=0;
M*x-gamma=0;
Transpose(lambda)*(M*x-gamma)=0
The solutions of X and lambda are
lambda=-(M*E^(-1)*Transpose(M))*(gamma+M*Transpose(E)*F)
x=-E^(-1)*(F+Transpose(M)*Transpose(lambda))
How can I use Matlab's symbolic operation to obtain the X and lambda solutions of the above matrix equation? I don't want to deduce the formula myself. I want Matlab to deduce the formula automatically.
I need to compute efficiently and in a numerically stable way the inverse CDF F^-1(y) (cumulative distribution function) of a probability function, assuming that both the PDF f(x) and the CDF F(x) are known analytically but the inverse CDF is not. I am doing this in MATLAB.
This is a root-finding problem for F(x)-y and I could use fzero:
invcdf = #(y, x0) fzero(#(x) cdf(x) - y, x0);
However, fzero is for a generic nonlinear function.
I wonder if there is some function, or I can write some algorithm that uses the explicit information that F(x) is a cdf (for example, we know that it is monotonically non-decreasing and we have its derivative, f(x)).
FYI, the shape of the PDFs I am working with is generic mixtures of Gaussian distributions multiplied by a polynomial of arbitrary degree (the CDF can be computed analytically in this case, although it's not pretty and it becomes expensive for polynomials with many terms). Note that I need to compute the inverse CDF for millions of CDFs within this class; a lookup table is not feasible.
For more mathematical details see also this related question on Math Exchange (here I am asking specifically for a MATLAB solution).
I have an integration function which does not have indefinite integral expression.
Specifically, the function is f(y)=h(y)+integral(#(x) exp(-x-1/x),0,y) where h(y) is a simple function.
Matlab numerically computes f(y) well, but I want to compute the following function.
g(w)=w*integral(1-f(y).^(1/w),0,inf) where w is a real number in [0,1].
The problem for computing g(w) is handling f(y).^(1/w) numerically.
How can I calculate g(w) with MATLAB? Is it impossible?
Expressions containing e^(-1/x) are generally difficult to compute near x = 0. Actually, I am surprised that Matlab computes f(y) well in the first place. I'd suggest trying to compute g(w)=w*integral(1-f(y).^(1/w),epsilon,inf) for epsilon greater than zero, then gradually decreasing epsilon toward 0 to check if you can get numerical convergence at all. Convergence is certainly not guaranteed!
You can calculate g(w) using the functions you have, but you need to add the (ArrayValued,true) name-value pair.
The option allows you to specify a vector-valued w and allows the nested integral call to receive a vector of y values, which is how integral naturally works.
f = #(y) h(y)+integral(#(x) exp(-x-1/x),0,y,'ArrayValued',true);
g = #(w) w .* integral(1-f(y).^(1./w),0,Inf,'ArrayValued',true);
At least, that works on my R2014b installation.
Note: While h(y) may be simple, if it's integral over the positive real line does not converge, g(w) will more than likely not converge (I don't think I need to qualify that, but I'll hedge my bets).
I want to evaluate a definite integral with variable precision arithmetic in Matlab. It can be done using symbolic math toolbox in this way:
syms x
f = (x.^2000).*((1-x).^4000)
vpa(int(f,0,1))
This gives me the answer of the integral with variable precision arithmetic.
But I like to evaluate the integral without symbolic math toolbox. I can use the command 'integral' to calculate the integral but since the integral is calculated in fixed precision, it returns zero, i.e. the output of the following code is zero.
f = #(x) (x.^2000).*((1-x).^4000)
integral(f,0,1)
How can I combine vpa with numerical integration without using symbolic math toolbox?
Impossible, because the vpa function is a part of the symbolic math toolbox. If you are using vpa, you are using this toolbox.
When using MATLAB's lsqnonlin function, I am trying to give a user-defined Jacobian matrix, as described in the documentation.
The output of the objective function used in lsqnonlin should be a vector of unsquared values, which, when squared and summed, give the energy. However, should the Jacobian be the partial derivates of the squared or unsquared values?
The unsquared values is correct.