Borrar filtros
Borrar filtros

Taylor Series on numbers

3 visualizaciones (últimos 30 días)
mathango
mathango el 27 de En. de 2016
Comentada: mathango el 27 de En. de 2016
Hi,
I know that I can perform series expansion of the function let say sin(x) by writing a following script commands:
syms x a
F = a*sin(x)
taylor(F,x,6);
The output is a nice series expansion of sin(x) up to 5th term. However, when I have a number such as F=1 , the taylor gives the error message and fails to give a correct answer which is 1. Is there a way to work around it? Is there a way to verify if F contains variable x or not so that taylor can be avoided when F does not have x variable. Thanks.

Respuesta aceptada

John D'Errico
John D'Errico el 27 de En. de 2016
Editada: John D'Errico el 27 de En. de 2016
Works fine for me.
syms x
F = sym(1);
taylor(F,x,5)
ans =
1
What you misunderstand is that taylor does not apply to a double variable. However, it works fine for a symbolic constant.
As for how to tell the difference, here is a thought:
isnumeric(F)
ans =
0
G = 1;
isnumeric(G)
ans =
1
Alternatively, you could use a try/catch construct to detect if there was a problem.
  1 comentario
mathango
mathango el 27 de En. de 2016
Hi John,
Thanks for the answer. The second string of code (isnumeric) works. However, the first string of code with sym(1) method does not work. I think it is due to the fact that I am using old version matlab 6.5 Looks like I have to use the second method and try/catch to get around that limitation. Again, thanks.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by