syms but not int

1 visualización (últimos 30 días)
Florin Georgescu
Florin Georgescu el 18 de Dic. de 2016
Comentada: Muhadda Rehan Saleem el 26 de Mzo. de 2020
If I enter this command:
>> syms x, int(1/(x^2-1))
I get the correct answer:
ans = -atanh(x)
But if I enter this command:
>> int('1/(x^2-1)','x')
I get this error:
Undefined function 'int' for input arguments of type 'char'.
Why is that and how to fix it?
I am running MATLAB R2014a v8.3 with Symbolic Math Toolbox v6.0.
Thanks

Respuestas (2)

John BG
John BG el 19 de Dic. de 2016
Florin
You have the following options:
1.- upgrade to R2016a or R2016b problem solved, whatever you key in, as long as syntactically correct,
int(1/(x^2-1))
ans =
-atanh(x)
or
int(sym('1/(x^2-1)'),'x')
Warning: Support of strings that are not valid variable names or define a
number will be removed in a future release. To create symbolic expressions,
first create symbolic variables and then use operations on them.
> In sym>convertExpression (line 1536)
In sym>convertChar (line 1441)
In sym>tomupad (line 1198)
In sym (line 177)
ans =
-atanh(x)
int(sym('1/(x^2-1)'))
Warning: Support of strings that are not valid variable names or define a
number will be removed in a future release. To create symbolic expressions,
first create symbolic variables and then use operations on them.
> In sym>convertExpression (line 1536)
In sym>convertChar (line 1441)
In sym>tomupad (line 1198)
In sym (line 177)
ans =
-atanh(x)
What int command does not take in are strings without sym
int('1/(x^2-1)')
Undefined function 'int' for input arguments of type 'char'.
2.- Use command integral with discrete variables, computable vectors, like
clear x % if you leave x from previous sym x MATLAB holds to already defined syms variable
f=@(x) 1./(x.^2-1)
integral(f,0,10)
Warning: Reached the limit on the maximum number of intervals in use.
Approximate bound on error is 1.6e+00. The integral may not exist, or it
may be difficult to approximate numerically to the requested accuracy.
> In integralCalc/iterateScalarValued (line 372)
In integralCalc/vadapt (line 132)
In integralCalc (line 75)
In integral (line 88)
ans =
-0.586189361714442
the warning has to do with the vertical asymptotes on x=-1 and x=1.
integral(f,2,Inf)
without asymptotes along the integration line, then no warnings:
integral(f,2,Inf)
ans =
0.549306144334055
if you find my answer useful would you please mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help, please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
  2 comentarios
Walter Roberson
Walter Roberson el 19 de Dic. de 2016
Upgrade is not required. R2014a supported int() of symbolic expressions created with sym().
>> ver
----------------------------------------------------------------------------------------------------
MATLAB Version: 8.3.0.532 (R2014a)
MATLAB License Number: XXXXXXXXXX
Operating System: Mac OS X Version: 10.11.6 Build: 15G1212
Java Version: Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
----------------------------------------------------------------------------------------------------
MATLAB Version 8.3 (R2014a)
Simulink Version 8.3 (R2014a)
Communications System Toolbox Version 5.6 (R2014a)
Computer Vision System Toolbox Version 6.0 (R2014a)
Control System Toolbox Version 9.7 (R2014a)
Curve Fitting Toolbox Version 3.4.1 (R2014a)
DSP System Toolbox Version 8.6 (R2014a)
Global Optimization Toolbox Version 3.2.5 (R2014a)
Image Processing Toolbox Version 9.0 (R2014a)
MATLAB Coder Version 2.6 (R2014a)
Neural Network Toolbox Version 8.2 (R2014a)
Optimization Toolbox Version 7.0 (R2014a)
Parallel Computing Toolbox Version 6.4 (R2014a)
Phased Array System Toolbox Version 2.2 (R2014a)
Signal Processing Toolbox Version 6.21 (R2014a)
Simulink Coder Version 8.6 (R2014a)
Symbolic Math Toolbox Version 6.0 (R2014a)
>> int(sym('1/(x^2-1)'),'x')
ans =
-atanh(x)
Muhadda Rehan Saleem
Muhadda Rehan Saleem el 26 de Mzo. de 2020
Hellow John BG
I am try Matlab command int('f',0,pi/2), command is working but answer is in fractional form, I want to get answer in floating point form

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 18 de Dic. de 2016
int() applies to symbolic expressions. '1/(x^2-1)' is a string, not a symbolic expression.
Even if you go back as far as R14, you will not find any documentation suggesting that int() can be applied to a string.
What you can do is
int(sym('1/(x^2-1)'),'x')
This will produce a warning in recent versions but as of R2016b will still succeed.
  6 comentarios
Karan Gill
Karan Gill el 22 de Dic. de 2016
Florin, why are you using string input to "int"? It is not a documented input to "int".
Walter Roberson
Walter Roberson el 22 de Dic. de 2016
Using a string input to int() has not been documented in any version for which the documentation is still available in Mathworks' archives.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by