How can i make my code interactive?

6 views (last 30 days)
Amanda Michel
Amanda Michel on 15 Apr 2019
Answered: Rik on 15 Apr 2019
I want to let people choose Forces and Angles then it will give them the answer of a total force.
For my first section i am already given 3 angles and 3 forces where i find the total force and result angle.
I started to use 'Force1= input('Enter force');
for all forces and angles then put end at the end of that but when i run it it just keeps going on. Then i put the equations underneath that for the total force and result angle but it doesnt run.
  2 Comments
Rik
Rik on 15 Apr 2019
Show the code you're using. The input function is indeed the function you should be using (unless you want to make a GUI).
Amanda Michel
Amanda Michel on 15 Apr 2019
%% 1st section
Force = [100, 200, 50];
theta = [-90, 90, 30];
% angle to radians
theta = theta.*pi/180;
%sum and components of X
ForceX = Force.*cos(theta);
XFORCEtotal = sum(ForceX);
%sum and components of Y
YFORCEtotal = sum(Force.*sin(theta));
%result angle (radians)
resultangle = atan(YFORCEtotal./XFORCEtotal);
%convert to degrees
resultangleDEGREE = resultangle.*180/pi
TOTALFORCE = XFORCEtotal./cos(resultangle)
%mesh
[XForce, Ytheta] = meshgrid (Force, theta);
Z = peaks(XForce, Ytheta);
surf (XForce, Ytheta, Z)
%% 2nd section interactive
valid = 0
while valid == 0
Force1 = input('Enter 1st Force');
Force2 = input('Enter 2nd Force');
Force3 = input('Enter 3rd Force');
Angle1 = input('Enter 1st angle');
Angle2 = input('Enter 2nd angle');
Angle3 = input('Enter 3rd angle');
hold on;
ForceALL = [Force1, Force2, Force3];
AngleALL = [Angle1, Angle2, Angle3];
AngleALL = AngleALL.*pi/180;
XForceALL_total = sum(ForceALL.*sin(theta));
YForceALL_total = sum(ForceALL.*cos(theta));
Angle_Result = atan(YForceALL_total./XForceALL_total);
Angle_ResultDegrees = Angle_Result.*180/pi
Total_Force = XForceALL_total./cos(Angle_Result)
hold off;
end
disp('Angle_ResultDegrees');
disp('Total_Force');

Sign in to comment.

Accepted Answer

Rik
Rik on 15 Apr 2019
You aren't checking if the values are valid. That means you're never changing the value of valid, which results in an endless loop.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!