A flag to indicate whether or not the int function has successfully computed a symbolic integral

3 visualizzazioni (ultimi 30 giorni)
The example below indicates my problem. In the first case, matlab cannot integrate the function provided to it and simply returns the computation I asked it to evaluate. In the second case, matlab is successful and returns a symbolic expression. The output argument of both `int` computations is of class `sym`, but, obviously, one is useful while the other is not. I could, of course, distinguish between them by searching for the string `int` in `char(Ans)` but that's a pretty inelegant thing to do.
Thanks!
f = @(x)((x+10)*exp(-x)/(sqrt(x*x+20*x)));
int(f,x,0,1);
Ans= int((exp(-x)*(x + 10))/(x^2 + 20*x)^(1/2), x, 0, 1)
class(Ans)
syms b
Ans = int(x^2,x,0,b)
class(Ans)

Risposta accettata

John D'Errico
John D'Errico il 7 Ott 2016
It appears your only alternative is to inspect the result, as int returns only one argument, with no flag indicating "success" at all. If that result contains the sub-string 'int', then you have not been successful.
  2 Commenti
Leo Simon
Leo Simon il 7 Ott 2016
That's what I've been doing, but it's clearly not bulletproof, since the variable itself could contain the substring int.
John D'Errico
John D'Errico il 7 Ott 2016
You could search for 'int('. That will resolve some problems. Of course, anything that starts with the string 'int(' as the first 4 characters will be clear, but that will miss many cases.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by