Variable might be set by a nonscalar operator

20 ビュー (過去 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 Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by