I've written an algorithm in MATLAB which has to be real time (by real time I mean anything less than 1 s is perfect for my purpose and less than 10 s is still acceptably good). My algorithm contains a for loop which at each iteration it has to compute a certain number of areas. Each of these areas are computed using the following formula: \begin{equation} A = \int_0^1\int_0^1 \sqrt{\det (g)}\ d u\ d v \end{equation} where $g$ is a $2\times 2$ matrix with polynomial entries (either linear or quadratic in variables $u$ and $v$). I already have managed to do that in Matlab in two ways as I explain below but both are very slow plus the fact that one of them has one additional problem in some special cases. In the first attempt I wrote the following:
syms u v real
volume = sqrt(det(g));
area(i) = int(int(volume, u,0,1),v,0,1); # area of the i-th ruled surface
in this case the area is computed but its extremely slow. The other way that I thought solving it was to do the following:
syms u v real
volume = sqrt(det(g));
h = matlabFunction(volume);
area(i) = integral2(h,0,1,0,1);
This method makes it a bit faster (but noway close to being fast enough). It also has one additional problem, in some rare cases when computing the determinant of $g$, the polynomial obtained is univariate (depends on either $u$ or $v$) and when I use the matlabFunction command it only assigns one variable to it (@(u) or @(v)) which makes problems in the next line (as integral2 doesn't recognize the other variable which is undefined by the matlabFunction). So my Questions are:
- Is there a faster numerical-way to compute these integrals (or does Matlab have some special functions for a similar purpose)? regarding the accuracy, it is ok if its accurate up to 3 or 4 digits.
- How can I force
matlabFunctioncommand to introduce the other variable in the case wheredet(induced_metric)is a univariate polynomial.
Thank you in advance,
Here I add the extra information regarding the ruled surfaces that I want to compute the area of. Each of these are 2-dimensional surfaces originally in $\mathbb{R}^6$ associated with a metric $g^\prime$. Lets say each one of them is an enclosed area by the points $A$, $B$, $P$ and $Q$. Then I have the following parametrization for each of them: \begin{equation} X:\ (u,v) \longrightarrow \left( \begin {array}{c} \left( \left( a_{{1}}-b_{{1}}-p_{{1}}+q_{{ 1}} \right) v+p_{{1}}-a_{{1}} \right) u+ \left( -a_{{1}}+b_{{1}} \right) v+a_{{1}}\\ \left( \left( a_{{2}}-b_{{2}} -p_{{2}}+q_{{2}} \right) v+p_{{2}}-a_{{2}} \right) u+ \left( -a_{{2}}+ b_{{2}} \right) v+a_{{2}}\\ \left( \left( a_{{3}}- b_{{3}}-p_{{3}}+q_{{3}} \right) v+p_{{3}}-a_{{3}} \right) u+ \left( -a _{{3}}+b_{{3}} \right) v+a_{{3}}\\ \left( \left( a _{{4}}-b_{{4}}-p_{{4}}+q_{{4}} \right) v+p_{{4}}-a_{{4}} \right) u+ \left( -a_{{4}}+b_{{4}} \right) v+a_{{4}}\\ \left( \left( a_{{5}}-b_{{5}}-p_{{5}}+q_{{5}} \right) v+p_{{5}}-a_{{ 5}} \right) u+ \left( -a_{{5}}+b_{{5}} \right) v+a_{{5}} \\ \left( \left( a_{{6}}-b_{{6}}-p_{{6}}+q_{{6}} \right) v+p_{{6}}-a_{{6}} \right) u+ \left( -a_{{6}}+b_{{6}} \right) v+a_{{6}}\end {array} \right) \end{equation} Then in order to compute the area of the surface I have to obtain the induced metric on it, which earlier I named it $g$, I obtained it by computing $\frac{\partial X}{\partial u}$ and $\frac{\partial X}{\partial v}$, and then \begin{eqnarray} g_{1,1} = \langle\frac{\partial X}{\partial u}, \frac{\partial X}{\partial u} \rangle ,\\ g_{1,2} = g_{2,1} = \langle\frac{\partial X}{\partial u}, \frac{\partial X}{\partial v} \rangle ,\\ g_{2,2} = \langle\frac{\partial X}{\partial v}, \frac{\partial X}{\partial v} \rangle . \end{eqnarray} where $\langle - , - \rangle$ is the scalar product computed with respect to the metric $g^\prime$ (which is symmetric and positive-definite).