Info

This question is closed. Reopen it to edit or answer.

Index Exceeds Matrix Dimension/Subscript Indices Must Be Real Positive

1 view (last 30 days)
This is the code I've got so far:
alpha = input('Please enter a value for alpha: ');
tsubo = input('Please enter a value for tsubo: ');
a = 1; b = cos(alpha); c = sin(alpha);
n = [1:N]
N = 10;
a(n) = (1/2)*(a(n-1) + b(n-1));
b(n) = sqrt(a(n-1)*b(n-1));
c(n) = (1/2)*(a(n-1)-b(n-1));
while abs(c(N)) < tsubo
K(alpha) = pi/(2*a(N))
N = N+1
end
format LONGE;
Elliptic = ellipke((sin(alpha))^2);
disp(['Thus, the process produces the value of ' num2str(K(alpha)) ' which is the same result of ellipke(sin^2(alpha)) of ' num2str(Elliptic) '. '])
Basically, the program I'm trying to write needs to show that one version of the arithmetic-geometric mean produces the same result as ellipke(sin^2(alpha))
Similarly, I need to write an equation determining the value of convergent series, and I'm getting the same index errors.... this is what I have so far:
n = [1:5:200];
x = 0;
x(n) = x(n)^2 + 0.25
Any help is great.
  1 Comment
dpb
dpb on 8 Oct 2013
n = [1:N]
N = 10;
a(n) = (1/2)*(a(n-1) + b(n-1));
a) You've tried to use N before it is defined,
b) if n=1, what's (n-1)?
You're going to need the "dot" operators in places --
doc times % and friends for details of point-by-point operations

Answers (0)

Community Treasure Hunt

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

Start Hunting!