Trouble Solving for Variables Using 3 Separate Numbers

Assignment is "write a MATLAB script file (Lab07p2.m) that plots the tensions for Theta=5,10,...85 deg, LAC=6 ft, LAB=3,6,9 ft, and W=2000 lb.
So heres my code: it works perfectly with one number in for LAB but when I plug in 3 it doesn't. Not sure how to fix this and/or if there is a simple way to do so.
CODE::
lab = (3 6 9); {PROBLEM AREA} %ft
lac = 6; %ft
W = 2000; %lbs
theta = (5:5:85); %degrees
phi = atand(lab.*sind(theta) ./ (lac-lab.*cosd(theta))); %degrees
Lbc = lab.*sind(theta) ./ sind(phi); %ft
Tab = (W.*cosd(phi)) ./ ((sind(theta)+ cosd(theta)).*(sind(phi)));
Tbc = (Tab.*cosd(theta)) ./ (cosd(phi));
T = max(Tab, Tbc);
plot(Tab, Tbc);
Any advice/fixes will be greatly appreciated!! Thank YOU :)

Answers (1)

Hi,
vectors are defined by square brackets. Then additionally use the colon operator ':' since your result gets a matrix:
lab = [1 2 4]; % {PROBLEM AREA} %ft
lac = 6; %ft
W = 2000; %lbs
theta = (5:5:85); %degrees
phi = atand(lab(:).*sind(theta) ./ (lac-lab(:).*cosd(theta))); %degrees
Lbc = lab(:).*sind(theta) ./ sind(phi); %ft
Tab = (W.*cosd(phi)) ./ ((sind(theta)+ cosd(theta)).*(sind(phi)));
Tbc = (Tab.*cosd(theta)) ./ (cosd(phi));
T = max(Tab, Tbc);
plot(Tab', Tbc');
Best regards
Stephan

This question is closed.

Asked:

on 24 Oct 2018

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!