How do I calculate an infinite series using a function file with for-end loops?
이전 댓글 표시
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
Youssef Khmou
2013년 3월 3일
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
2013년 3월 3일
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
2013년 3월 3일
that is matter of Initial conditions
채택된 답변
추가 답변 (1개)
Azzi Abdelmalek
2013년 3월 3일
x=2
n=5
f=x^2/37+sum(arrayfun(@(n) x^n/factorial(n),3:n))
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!