DOUBLE cannot convert the input expression into a double array?

7 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Stephan
Stephan am 10 Okt. 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

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by