% Write a program to solve t aylor series expan sion from zero to third % order
ID: 3550306 • Letter: #
Question
% Write a program to solve taylor series expansion from zero to third
% order to predict f(3) for: f(x)= 25x^3+ 6x^2 - 7x-88
% Display results in array
x= 1;
z= 3;
h= z-x;
n(1)= 1;
f_n(1)= 25* x^(3)- 6*x^(2)+7*x- 88;
f_n(2)= 75* x^(2)- 12*x^(1)+7;
f_n(3)= 150*x-12;
f_n(4)= 150;
exact = 25*3^(3)-6*3^(2)+7*3-88;
array=0;
for i=1:4
Taylor=(f_n(i)/ factorial(i-1))*(h^(i-1));
n(i+1)= Taylor + n(i);
error= ((exact- n(i+1))/ (exact))*100;
approx= abs((n(i+1)-n(i))/n(i+1))* 100 ;
end
L=[f_n() n(i+1) error];
fprintf (' Function Value Exact Value True Percent Error ');
fprintf (' %4.0f %4.0f %4.0f n',L);
disp (approx)
Problem: not all the results are displaying, please help.
% Write a program to solve series expansion from zero to thirdExplanation / Answer
% Write a program to solve taylor series expansion from zero to third
% order to predict f(3) for: f(x)= 25x^3+ 6x^2 - 7x-88
% Display results in array
clear all
close all
clc
x=1;
z= 3;
h= z-x;
n(1)= 1;
f_n(1)= 25* x^(3)- 6*x^(2)+7*x- 88;
f_n(2)= 75* x^(2)- 12*x^(1)+7;
f_n(3)= 150*x-12;
f_n(4)= 150;
exact = 25*3^(3)-6*3^(2)+7*3-88;
array=0;
for i=1:4
Taylor=(f_n(i)/ factorial(i-1))*(h^(i-1));
n(i+1)= Taylor + n(i);
error= ((exact- n(i+1))/ (exact))*100;
approx= abs((n(i+1)-n(i))/n(i+1))* 100 ;
end
%L=[f_n() n(i+1) error];
fprintf (' Function Value Exact Value True Percent Error approx ');
fprintf (' %8.3f %8.3f %8.3f %8.3f ',exact,n(i+1),error,approx);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.