How can I plot the figure?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
if true
% code
end
2 commentaires
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.
Réponse acceptée
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
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]);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!