How can I plot the figure?
2 views (last 30 days)
Show older comments
if true
% code
end
2 Comments
Image Analyst
on 28 Oct 2018
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.
Accepted Answer
Image Analyst
on 27 Oct 2018
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 Comments
Image Analyst
on 27 Oct 2018
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]);
More Answers (0)
See Also
Categories
Find more on Line Plots 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!