1
$\begingroup$

CS Beta people:

I have been doing some multiple integrals with a combination of symbolic and numerical integration (because symbolic answers have not always been possible). I have been using Mathematica to do the symbolic integration, cut-and-pasting the results into Matlab, and then using quad or dblquad in Matlab. I could probably do the whole thing in Mathematica, but I would like to develop my Matlab skills. My question is, is there a convenient way to use Matlab's symbolic capabilities to do this more efficiently, without cut-and-pasting?

The only symbolic engine I have access to in Matlab is mupad (I don't have the Maple Toolbox, for example). I would consult the Mathworks documentation, but I have found it deficient on several other questions, and I would like to hear from someone who has actually done it.

EDIT (March 5): Someone asked me to be more specific. Here is part of what I'm doing. I want to evaluate the triple integral

$$\int_1^{RmaxOverRmin} \int_1^{r_2}\int_0^{r_2-r_1}\frac{r_1^3 t^2}{r_2^3}\exp(-\frac{t^2}{4 dOverRmin^2})\,dt\,dr_1\,dr_2.$$

Mathematica can't do it symbolically, so it is probably impossible. Mathematica can do the inner double integral symbolically. So I did it, cut-and-pasted the results into a Matlab function file, and used Matlab's "quad" to integrate the result as $r_2$ went from $1$ to $RmaxOverRmin$.

Stefan (STack Exchange FAN)

$\endgroup$
4
  • 1
    $\begingroup$ Yes, I've done this sort of thing exactly. Your problem is still a bit too general, if you'd like a specific answer (instead of a comment), could you post a more specific problem, giving the details of the numerical integration you are trying to do? $\endgroup$ Commented Mar 5, 2013 at 0:58
  • 2
    $\begingroup$ In my experience if you need to do anything symbolic, you're best off sticking with Mathematica. Matlab can probably do it, but it is atrocious. $\endgroup$
    – Victor Liu
    Commented Mar 5, 2013 at 6:29
  • $\begingroup$ If you are not tied to Matlab, you could check out the combination of NumPy/SciPy and SymPy. $\endgroup$ Commented Mar 5, 2013 at 9:49
  • $\begingroup$ @Aron : I added to my question. $\endgroup$ Commented Mar 5, 2013 at 16:25

1 Answer 1

1
$\begingroup$

The easiest way would probably be to use mEngine. I have not worked with it, but I am pretty sure it will be a breeze to install and use. Not sure exactly how the expressions will be transferred though.

Otherwise you could just write the expressions into text files. Then you can run f=sym(somestring); to have MATLAB parse it into a symbolic object. Then just substitute using subs().

Edit : Check this answer.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.