How can I plot the figure?

2 vues (au cours des 30 derniers jours)
Myo Gyi
Myo Gyi le 27 Oct 2018
Commenté : Myo Gyi le 29 Oct 2018
if true
% code
end
  2 commentaires
Image Analyst
Image Analyst le 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.
Myo Gyi
Myo Gyi le 29 Oct 2018
Thank you sir.

Connectez-vous pour commenter.

Réponse acceptée

Image Analyst
Image Analyst le 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 commentaires
Image Analyst
Image Analyst le 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]);
Myo Gyi
Myo Gyi le 28 Oct 2018
Thank you very much sir.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by