DOUBLE cannot convert the input expression into a double array?

2 次查看(过去 30 天)
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

采纳的回答

Stephan
Stephan 2019-10-10
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by