Variable might be set by a nonscalar operator

조회 수: 19 (최근 30일)
Saif
Saif 2025년 3월 1일
댓글: Saif 2025년 3월 8일
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

채택된 답변

Torsten
Torsten 2025년 3월 1일
편집: Torsten 2025년 3월 1일
%% 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
Torsten
Torsten 2025년 3월 1일
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°.
Saif
Saif 2025년 3월 8일
Make sense, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2025년 3월 1일
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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by