AoPSWiki
Looking for a challenging algebra text? Preparing for MATHCOUNTS or the AMC exams?
Check out Art of Problem Solving's Introduction to Algebra by Richard Rusczyk.

Asymptote: Graphing

From AoPSWiki

Asymptote (Vector Graphics Language)
Getting Started - Basics - Reference - Examples - How to - Macros and Packages - Advanced Asymptote - Help

Useful functions - CSE5 Package

There are two parts to a graph.

The axises codes:

Label f; 
f.p=fontsize(6); 
xaxis(-8,8,Ticks(f, 2.0)); 
yaxis(-8,8,Ticks(f, 2.0)); 

This means ticks at an interveral of 2.0 between -8 and 8 for both the x and y axises.

And the graph code:

real f(real x) 
{ 
return x^3; 
} 
draw(graph(f,-2,2));

The return x^3 is the function of the graph, and the draw command draws the graph from the x coordinate of x = - 2 to x = 2.

import graph; size(300); Label f; f.p=fontsize(6); xaxis(-8,8,Ticks(f, 2.0)); yaxis(-8,8,Ticks(f, 2.0)); real f(real x) { ret...

We can also alter the ticks code. For example, if we want intervals of 2 labeled, then 0.5 in between each one, we can use the following code:

Label f; 
f.p=fontsize(6); 
xaxis(-8,8,Ticks(f, 2.0,0.5)); 
yaxis(-8,8,Ticks(f, 2.0,0.5)); 

Label f; f.p=fontsize(6); xaxis(-8,8,Ticks(f, 2.0,0.5)); yaxis(-8,8,Ticks(f, 2.0,0.5)); This graph, like with any draw command, can have several attributes fixed to it, such as color:

import graph; size(300); Label f; f.p=fontsize(6); xaxis(-8,8,Ticks(f, 2.0)); yaxis(-8,8,Ticks(f, 2.0)); real f(real x) { ret...

import graph; 
size(300); 
Label f; 
f.p=fontsize(6); 
xaxis(-8,8,Ticks(f, 2.0)); 
yaxis(-8,8,Ticks(f, 2.0)); 
real f(real x) 
{ 
return x^3; 
} 
draw(graph(f,-2,2),green+linewidth(1));

Remember, you can still draw normal functions, so you can create lines, circles and ellipses.

Want to learn how to tackle those tough MATHCOUNTS and AMC counting and probability problems? Check out Art of Problem Solving's Introduction to Counting & Probability by David Patrick.
© Copyright 2008 AoPS Incorporated. All Rights Reserved. • FoundationPrivacyContact Us