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
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!