Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a funn ion called aeries to do E 1 2\" functi go trom and The ingut argume

ID: 3822220 • Letter: W

Question


write a funn ion called aeries to do E 1 2" functi go trom and The ingut argument infinity will be the 1 ion will be the value for n and the vector of that was ohould be di aplayed fron within the tunet. ample will return 5, awam- 1.0 1.5.1-75.3 s.1.ga1s 1/1 2/2 1/4 1/8 1/1G Hint: uue a while loop write a script that will call the function. series for the and diaplay only the four returned BUNS 1.9. 1.99 1.999 1.9999 Use a for series Do not display the n'a Write a script that will take the veetor Name from the first page a diaplay it written backwarda Example Nane Mohamed Display der

Explanation / Answer


% QUESTION-1
function [n vect] = series(req_value)
    n = 0;
    vect = []
    current_val = 0;

    while (current_val < req_value)
        current_val = current_val + (1/2^n);  
        vect = [vect current_val];      
        n = n + 1;
    end
end

[n vector] = series(1.99);
fprintf(" Value of n is %d Vector is ", n);
disp(vector);


% QUESTION-2
SUMS = [1.9 1.99 1.999 1.9999];
for i=1:length(SUMS)
    fprintf("Values for %f ", SUMS(i));
    [n vector] = series(SUMS(i));
    fprintf(" Value of n is %d Vector is ", n);
    disp(vector);
end

%QUESTION-3 is not visible properly