DOUBLE cannot convert the input expression into a double array?

7 visualizaciones (últimos 30 días)
Hi everybody,
I want to calculate a problem about Taylor series from a book but an error message occurred as follows:
Thank you from now.
The following error occurred converting from sym to double:
Error using symengine (line 59)
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.
Error in example_four3 (line 35)
sol(i+1) = sol(i+1) + (diff(f,(i+1))) * (h^(i+1)/factorial(i+1));
Here is my code:
clc;
clear;
anglout = radtodeg(pi);
true_value = cos(pi/3);
h = pi/3-pi/4;
n = 6;
syms x
f = cos(x);
sol(1) = cos(pi/4);
for i = 0:n
sol(i+1) = sol(i+1) + (diff(f,(i+1))) * (h^(i+1)/factorial(i+1));
sol(1) = sol(i);
end

Respuesta aceptada

Stephan
Stephan el 10 de Oct. de 2019
clc;
clear;
anglout = rad2deg(pi);
true_value = cos(pi/3);
h = pi/3-pi/4;
n = 6;
syms f(x) op(x)
f(x) = cos(x);
sol = zeros(1,7);
sol = cos(pi/4);
for i = 0:n
op(x) = (diff(f,x,(i+1)));
sol = double(sol + op(i+1) * (h^(i+1)/factorial(i+1)));
end

Más respuestas (0)

Categorías

Más información sobre Numbers and Precision en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by