Help with my matlab function.

3 visualizzazioni (ultimi 30 giorni)
Alan Barraza
Alan Barraza il 3 Dic 2020
Commentato: Joseph Wilson il 3 Dic 2020
Is there also a way to make it so that instead of manually entering the ultimate strength of the cable, the function recommends three metal options (bronze, aluminum, or steel). And whichever option the user picks, the function has a preset number for that metal and calculates it.
MATLAB FUNCTION:
function [FB, FC, FD] = CableForces()
% This function determines the force in two cables used to support
% an assigned crate.
clc
close all
clear all
help CableForces
disp('Note: Please enter the coordinates in the form of [x,y,z]!')
B = input('Enter the coordinates of B:');
C = input('Enter the coordinates of C:');
W = input('Enter the weight of the crate in lbs:');
% ultimate strength
UB=input('Ultimate strength of cable BD: ');
UC=input('Ultimate strength of cable CD: ');
dB=input('Cross-section diameter of cable BD: ');
dC=input('Cross-section diameter of cable CD: ');
AB=(pi/4)*dB^2;
AC=(pi/4)*dC^2;
Wrange = input('Enter the range of weights for which you wish to plot F vs W [W_min, W_max]:');
fb = B./norm(B);
fc = C./norm(C);
fd = [1 0 0];
A = [fb(1), fc(1), fd(1)
fb(2), fc(2), fd(2)
fb(3), fc(3), fd(3)];
b = [0, 0, W]';
sol = A\b;
FB = sol(1);
FC = sol(2);
FD = sol(3);
% stress finding
SB=FB/AB;
SC=FC/AC;
if SB>UB || SC>UC
fprintf('\nStress is high. So, cable will break\n')
else
fprintf('\nStress is low. So, cable will not break\n')
end
W = Wrange(1):Wrange(2);
FBg = zeros(size(W));
FCg = zeros(size(W));
FDg = zeros(size(W));
for i = 1:length(W)
b = [0, 0, W(i)]';
sol = A\b;
FBg(i) = sol(1);
FCg(i) = sol(2);
FDg(i) = sol(3);
end
plot(W,FBg,'r--p')
hold on
plot(W,FCg, 'b--p')
plot(W,FDg,'g--p')
grid on
title('FORCE vs WEIGHT')
xlabel('WEIGHT (lb)')
ylabel('FORCE (lb)')
legend('FB','FC','FD');
end
  1 Commento
Star Strider
Star Strider il 3 Dic 2020
I’m not certain what you want to do, however if you want default entries of some sort, the inputdlg function (and its firends) would likely be better options than input.

Accedi per commentare.

Risposte (1)

Joseph Wilson
Joseph Wilson il 3 Dic 2020
type_of_metal_BD = questdlg('prompt question i.e. Type of metal for BD?','Title of prompt','bronze', 'aluminum', 'steel','steel');
switch type_of_metal_BD
case 'aluminum'
UB = 5;
end
Refer to MATLAB documentation for questdlg for style options for the user prompt.
Could use IF statements instead of switch but I'd prefer switch in this circumstance.
  1 Commento
Joseph Wilson
Joseph Wilson il 3 Dic 2020
If you need more than three options use listdlg. questdlg is limited to three buttons.

Accedi per commentare.

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by