how can I plot

1 回表示 (過去 30 日間)
ueqweoıqwueoq
ueqweoıqwueoq 2024 年 3 月 25 日
編集済み: Rena Berman 2024 年 4 月 3 日
sigma_0 = 2;
r = 1:0.1:2;
ksi = 1./r;
theta = 0;
sigma_r = (1/2.*sigma_0.*(1-(ksi.^2)))-(1/2.*sigma_0.*(1+(3.*(ksi.^4))-(4.*(ksi.^2))).*cos(2.*theta))
How can I show this as theta 0, 90, 180 and 270, all in one chart, depending on sigma r?
  2 件のコメント
Manikanta Aditya
Manikanta Aditya 2024 年 3 月 25 日
Hey,
Check this:
% Constants
sigma_0 = 2;
theta_deg = [0, 90, 180, 270]; % Degrees
theta_rad = deg2rad(theta_deg); % Convert degrees to radians
% Variable
r = 1:0.1:2;
% Pre-allocate sigma_r for efficiency
sigma_r = zeros(length(r), length(theta_rad));
% Calculate sigma_r for each theta
for i = 1:length(theta_rad)
theta = theta_rad(i);
ksi = 1./r;
sigma_r(:, i) = (1/2.*sigma_0.*(1-(ksi.^2))) - (1/2.*sigma_0.*(1+(3.*(ksi.^4))-(4.*(ksi.^2))).*cos(2.*theta));
end
% Plotting
figure; % Create a new figure
hold on; % Hold on to plot multiple lines
colors = ['r', 'g', 'b', 'k']; % Colors for each theta
for i = 1:length(theta_rad)
plot(r, sigma_r(:, i), 'Color', colors(i), 'DisplayName', sprintf('\\theta = %d°', theta_deg(i)));
end
hold off;
xlabel('r');
ylabel('\sigma_r');
title('\sigma_r vs. r for \theta = 0, 90, 180, and 270 degrees');
legend('show');
grid on;
Rena Berman
Rena Berman 2024 年 4 月 3 日

(Answers Dev) Restored edit

サインインしてコメントする。

回答 (1 件)

Hassaan
Hassaan 2024 年 3 月 25 日
sigma_0 = 2;
r = 1:0.1:2; % Range of r
theta_deg = [0, 90, 180, 270]; % Angles in degrees
theta_rad = deg2rad(theta_deg); % Convert angles to radians
% Preallocate matrix for sigma_r values
sigma_r = zeros(length(r), length(theta_rad));
% Calculate sigma_r for each theta
for i = 1:length(theta_rad)
ksi = 1./r;
theta = theta_rad(i);
sigma_r(:, i) = (1/2.*sigma_0.*(1-(ksi.^2))) - (1/2.*sigma_0.*(1+(3.*(ksi.^4))-(4.*(ksi.^2))).*cos(2.*theta));
end
% Plot sigma_r vs r for each theta
figure;
plot(r, sigma_r, 'LineWidth', 2);
xlabel('r');
ylabel('\sigma_r');
title('\sigma_r vs r for Different \theta Values');
legend('0°', '90°', '180°', '270°');
grid on;
-----------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
It's important to note that the advice and code are based on limited information and meant for educational purposes. Users should verify and adapt the code to their specific needs, ensuring compatibility and adherence to ethical standards.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.

カテゴリ

Help Center および File ExchangeVector Fields についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by