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 :)

回答 (1 件)

Stephan
Stephan 2018 年 10 月 25 日
編集済み: Stephan 2018 年 11 月 1 日

0 投票

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

この質問は閉じられています。

質問済み:

2018 年 10 月 24 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by