User defined Jacobian in MATLAB's lsqnonlin - matlab

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.

Related

scipy's default "epsilon" when calculating the Jacobian

Does anyone know what criteria is used to decide the value of "epsilon" for each parameter in the calculation of the Jacobian matrix in scipy? I am using scipy.curve_fit where I get the covariance matrix, but I need to do this fit in matlab as well where I have to manually calculate the Jacobian and convert to covariance matrix. I have not been able to find the criteria by which scipy decides on the default shift in parameter (i.e. epsilon) used to determine the function gradient

How can I calculate int(exp(sin(x)),x) in MATLAB

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.

Can I get Jacobian from fminsearch

I wonder if there is an easy way to get Jacobian out from fminsearch in Matlab ? like in
[OptimizedParamters,residualsNorm,residual,exitflag,output,lambda,jacobian] =
lsqnonlin(#function,
intialparamtersguess,lb,ub,options);
I've tried
options = optimset('MaxFunEvals',100,'Jacobian','on');
[x,fval,exitflag,output] = fminsearch(fun,x0,options)
but there is no Jacobin in the output
any ideas please
fminsearch performs gradient free optimization, i.e. this function never computes a Jacobian. Thus, it cannot return it.
To get a Jacobian you could try numerical or symbolic differentiation.

Variable precision arithmetic for definite integrals in Matlab

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.

MATLAB: Plot integral using quad/quadl

I would like to know if anybody knows how I can plot an integral calculated using quad/quadl, or if this is possible.
I read that I can set the trace parameter to be non-zero, and this results in the information of each iteration being provided, but I'm not sure how and if I can use the information to plot an integral.
Thanks.
quad and quadl do not compute an integral function anyway, i.e., an integral as a function of the parameter. And since tools like this work iteratively, refining their estimate until it satisfies a tolerance on the global value, they are not easily made to produce the plot you desire.
You can do what you desire by using a differential equation solver to generate the solution, ode45 for example.