How do I calculate an infinite series using a function file with for-end loops?
Show older comments
Given f(x)= [(x^2)/37]+[(x^3)/3!]+[(x^4)/4!]+[(x^5)/5!]+...
Using a function file (function fn=my_fun(x,n)) with for-end loops for several test files.
I'm just having issues defining the function file using the for-end loop. What I have so far is:
function [xval,nterms]=my_series(x,n)
3 Comments
Youssef Khmou
on 3 Mar 2013
hi is the code below fine? i mean your input is : vector X and order N , so as for every point in X we sum N terms defined with general formula .
Walter Roberson
on 3 Mar 2013
Could you confirm that the first term is divided by 37, and not factorial(2) as would match the 3! 4! 5! pattern?
Youssef Khmou
on 3 Mar 2013
that is matter of Initial conditions
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 3 Mar 2013
x=2
n=5
f=x^2/37+sum(arrayfun(@(n) x^n/factorial(n),3:n))
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!