Here is a bit of Matlab code that adds two 2-Dimensional vectors together by get
ID: 3939938 • Letter: H
Question
Here is a bit of Matlab code that adds two 2-Dimensional vectors together by getting the components and summing the components. Use the blank lines to create a loop using this code, so that any number of vectors can be added, as the code user desires. %These first two line merely initialize X and Y so that no "old" values contaminate the calculations, and % so that X and Y can be used in calculations. They do not need to be in the loop. X = 0; Y = 0; %Loop the following segment, using whatever type of loop you like and can make work. You are not required to use all of these lines, if you do not need them. X_new = input('What is the x-component of the next vector?'); Y_new = input('What is the y-component of the next vector?'); X = x + X_new; Y = y + Y_new; % The following does output, and does not need to be in the loop fprintf('The sum of all of these vectors is %5.4f units horizontally and %5.4f units vertically. ', X, Y)Explanation / Answer
Answer
prompt = "Enter the number of times you want this section to run::";
loop_num = input(prompt);
for i = 1:loop_num
%%body of loop where the sum of the vectors is calculated
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.