Here is a bit of Matlab code that adds two 2Dimentional vect

Here is a bit of Matlab code that adds two 2-Dimentional 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 designs. %These first two lines 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 whether 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)

Solution

% Program to sum vector components

X = 0;
Y = 0;
i = 0;
vectorCount = input(\" Enter number of vectors ::\\t\"); % Code user input
while (i<vectorCount) % lopping till the number of vector input
x_new = input(\" What is the x-comopnent of next vector ?\\t\");
y_new = input (\" What is the y-comopnent of next vector ?\\t\");
X = X + x_new;
Y = Y + y_new;
i = i+1;
end
fprintf(\" The sum of all these vectors is %5.4f units horizontally and %5.4f units vertially \ \", X,Y);

 Here is a bit of Matlab code that adds two 2-Dimentional vectors together by getting the components and summing the components. Use the blank lines to create a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site