How to find value of an infinite series using for-end loops
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
Walter Roberson
on 28 Mar 2016
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.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!