Created
August 1, 2013 17:04
-
-
Save sandeepkunkunuru/6133274 to your computer and use it in GitHub Desktop.
Plot Big O functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hold off; | |
close; | |
N = 1000; | |
X = 1:N; | |
size(X) | |
hold on; | |
axis([1 50 1 50 ]); | |
xlabel ("x"); | |
z = log(X); | |
plot (X, z, 'b', 'LineWidth', 2); | |
text (X(25), z(25) + 1, "log(x)"); | |
z = X; | |
plot (X, z, 'g', 'LineWidth', 2); | |
text (X(25), z(25) + 1, "x"); | |
z = X .* log(X); | |
plot (X, z, 'm', 'LineWidth', 2); | |
text (X(10), z(10), "x*log(x)"); | |
z = X.^2; | |
plot (X, z, 'r', 'LineWidth', 2); | |
text (X(5), z(5), "x^2"); | |
z = 2 .^ log(X); | |
plot (X, z, 'c', 'LineWidth', 2); | |
text (X(40), z(40), "2 power log(x)"); | |
z = 2 .^ X; | |
plot (X, z, 'k', 'LineWidth', 2); | |
text (X(4), z(5) , "2^x"); | |
legend("log(x)", "x", "x*log(x)", "x^2", "2 power log(x)", "2^x"); | |
hold off; | |
print("BigOComparisons.png"); | |
refresh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment