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

MATLAB 3D Resultant Vector Calculator Note: You may upload the code we worked on

ID: 2088720 • Letter: M

Question

MATLAB 3D Resultant Vector Calculator Note: You may upload the code we worked on in class or create your own code Create a MATLAB script that 1) formation Prompts the user to enter the name of an Excel spreadsheet containing vector in for a system of vectors that can have anywhere from 2 vectors to an infinite number of vectors 2) Imports the data from the Excel spreadsheet and save the data as a variable(s) a. The first column of the spreadsheet contains the x coordinate of a vector b. The second column of the spreadsheet contains the y coordinate of a vector c. The third column of the spreadsheet contains the z coordinate of a vector Computes the x, y and z components of the resultant force (the sum of all the vectors) 3) 4) Plots the system of vectors, and the resultant vector 5) Displays the x, y and z components of the resultant vector in the Command Window, in sentence form, back to the user. 6) Comment every line of code you write/wrote to explain what each command does

Explanation / Answer

% This vector file should be in the same folder where the matlab file is present

% Create an excel file with 2-dimensional or 3-dimensional vectors
% The vectors can be in any number ( 1 to infinite)
% The resultant will be in red color

clc
clear
close all

% Question 1: To take excel file as input
file_name = input('Please enter the file name - ','s');

% Question 2: To input the excel sheet data into variable
a=[];   % variable to store data in excel sheet
a=xlsread(file_name); % import the data

%Question 3: resultant of vectors
x_resultant = sum(a(:,1)); % X - resultant of vectors
y_resultant = sum(a(:,2)); % Y - resultant of vectors
z_resultant = sum(a(:,3)); % Z - resultant of vectors

%Question 4:
plot3(a(:,1),a(:,2),a(:,3)); % plotting the given vectors
hold on
line([0 x_resultant],[0 y_resultant],[0 z_resultant],'color','r'); % plotting the resultant

%Question 5:
fprintf('x resultant is %.1f, y_resultant is %.1f, z_resultant is %.1f',x_resultant,y_resultant,z_resultant);

_______________________________________________________________________________________________