Hypergeometric function in Scipy giving incorrect infinities - scipy

The current hypergeometric function hyp2f1 in scipy.special cannot handle instances where the third argument is negative and the fourth argument is complex. The MATLAB counterpart seems to handle these instances without problems. Is this a bug in the scipy function?

This might be a bug indeed.
As a work around you could use mpmath:
>>> import mpmath as mp
>>> complex(mp.hyp2f1(-2,-3,-19,3.4+0.4j))
(0.12631578947368421-0.07859649122807018j)
which also allows other functions to have complex arguments - unlike in the current scipy implementation (e.g. hyperu or numerical integration of complex-valued functions using quad).

Related

Does Octave have a ScaleProblem equivalent for fmincon?

I'm in the process of porting a large set of MATLAB scripts to Octave. Some of the scripts use the MATLAB Optimization toolbox, specifically the fmincon function. In the optim package in Octave, the fmincon function exists but has different parameters. Is there a way to replicate the ScaleProblem parameter in Octave's fmincon?
In my Octave script, I use optimset:
options = optimset('fmincon','Algorithm','sqp','ScaleProblem','obj-and-constr', ...);
Which causes the following warning:
warning: optimset: unrecognized option: ScaleProblem
Is there a workaround for this?
Apart from the trivial advise to write a wrapper that looks for this parameter-value pair, scales the matrices & calls fmincon without the ScaleProblem option, I can only emphasize to use the NLopt-toolbox from the MIT: https://nlopt.readthedocs.io/en/latest/ it got far more optimization algorithms with a neat matlab/octave interface, all open-source, and -- to my experience -- often more accurate and faster indeed =)

What is actually symbolic variable in matlab?

I am new in learning matlab. when I am using the solve() function, matlab warning me that i must use a symbolic variable before using the solve function. but I actually don't know what the sym variable is. or What is the difference between the symbolic variables and the ordinary variables of the base workspace?
Symbolic variables are useful to express equations and manipulate them in an analytic manner. You can use them to manipulte them algebrically, without the need of actually associating any type of numbers.
Suppose you want the exact analytical form of a solution for an equation, in terms of symbols that express this function. Then you can use a sym variable to express and operate with the unkwons, rather than to use on numerical methods to find solutions
Symbolic variables are also useful to operate with tranfer funcions and perform simplications that are very tedious If done without a computer program.
You also can associate numbers with sym variables, once you have done all the all the intended operations.
If you don't want perform operations with algebraic variables, you should checkout the fsolve function

Computation of Confluent Hypergeometric Function of the First Kind in Matlab

Is there a way to perform a computation of the confluent yypergeometric function of the first kind in Matlab (specifically in R2013a)?
In Mathematica, this function is called Hypergeometric1F1. I've seen kummerU in Matlab, but the definitions look different.
In Mathematica, the definition is:
While in Matlab, the definition is given as:
How do I calculate confluent hypergeometric function of the first kind, i.e., the first of the two integrals, in Matlab?
The two are different because they return different solutions to the same second order ODE, but the names can make them easy to confuse. Mathematica's Hypergeometric1F1 calculates the confluent hypergeometric function, also known as Kummer's function. Matlab's kummeru calculates the confluent hypergeometric Kummer U function, also known as Tricomi's confluent hypergeometric function. The two are related by a simple relation, as shown here (see also the relations here and here).
In Matlab, you can calculate the confluent hypergeometric function symbolically via the general hypergeom function (a numeric solution is returned if all of the input arguments are floating point):
A = hypergeom(a,b,z);
This will return a result equivalent to that from Mathematica's Hypergeometric1F1. If you need faster solutions, you can try my optimized hypergeomq described in this Math.SE answer. For a purely numeric solution, you could also try this File Exchange submission
In Mathematica, you can use HypergeometricU to produce a result equivalent to Matlab's kummeru.

Why is Matlab function interpn being modified?

The Matlab function interpn does n-grid interpolation. According to the documentation page:
In a future release, interpn will not accept mixed combinations of row and column vectors for the sample and query grids.
This page provides a bit more information but is still kind of cryptic.
My question is this: Why is this modification being implemented? In particular, are there any pitfalls to using interpn?
I am writing a program in fortran that is supposed to produce similar results to a Matlab program that uses interpn as a crucial component. I'm wondering if the Matlab program might have a problem that is related to this modification.
No, I don't think this indicates that there is any sort of problem with using interpn, or any of the other MATLAB interpolation functions.
Over the last few releases MathWorks has been introducing some new/better functionality for interpolation (for example the griddedInterpolant, scatteredInterpolant and delaunayTriangulation classes). This has been going on in small steps since R2009a, when they replaced the underlying QHULL libraries for computational geometry with CGAL.
It seems likely to me that interpn has for a long time supported an unusual form of input arguments (i.e. mixed row and column vectors to define the sample grid) that is probably a bit confusing for people, hardly ever used, and a bit of a pain for MathWorks to support. So as they move forward with the newer functionality, they're just taking the opportunity to simplify some of the syntaxes supported: it doesn't mean that there is any problem with interpn.

Converting Matlab anonymous functions to Scilab inline functions

Most of my Matlab functions can be converted with the mfile2sci function to Scilab functions except some functions that contain anonymous functions (for example f=#(x,y)sin(x)+log(y)). Is there a way to convert the anonymous functions to Scilab inline functions (for example, for the previous example deff('[z]=f(x,y)','z=sin(x)+log(y)')) so that I don't have to change my Matlab functions?
Yes, in its current state the Matlab to Scilab translator mfile2sci fails to translate anonymous functions, but this behavior can be improved by the following patch:
https://codereview.scilab.org/#/c/20916/
However, be warned that anonymous function occur most of the time when using "solvers" like fsolve, optim, ode solvers (e.g. ode45, ode15s,...), and that statements using these are never translated to working Scilab statements (a warning is given).