필터 지우기
필터 지우기

How to find value of an infinite series using for-end loops

조회 수: 1 (최근 30일)
Vinny
Vinny 2016년 3월 28일
답변: Walter Roberson 2016년 3월 28일
Write a program to determine values from the following infinite series.
f(x)=sqrt(x)/42+1/2x+1/3x^2+1/4x^3+1/5x^4+1/6x^5......
There are two inputs, the value of (x), and the number of terms to use in the series (n),
and there is one output, the value of the function.
Using x=0.932 and n=7 as your inputs, find the value of this function.
I've tried working the problem but I can only get the value for the first 2 values. Here is what I have so far:
x=0.932
n=7
exp1=sqrt(x)/42
exp2=x^(n-1)/n
for i=exp1:1:n
op=exp1+exp2
end
Any help is appreciated with this problem. Thank you.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 3월 28일
Correcting only one of the problems with your code:
exp2 = @(x,n) x^(n-1)/n;
for i = exp1:1:n
op = exp1 + exp2(x,n)
end
That is, you wrote exp2 as if you expected to be giving a formula, so show here how to really make it a formula.
I can see at least three remaining bugs in the code, so do not expect the above to work directly: it is an illustration of a technique and you now need to fix your code, possibly making use of this technique.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by