homework help with a statics programing question?
1 次查看(过去 30 天)
显示 更早的评论
The script needs to
- accepts any number (determined by the program user at run-time) of user-input 2-D force vectors (in component form, with x-, y- magnitudes AND force application point);
- You might ask the user how many vectors will be input (which is easier to code), or
- You can use a signaling mechanism - for example, ask the user whether there are more vectors to input, and continue if there is an affirmative response (which is more interesting and/or user-friendly).
- accepts the x, y coordinates of a reference point within the defined square space;
- calculates the equivalent force/couple system at the reference point, due to the applied forces at the true application points
test case:
Force one: (25, 25) pounds at location (10, 5)
Force two: (-40, 5) pounds at location (4, 7)
Force three: (20, -10) pounds at location (3, 2)
Reference point: (5, 5)
The script will be graded for
- Adherence to directions;
- User-friendliness of input and output;
- Use of Matlab output functions “disp” and “fprintf” to make the output well-understandable by the script user, and
- Clear, correct and understandable input statement prompts, and
- Suppression of all unnecessary output values and
- Adequate responses so that the user understands what user actions have been incorrectly done
- Correctness of the result when I run it for my own separate test case;
- Good programming practice, including proper documentation of the completed m-file
- Good practice includes use of whitespace to make the code readable, and
- Documentation includes sufficient comment statements to
- allow a human reader to understand well the intent and method of the script and
- allow me to know who wrote it and when, and what the variable names represent
the script is:
n_vectors = input("How many vectors would you like to input? "); %Initial inputs
referencex = input("What is the x-value of the reference point? ");
referencey = input("What is the y-value of the reference point? ");
sum_Fx = 0; %Defining variables that will be used later
sum_Fy = 0;
moment = 0;
for total = 1:n_vectors %For loop makes the program ask for the desired number of vectors
xi = input("What is the horizontal component of the vector? ");%Inputs for the Forces, one at a time
yj = input("What is the vertical component of the vector? ");
x = input("What is the x-value of the application point? ");
y = input("What is the y-value of the application point? ");
rx = x - referencex; %Finds the relative position of the vector to the reference point
ry = y - referencey;
sum_Fx = sum_Fx + xi; %Sums each vector and moment together as the loop continues
sum_Fy = sum_Fy + yj;
moment = moment + xi*ry - yj*ry;
end
fprintf("The sum of the forces is %.2f i and %.2f j",sum_Fx,sum_Fy) %Display statements for the desired information
fprintf("The moment about the reference point is: %.2f k",moment)
For some reason I am geting the result of: 180
I should be getting a result of: 280
Can you help?
1 个评论
Dave B
2021-10-13
just a guess, but you didn't use rx for anything...did you mean:
moment = moment + xi*rx - yj*ry;
采纳的回答
Image Analyst
2021-10-13
Which variable is taking on the value of 180?
Double the number of comments.
Add
fprintf('Written by Michail Popovits on Octover 12, 2021.\n');
to the end of the program.
For user Friendliness, use inputdlg() instead of input(). Here's a snippet you can adapt from 2 inputs to 3 or 4 inputs:
% Ask user for two floating point numbers.
defaultValue = {'45.67', '78.91'};
titleBar = 'Enter values';
userPrompt = {'Enter floating point number 1 : ', 'Enter floating point number 2: '};
caUserInput = inputdlg(userPrompt, titleBar, 1, defaultValue);
if isempty(caUserInput),return,end % Bail out if they clicked Cancel.
% Convert to floating point from string.
usersValue1 = str2double(caUserInput{1})
usersValue2 = str2double(caUserInput{2})
% Check usersValue1 for validity.
if isnan(usersValue1)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue1.
usersValue1 = str2double(defaultValue{1});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue1);
uiwait(warndlg(message));
end
% Do the same for usersValue2
% Check usersValue2 for validity.
if isnan(usersValue2)
% They didn't enter a number.
% They clicked Cancel, or entered a character, symbols, or something else not allowed.
% Convert the default from a string and stick that into usersValue2.
usersValue2 = str2double(defaultValue{2});
message = sprintf('I said it had to be a number.\nTry replacing the user.\nI will use %.2f and continue.', usersValue2);
uiwait(warndlg(message));
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!