Advertisement
ForeverStrong

Wypok_Task_One

May 1st, 2020
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.75 KB | None | 0 0
  1. function output_sum = task_one(start_element_value, end_element_index, constant)
  2. %% HOW TO
  3. %     start_element_value - first a element
  4. %     end_element_index - n (how many values of elements we should calculate)
  5. %     constans - m constans added to each elemect according to formula:
  6. %     a(n)=a(n-1)+m
  7. %     output - vector with calculeted elements
  8. %     element - current callculeted element
  9. %% MAIN CODE
  10.     output(1,1) = start_element_value ;
  11.     element =  output(1,1); % Initialization of a1
  12.     for step=2:1:end_element_index % calculations starts for a2 element
  13.         element = element + constant; % a(n) = a(n-1) + m
  14.         output(1, step) = element; % append calculated value on an index
  15.     end
  16.     output_sum = sum(output);
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement