How to improve plot in MATLAB?

7 次查看(过去 30 天)
Juliane Trianon
Juliane Trianon 2016-11-12
I'm trying to plot the following functions on MATLAB:
function [] = testeh()
E = @(z) 0.23.*(1+z).^3+0.77
rhoc = @(z) E(z).*(2.775.*10.^(11))
omegam = @(z) 0.23.*(1+z).^3./(E(z))
x = @(z) omegam(z) - 1
deltac = @(z) 177.65+82.*x(z)-39.*x(z).^2
rvir = @(M,z) (3.*M./(12.566.*rhoc(z).*deltac(z))).^(1/3)
c = @(M,z) (9./(1+z)).*(M./((1.23).*10.^(12))).^(-0.13)
rhos = @(M,z) (c(M,z)).^3.*(M./(12.566.*(rvir(M,z)).^(3))).*(1./(log(1+c(M,z))-(c(M,z))./(1+c(M,z))))
rho = @(M,z,r) rhos(M,z)./((c(M,z).*r./(rvir(M,z))).*(1+(c(M,z).*r./(rvir(M,z)))).^2)
rho1 = @(r) rho(10.^14,0,r)
rho2 = @(r) rho(10.^14,1,r)
rho3 = @(r) rho(10.^15,0,r)
rho4 = @(r) rho(10.^15,1,r)
hold on
ezplot(rho1, [10.^-2 10.^2])
ezplot(rho2, [10.^-2 10.^2])
ezplot(rho3, [10.^-2 10.^2])
ezplot(rho4, [10.^-2 10.^2])
set(gca, 'XScale', 'log')
set(gca, 'YScale', 'log')
ylim([10.^5 10.^17])
But I obtain the graph below, which seems to have a discontinuity on the first derivative. Is there a way to avoid this? I wish a smoother result.
%

回答(2 个)

Walter Roberson
Walter Roberson 2016-11-13
If you want smoother results, do not use ezplot(). Instead, evaluate the function handles at specific locations and plot() the result against the locations.
If you have a sufficiently new version of MATLAB you could also consider using fplot() instead of ezplot(), and specify the MeshDensity option.

atharva aalok
atharva aalok 2021-10-17
Please refer the following Plotting Template:
The above is an easy to follow Beginner Friendly template.
The idea is to create Professional Standard Plots within seconds without a steep learning curve and with consistency.
It also offers a wide range of preset Color Codes (please refer the attached image for the Color Palatte)
Sample Plot:
Color Palatte:

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by