Variable might be set by a nonscalar operator

6 views (last 30 days)
what is wrong with variable theta_deg,
clc
clear
close all
%% Define varaibles
theta_deg=10:1:80; %% theta in 1 degrees increments
theta_rad=deg2rad(theta_deg);
theta_decline= 40.65;
thata_incline=18.05;
M=1; % mass, kg
g=9.81; %acceleration
m_M=0.5;
Mu_s=0.2;
Mu_k=0.15;
%F_f_k=Mu_k*M*g*cos(theta_deg); % dynamic friction force
%F_f_s=Mu_s*M*g*cos(theta_deg); % static friction force
if (10 <theta_deg) && (theta_deg<=18.05)
F_f_k=Mu_k*M*g*cos(theta_deg); % dynamic friction force, box moving upwards
end
if (18.05 <theta_deg)&&(theta_deg<=40.65)
F_f_s=Mu_s*M*g*cos(theta_deg); % static friction force, the box is still
end
if (40.6<theta_deg)&&(theta_deg<=80)
F_f_k=Mu_k*M*g*cos(theta_deg); % dynamic friction force, the box is sliding downwards
end

Accepted Answer

Torsten
Torsten on 1 Mar 2025
Edited: Torsten on 1 Mar 2025
%% Define varaibles
theta_deg=10:1:80; %% theta in 1 degrees increments
theta_incline=18.05;
theta_decline= 40.65;
M=1; % mass, kg
g=9.81; %acceleration
Mu_s=0.2;
Mu_k=0.15;
theta_zone1 = theta_deg<=theta_incline;
theta_zone2 = theta_deg >theta_incline & theta_deg<=theta_decline;
theta_zone3 = theta_deg >theta_decline ;
F_f_k(theta_zone1) = Mu_k*M*g*cosd(theta_deg(theta_zone1));
F_f_k(theta_zone2) = Mu_s*M*g*cosd(theta_deg(theta_zone2));
F_f_k(theta_zone3) = Mu_k*M*g*cosd(theta_deg(theta_zone3));
plot(theta_deg,F_f_k)
grid on
  3 Comments
Torsten
Torsten on 1 Mar 2025
I doesn't make sense to use different arrays for different zones for the variable theta_deg. All should be saved in one array (F_f_k) as I did above. As you can see, there are jumps in the friction force curve at theta_deg = 18.05° and theta_deg = 40.65°.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 1 Mar 2025
If theta_deg is in degrees, you should be using the degrees version of cosine, not the radian version. In other words use cosd, not cos
help cosd
cosd - Cosine of argument in degrees This MATLAB function returns the cosine of the elements of X, which are expressed in degrees. Syntax Y = cosd(X) Input Arguments X - Angle in degrees scalar value | vector | matrix | multidimensional array | table | timetable Output Arguments Y - Cosine of angle scalar value | vector | matrix | multidimensional array | table | timetable Examples openExample('matlab/Cosineof90degreescomparedtocosineof2radiansExample') openExample('matlab/CosineofcomplexanglesspecifiedindegreesExample') See also cos, acos, acosd Introduced in MATLAB before R2006a Documentation for cosd doc cosd Other uses of cosd codistributed/cosd gpuArray/cosd sym/cosd tabular/cosd

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!