Create a function to calculate error, approximation, exact, etc.

10 visualizaciones (últimos 30 días)
amateurintraining
amateurintraining el 13 de Oct. de 2017
Respondida: Prashant Arora el 16 de Oct. de 2017
How do you create a function to calculate:
I have attempted to do so but keep getting errors:
exact=exp_or_sin(x+dx);
abs_error=0;
n=1;
count=0;
terms=1;
while abs_error<=tol && n>1 && terms>max_terms
count=count+1;
terms(count)=(1)^(count+1)*(dx^n).*diff(exp_or_sin,x,n)/factorial(n);
approx(count)=exp_or_sin+sum(terms);
n=n+1;
abs_error=abs((exact-approx)/exact);
end
disp(exact)
disp(approx)
disp(abs_error)
X=terms
X(:)=1;
terms=sum(X)
I am debating starting from scratch.

Respuestas (1)

Prashant Arora
Prashant Arora el 16 de Oct. de 2017
Hi,
You can refer to the "taylor" function in Symbolic Math Toolbox.
Hope this helps!
Prashant

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by