필터 지우기
필터 지우기

Help creating an array to hold approx error from a taylor series

조회 수: 2 (최근 30일)
John Furman
John Furman 2020년 2월 7일
편집: James Tursa 2020년 2월 7일
I have a taylor series function for sin(x) and want to hold each value for approx error at each index value. Can anyone explain how I would go about doing this? Here is my while loop:
while index<100 && a_err>1
% while loop specifies that if the power of the taylor series is below 100 and the approximite
% error is greater than 1% the the program will loop through and create the
% next iteration of the taylor series
t = taylor(f,'Order',index, 'ExpansionPoint', xi)
% The taylor function is used to create the taylor series of increasing
% order
t_array(index) = vpa(subs(t,x,xi+h))
% An array is created to hold the values of each iteration of taylor
% series
if index>1
% The if statement keeps the program from stoping early since
% the aproximate error on the first iteration is not valid
a_err = abs((t_array(index)-vpa(subs(f,x,xi)))/vpa(subs(f,x,xi)))*100
% Calculates the approx. error
end
index = index+1
% Increase the index
end

답변 (1개)

James Tursa
James Tursa 2020년 2월 7일
편집: James Tursa 2020년 2월 7일
Generally, just index into your variable inside the loop:
a_values(index) = a_err;
If the indexing could be large, you would also consider pre-allocating the a_values variable.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by