How can I plot the figure?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Myo Gyi
el 27 de Oct. de 2018
Comentada: Myo Gyi
el 29 de Oct. de 2018
if true
% code
end
2 comentarios
Image Analyst
el 28 de Oct. de 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.
Respuesta aceptada
Image Analyst
el 27 de Oct. de 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 comentarios
Image Analyst
el 27 de Oct. de 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]);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193529/image.png)
Más respuestas (0)
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!