How to improve plot in MATLAB?
7 views (last 30 days)
Show older comments
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.
%
0 Comments
Answers (2)
Walter Roberson
on 13 Nov 2016
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.
0 Comments
atharva aalok
on 17 Oct 2021
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:
0 Comments
See Also
Categories
Find more on Surface and Mesh 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!