How can I plot the figure?
2 ビュー (過去 30 日間)
古いコメントを表示
if true
% code
end
2 件のコメント
Image Analyst
2018 年 10 月 28 日
In the future, please don't post questions that are homework without tagging them as homework. That way we can answer in a way that you can still guide you to the answer without giving it to you outright, and then requiring you to delete your question so you don't get into trouble with your professor.
採用された回答
Image Analyst
2018 年 10 月 27 日
Is this homework?
Just use an two sets of code for the two ranges.
% First do the left range.
r1 = linspace(0, a, 500); % 500 points from 0 to a
z1 = ...your formula
plot(r1, z1, 'b-', 'LineWidth', 2);
% First do the right range.
r2 = linspace(a, 3, 500); % 500 points from a to 3
z2 = ...your formula
hold on;
grid on;
plot(r2, z2, 'b-', 'LineWidth', 2);
% Plot dashed line
line([1, 1], ylim, 'LineStyle', '--', 'Color', 'k');
2 件のコメント
Image Analyst
2018 年 10 月 27 日
You didn't have the right equations. For example you didn't put parentheses around 2*g, so g ended up in the numerator instead of the denominator. And the equation for z2 was totally messed up. Fixed code is below:
% First do the left range.
w = 1;
a = 1;
g = 9.82;
r1 = linspace(0, a, 500); % 500 points from 0 to
z1 = (w^2. * r1.^2) / (2*g); % your formula
plot(r1, z1, 'b-', 'LineWidth', 2);
% First do the right range.
r2 = linspace(a, 3, 500); % 500 points from a to 3
term1 = (w^2 .* a.^2)/g;
term2 = 1 - a^2 ./ (2 * r2 .^ 2);
z2 = term1 .* term2;
hold on
grid on;
plot(r2, z2, 'b-', 'LineWidth', 2);
xlabel('r', 'FontSize', 25);
ylabel('z(r)', 'FontSize', 25);
% Plot dashed line
line([1, 1], ylim, 'LineStyle', '--', 'Color', 'k');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!