Help creating an array to hold approx error from a taylor series
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
James Tursa
am 7 Feb. 2020
Bearbeitet: James Tursa
am 7 Feb. 2020
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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!