Gistlib Logo

gistlib

create a while loop when y=summation(((-1)^n)/(1+3^n))) and add in terms until the difference between consecutive terms in 10^-6 in matlab

main.m
n = 0;
y = 0;
term = 1;

while abs(term) > 1e-6
    term = (-1)^n / (1 + 3^n);
    y = y + term;
    n = n + 1;
end

y
119 chars
12 lines

similar matlab code snippets

how to calculate the volume of a sphere in matlab
how to calculate the area of a ellipse in matlab
how to calculate the secant of an angle in degrees in matlab
how to calculate the volume of a prism in matlab
how to calculate the first derivative of a function in matlab
how to calculate the arccosine of an angle in matlab
find the roots of a polynomial in matlab
how to calculate the arccosine of an angle in degrees in matlab
how to calculate the area of a triangle in matlab
find the slope of a set of points in matlab

related categories

matlab
mathematics

gistlibby LogSnag