︠c49dac75-13e2-4951-9fe6-a75a4de67425i︠ %html
Sage is a powerful mathematical calculator, often called a computer algebra system (CAS) or symbolic mathematics program, because unlike most calculators it can do algebra and calculus symbolically. For example, it can expand the product ${(x + 1)}^{30}$ into the normal representation of this polynomial, and it can factor the result back into the original form. It can compute the derivative or antiderivative of $3x∕\sqrt{{x}^{2 } + 2x + 47}$. It can also serve as a numerical calculator, but again unlike most calculators it can do integer and rational number arithmetic exactly, no matter how many digits are involved. If it is undesirable or impossible to express a result exactly, Sage can do numerical approximation. Finally, Sage can plot curves and surfaces in two and three dimensions.
To learn how to use some of Sage’s features, you should work through this tutorial step by step. As you go, you may alter the Sage commands and type new ones to experiment; you will learn better and faster if you do this. However, some commands depend on the results of previous commands, so before you continue you may want to restore the original calculation. A good alternative is to experiment in a new command window, called a cell in Sage. If you hover your mouse just a bit above an existing cell you will see a blue bar appear; click on this bar and a new cell appears. The blocks of plain text between command cells are themselves cells, and you can open new command cells above them in the same way.
Sage remembers values from one cell to the next, but if you don’t execute any commands for a while these values are forgotten. You may have to return to an earlier cell and re-execute it to refresh a value.
To evaluate the contents of a command cell, click in the box; the outline should turn blue. Then hold down the shift key and press return. This takes some getting used to; if you press just return, Sage will simply start a new line. When this happens, just backspace and then press shift-return. If you prefer, you can click on the word Evaluate below the box.
Try evaluating the cell below. Then hover above the box and open a new cell. Then hover between the original cell and the following text (“You may type more than one command…”) and open a new cell there as well. Try evaluating some simple arithmetic expressions using “$+$”, “$−$”, “$∗$”, and “$∕$”.
︡52149b01-30ed-4361-9382-e287bb4aeead︡{"html": "Sage is a powerful mathematical calculator, often called a computer algebra system (CAS) or symbolic mathematics\nprogram, because unlike most calculators it can do algebra and calculus symbolically. For example, it can expand\nthe product ${(x + 1)}^{30}$\n \n \ninto the normal representation of this polynomial, and it can factor the result\nback into the original form. It can compute the derivative or antiderivative of\n$3x∕\\sqrt{{x}^{2 } + 2x + 47}$. It can\nalso serve as a numerical calculator, but again unlike most calculators it can do integer and rational\nnumber arithmetic exactly, no matter how many digits are involved. If it is undesirable or impossible to\nexpress a result exactly, Sage can do numerical approximation. Finally, Sage can plot curves and surfaces\nin two and three dimensions.\n
To learn how to use some of Sage’s features, you should work through this tutorial step by step. As you\ngo, you may alter the Sage commands and type new ones to experiment; you will learn better and faster if\nyou do this. However, some commands depend on the results of previous commands, so before you\ncontinue you may want to restore the original calculation. A good alternative is to experiment in a new\ncommand window, called a cell in Sage. If you hover your mouse just a bit above an existing cell you will\nsee a blue bar appear; click on this bar and a new cell appears. The blocks of plain text between\ncommand cells are themselves cells, and you can open new command cells above them in the same\nway.\n
Sage remembers values from one cell to the next, but if you don’t execute any commands for a while\nthese values are forgotten. You may have to return to an earlier cell and re-execute it to refresh a\nvalue.\n
\n
\n
To evaluate the contents of a command cell, click in the box; the outline should turn blue. Then hold down\nthe shift key and press return. This takes some getting used to; if you press just return, Sage will simply\nstart a new line. When this happens, just backspace and then press shift-return. If you prefer, you can\nclick on the word Evaluate below the box.\n
Try evaluating the cell below. Then hover above the box and open a new cell. Then hover\nbetween the original cell and the following text (“You may type more than one command…”)\nand open a new cell there as well. Try evaluating some simple arithmetic expressions using\n“$+$”,\n“$−$”,\n“$∗$”, and\n“$∕$”.\n
"}︡ ︠fb25529c-ddfc-4efb-86f6-2ad5b20300ee︠ 123456789*987654321 ︡6ad8bc0e-a4cd-4e6c-a9ba-fc630f9a1e3f︡︡ ︠cefd60b9-93d0-47c2-ae32-dcdcdf55a7d1i︠ %htmlYou may type more than one command in a window by placing semicolons between them.
︡489d90f3-cfe4-4f5f-91ee-5130491ec71b︡{"html": "You may type more than one command in a window by placing semicolons between them.\n \n \n
"}︡ ︠8f14e6df-8209-4a4a-8453-a788750a9169︠ 2+3; 34*98-45 ︡6647c1b9-7ff8-4d22-83f7-53c204a3288e︡︡ ︠d59b67a6-a9c8-4ef0-8508-a65f9165575ci︠ %htmlThe ordinary precedence rules apply to mathematical operations: multiplication and division are done first, then addition and subtraction. Multiplication and division have the same precedence, as do addition and subtraction; a sequence of mixed multiplications and divisions is evaluated left to right, and likewise for additions and subtractions. Make sure you understand these:
︡3965f67c-e50d-4b0c-86ee-430f433cc1e1︡{"html": "The ordinary precedence rules apply to mathematical operations: multiplication and division are done\nfirst, then addition and subtraction. Multiplication and division have the same precedence, as do addition\nand subtraction; a sequence of mixed multiplications and divisions is evaluated left to right, and likewise\nfor additions and subtractions. Make sure you understand these:\n
"}︡ ︠abbf7aa7-8707-49a7-83d4-8ac0b905d91d︠ 24/3/2; 24/3*2; 24/4+1 ︡b0ba5c67-0320-44b6-a6f4-7a4167922c08︡︡ ︠59c6055e-190f-421b-b468-c3205396f674i︠ %htmlYou may of course use parentheses to alter the order of operations. Sometimes using extra parentheses is a good idea because it makes it easier to read and understand an expression.
Sage will do arithmetic with rational numbers without converting to decimal form:
︡e9a697ea-620f-4d23-a8b4-5c359dcacba5︡{"html": "You may of course use parentheses to alter the order of operations. Sometimes using extra parentheses is a\ngood idea because it makes it easier to read and understand an expression.\n
Sage will do arithmetic with rational numbers without converting to decimal form:\n
"}︡ ︠1a18ddb0-9d68-4052-9021-1bf085a3cf10︠ 2/5 + 1/3; 23/45-167/345*2/3 ︡8c8ebd6f-5187-4e46-985a-15eb7c4cd7ce︡︡ ︠506a96be-5692-4df9-82f9-b2f9bfdf8338i︠ %htmlSage knows standard mathematical notation, including two symbols for exponentiation. The underscore character refers to the previous result.
︡13957908-5778-4820-95fb-2311ca537d66︡{"html": "Sage knows standard mathematical notation, including two symbols for exponentiation. The underscore\ncharacter refers to the previous result.\n
"}︡ ︠cdced045-67d5-48bd-afaa-698b1288c098︠ 2**5; 3^27; factor(_) ︡3ae51307-ea1b-4240-9d3d-2eb2bb074f7f︡︡ ︠e3004f22-8b97-4a42-a040-e125ea3bf640i︠ %htmlYou can force Sage to approximate values using decimal notation.
︡bb9f6f82-1526-4819-b7da-65e22ce96cb9︡{"html": "You can force Sage to approximate values using decimal notation.\n
"}︡ ︠50441c45-007b-4d02-9bd7-122f2aa5dedb︠ 12345/98765; n(_) ︡0b4fd256-3366-4362-b09f-74f1e7fc4278︡︡ ︠080984b7-f2ec-4460-8ac4-20dd07aa2bcfi︠ %htmlSage understands $\pi$, $e$, and $i$ (the square root of $ − 1$).
︡6b25f7f3-fa12-4712-ae87-1db47e8a5d57︡{"html": "Sage understands $\\pi$, $e$, and $i$ (the square root of $ − 1$).
"}︡ ︠d5ed5e12-0b6e-44a2-984b-c3845efd369d︠ 3*pi; n(_); n(e); i^2 ︡e5588269-fd4f-45db-8307-4b1410330a95︡︡ ︠cce9b69c-8e2d-45ba-a2b7-1caa9ebc3490i︠ %htmlSage’s normal output can be a bit hard to read when it is complicated, though it becomes easier with practice, and it can be useful for copying results and pasting them in to new commands. At the top of the worksheet is a checkbox labeled Typeset. Check the box and then evaluate the previous cell; the output will be more familiar. Alternately, you may use the jsmath function to typeset a single result. Uncheck the Typeset box at the top of the page and then execute the next box.
︡8b368c3d-bf92-485b-9a81-ef86d445156d︡{"html": "Sage’s normal output can be a bit hard to read when it is complicated, though it becomes easier with\npractice, and it can be useful for copying results and pasting them in to new commands. At the top of the\nworksheet is a checkbox labeled Typeset. Check the box and then evaluate the previous cell;\nthe output will be more familiar. Alternately, you may use the jsmath function to typeset\na single result. Uncheck the Typeset box at the top of the page and then execute the next\nbox.\n
"}︡ ︠6e9e5c71-5a52-4ecc-a4de-fc6c50f030ab︠ sqrt(2); jsmath(sqrt(2)) ︡8e9a6e7a-a550-43a6-b676-4d2edf871e55︡︡ ︠8f14f308-952b-4804-8e49-b76869fc95f8i︠ %htmlThe function $\mathop{ exp}\nolimits (x)$ is an alternate form of ${e}^{x}$.
︡0a06e098-c029-43a0-a9a8-57294373234e︡{"html": "The function $\\mathop{ exp}\\nolimits (x)$ is\nan alternate form of ${e}^{x}$.\n
"}︡ ︠91715ef5-3ca5-4bfc-9981-33a86e17bad7︠ e^2; exp(2) ︡88787a24-42ed-409f-ae73-9a102851cc96︡︡ ︠4f7ea87f-ed46-47ef-9aac-f99472882f10i︠ %html
Sage can manipulate expressions involving variables as well as numbers. Variables can be assigned values, either actual numeric values or entire expressions.
︡5351ca12-7251-4818-948c-836015a32860︡{"html": "\n
Sage can manipulate expressions involving variables as well as numbers. Variables can be assigned values,\neither actual numeric values or entire expressions.\n
"}︡ ︠75aa3d0c-0473-4956-94a1-7803a9034562︠ f=(x+5)^2; f; expand(f); factor(_) ︡cbdafa2d-eccb-4edb-9be4-94ea4586222f︡︡ ︠dad94203-6525-48b1-a34d-5cca144089e0i︠ %htmlFor readability you can also put different commands on different lines; just press return without the shift at the end of the line. Note that only the last result will be displayed in this case, so generally you use this when the other lines produce no output.
︡3a93db51-53f6-45f0-8c39-410b58820f4a︡{"html": "For readability you can also put different commands on different lines; just press return without the shift\nat the end of the line. Note that only the last result will be displayed in this case, so generally you use this\nwhen the other lines produce no output.\n
"}︡ ︠a308c0d6-5c52-4f45-874f-36f08ab56b69︠ f=(x+5)^2 expand(f) factor(_) ︡a5f05f30-d13c-4046-ab80-809870d0fd0f︡︡ ︠fb6779dd-588f-45b8-bf07-4e847b04b967︠ f=(x+5)^2 expand(f); factor(_) ︡5a5f8022-0e8b-47b3-884f-31c700c6908c︡︡ ︠2c349d21-bbb7-46ec-8def-a336c68dd44di︠ %htmlWe normally think of $f = {(x + 5)}^{2}$ as a function, but it is not officially a function.
︡16199dc7-7dcb-44bd-b798-f58361067556︡{"html": "We normally think of $f = {(x + 5)}^{2}$\nas a function, but it is not officially a function.\n
"}︡ ︠9275d408-4f3d-4d87-b26e-61385394e02a︠ f(5) ︡fc76d449-7260-4469-afb7-8da77d662ef0︡︡ ︠d79e0d7d-529e-40c6-83b0-df1b7a4e2277i︠ %htmlSo that gives the result you expect, but only after a warning. Here’s how to make $f$ an official function:
︡0ab4abfd-cf52-4eb0-8a51-855fbb1a020e︡{"html": "So that gives the result you expect, but only after a warning. Here’s how to make\n$f$ an\nofficial function:\n
"}︡ ︠0b90e55f-7cc3-4660-898b-dba7f119f984︠ f(x) = (x+5)^2; f(5) ︡b4c04d05-f8c7-4b37-8af3-56be85b2f354︡︡ ︠e02b5317-0d06-4b0c-9fd0-fbbbdb7d3863i︠ %htmlYou should get in the habit of defining functions this way. You can see the value of $f$ by evaluating it:
︡39ab520b-61ae-4833-8dca-d8f4354566c4︡{"html": "You should get in the habit of defining functions this way. You can see the value of\n$f$ by\nevaluating it:\n
"}︡ ︠8fce23d2-7168-4df1-9642-e2bad24d1ed3︠ f ︡2c161199-1ee0-4522-b2fb-f3959a22e5e1︡︡ ︠1bc1c609-67ac-4f09-97c2-b87d114f1fb1i︠ %htmlThis notation indicates that Sage thinks of $f$ as a function, not merely an expression. Compare to this:
︡913b334c-5178-4cd6-97a7-4c92f55c5bbb︡{"html": "This notation indicates that Sage thinks of $f$\nas a function, not merely an expression. Compare to this:\n
"}︡ ︠888399ef-d101-44e6-91e7-eaf4554ac80d︠ g=(x+5)^2; g ︡6bdcd876-569b-4a75-ab89-83d2590d1e2e︡︡ ︠53586e98-91a6-4e2d-81e6-d3a5f429e8e9i︠ %htmlIf you have a mere expression that you would like to be a function, you have a couple of options. You can redefine it, but the expression you have might be the result of many calculations, not a simple definition. To turn the previous $g$ into a function you can do this:
︡81769305-bff4-42dc-a259-b0ce797bb4f0︡{"html": "If you have a mere expression that you would like to be a function, you have a couple of options. You can\nredefine it, but the expression you have might be the result of many calculations, not a simple definition. To turn\nthe previous $g$\ninto a function you can do this:\n
"}︡ ︠4708a771-0d03-403f-965f-2d2d205def59︠ h(x) = g; h ︡2601b278-fda0-4b76-9267-af00382a64c6︡︡ ︠b3cf3891-db37-4eb1-a8ec-aa7234c657a1i︠ %htmlThere’s no need to use a different name if you don’t need the original one:
︡b4ccbe5f-0588-4c23-8981-85a8c0e56dbb︡{"html": "There’s no need to use a different name if you don’t need the original one:\n
"}︡ ︠d32ef0b5-7da4-44ac-acd2-21bd8124705c︠ g(x) = g; g ︡1d55a40f-0c90-46f5-9836-7a42ba146eb8︡︡ ︠993b5434-6f7b-4ddc-ae06-9cedccc5d352i︠ %htmlHere’s something a little more realistic:
︡79b9bc02-e0b2-48d1-a227-e929fd2c1a8d︡{"html": "Here’s something a little more realistic:\n
"}︡ ︠792e89c3-77f1-413a-9eee-73c7b505e344︠ expand((x+4)^2 * (2*x+1)); g(x) = _; g; g(3) ︡5a6a002b-3f3d-493d-8e84-18c36db48761︡︡ ︠07ba583d-8790-4578-95fa-483db7df1af7i︠ %htmlYou may need to apply a function to a list of input values; here is something a bit easier than doing each one separately:
︡aeefa98b-ecee-4466-8dc6-67f9699fd603︡{"html": "You may need to apply a function to a list of input values; here is something a bit easier than doing\neach one separately:\n
"}︡ ︠8210abf4-d38b-48f7-bec1-edcbffc64225︠ L = [1,2,3,10]; map(g,L) ︡991ca2d8-0195-41d3-8767-effb8072bf71︡︡ ︠542a557f-c33c-4ab3-995d-c6e60dd3c7aai︠ %htmlIn ordinary mathematical notation you are used to leaving out some multiplication symbols; Sage does not allow this:
︡645a2b35-d902-4b4a-a274-0e37e6237eea︡{"html": "In ordinary mathematical notation you are used to leaving out some multiplication symbols; Sage does\nnot allow this:\n
"}︡ ︠0d144d3a-324e-4801-8831-9e75aee21a48︠ 2x ︡0d939aa6-91cb-46cb-8d6d-0b79c80b40d5︡︡ ︠807331d0-fec0-461e-a967-b42a780e6c2bi︠ %htmlType an asterisk between the 2 and the $x$ and evaluate that cell again.
We saw above how to expand and factor polynomials. If a polynomial has integer or rational coefficients, the “factor” command tries to factor it into polynomials with integer coefficients, perhaps times a rational number:
︡7f488d80-cf7d-4481-86ca-334ed0f60f29︡{"html": "Type an asterisk between the 2 and the $x$\nand evaluate that cell again.\n
We saw above how to expand and factor polynomials. If a polynomial has integer or rational\ncoefficients, the “factor” command tries to factor it into polynomials with integer coefficients, perhaps\ntimes a rational number:\n
"}︡ ︠2cde27b7-a87d-47b9-84c1-b589cd426aa1︠ expand((x+2)*(x-1/3)); factor(_) ︡575b6d85-d092-4808-b3de-946a3e81b8f5︡︡ ︠e2a41375-6644-4f2e-88fd-a7d626b4b073i︠ %htmlIf Sage can’t do this, it leaves the polynomial alone, even if it has a “nice” factorization:
︡296d37b1-3199-4e3b-b6b7-c780c2370bed︡{"html": "If Sage can’t do this, it leaves the polynomial alone, even if it has a “nice” factorization:\n
"}︡ ︠927ee268-8804-478e-a86c-6d583cf44659︠ factor(x^2-2); factor(x^2-x-1) ︡01d23295-5b0d-4c0f-b88a-ea82342f7938︡︡ ︠1c6208cc-18a6-41f3-853e-f28ae357aaeci︠ %html
We use “variables” in a variety of ways, to stand for “true variables”, for functions, or for unspecified constants. We might say, for example, $f(x) = A{(x + 5)}^{2}$, using all of these. If we try this, there is already a problem:
︡a5c544b3-0d0d-4ce4-9d0b-6f9a2aadc8d0︡{"html": "\n
We use “variables” in a variety of ways, to stand for “true variables”, for functions, or for unspecified constants. We might\nsay, for example, $f(x) = A{(x + 5)}^{2}$,\n \n \nusing all of these. If we try this, there is already a problem:\n
"}︡ ︠c30c1190-f185-4858-9c80-f31e1a70c999︠ f(x)=A*(x+5)^2 ︡35db4a16-5321-44e0-8f38-49ae67f5fb7f︡︡ ︠5a99654a-9a23-4afb-b678-5ed2be7eead9i︠ %htmlAlthough Sage understands that $x$ is a variable, we must tell it explicitly about others:
︡01783f38-3cc6-479b-9365-defb0cb4c36f︡{"html": "Although Sage understands that $x$\nis a variable, we must tell it explicitly about others:\n
"}︡ ︠822e6ca0-b3c5-44b8-8948-c73f6abf90fe︠ A=var("A"); f(x)=A*(x+5)^2 ︡39544ef3-a186-4a20-b05f-916b4159b924︡︡ ︠8840e03e-2b04-49ec-b23d-efcefceea394i︠ %htmlWe can manipulate this as you would expect:
︡da2db64c-bd2f-4ecf-9367-31852364b6a2︡{"html": "We can manipulate this as you would expect:\n
"}︡ ︠ceb4b4d6-607f-4dc5-afd4-9143dd389bb7︠ expand(f); factor(_) ︡0811bb47-d078-438a-9d25-e379a10bb7fb︡︡ ︠12803ba0-e02c-4d12-8be6-4439a50d8e49i︠ %htmlNotice that strangely the result of expand is a function but the result of factor is not!
We may then want to assign the constant $A$ a value. We can do this temporarily like this:
︡e941aa09-56ce-41d1-a08f-b425c58d750d︡{"html": "Notice that strangely the result of expand is a function but the result of factor is not!\n
We may then want to assign the constant $A$\na value. We can do this temporarily like this:\n
"}︡ ︠0d84e9b5-bc68-4fda-b6cb-eafa8e094b10︠ f(A=2); f(3,A=2); f; A ︡58d5b612-0688-4a83-b705-6ec009432970︡︡ ︠e874a912-5a0d-4f67-8e75-ac46aa97b649i︠ %htmlSo we see that the definition of $f$ has not changed, it still contains the symbol $A$. This happens even if we give $A$ a permanent value:
︡e338dbbe-7de1-4e40-a6c4-804576edcad9︡{"html": "So we see that the definition of $f$ has not\nchanged, it still contains the symbol $A$.\nThis happens even if we give $A$\na permanent value:\n
"}︡ ︠79898e5a-6172-4ee6-be90-e0afc1c844fb︠ A=2; f; A ︡49c1cdb4-4638-4cc7-bf89-d8e34fd29da2︡︡ ︠4d468da2-6e34-4b6f-8e9c-eae56bbfaa8di︠ %htmlThis is probably a bad idea, since it is at least confusing. If you would like a new function with $A$ replaced by 2 you can do something like this:
︡4278b2f5-827e-4b1d-94de-496fb1df9587︡{"html": "This is probably a bad idea, since it is at least confusing. If you would like a new function with\n$A$\nreplaced by 2 you can do something like this:\n
"}︡ ︠1fe5ac19-95c9-412b-a991-3e8792e2d77b︠ g(x) = f(A=2); g; g(5) ︡15306153-b4d2-4650-a149-82bd04ccd81b︡︡ ︠918ebf11-2c63-4187-96b9-c93a3f665823i︠ %htmlLet’s restore $A$ to its status as a variable with no value:
︡af98d637-2281-461f-a27b-798b74f6a742︡{"html": "Let’s restore $A$\nto its status as a variable with no value:\n
"}︡ ︠1436cc13-ea15-497e-bd14-a36d4d306d40︠ A; A=var("A"); A ︡fe705672-2069-494c-a81c-943a5b51d3d3︡︡ ︠92d56e84-1a2e-41e7-859e-7a2c9038eeb9i︠ %htmlYou can subsitute expressions for variables, not just values.
︡5d865f43-5f84-4f98-b0e2-045f01581f46︡{"html": "You can subsitute expressions for variables, not just values.\n
"}︡ ︠6cfd2286-cb92-4602-bb13-7fc4d2d505b2︠ g(x) = f(A=x^3-1); g; h(x) = f(2*x+3,A=x^3-1); h ︡946405a1-7da2-49f5-844d-ccd4c51ed33d︡︡ ︠ff2772e8-c5c7-492f-971c-5c34c539b0bci︠ %htmlMake sure you understand how $h$ is defined. This substitution method works quite generally on expressions that may not have names:
︡037179c1-9643-4513-aafe-ea3337df8889︡{"html": "Make sure you understand how $h$\nis defined. This substitution method works quite generally on expressions that may not have\nnames:\n
"}︡ ︠5b77a4fb-62d9-4b26-b80f-36963225b737︠ (A^2+2)(A=3*x+1) ︡3168afd8-20df-49fa-be52-df9919fb6d30︡︡ ︠d64680e1-2b20-4489-a835-d1a095325022i︠ %html
Sage will solve a limited class of equations exactly and a broader class approximately. The solve command will give exact answers if possible, including complex answers.
︡e258950c-0b68-43cb-b0b6-f5a596d02281︡{"html": "\n
Sage will solve a limited class of equations exactly and a broader class approximately. The solve command\nwill give exact answers if possible, including complex answers.\n
"}︡ ︠9505817c-4986-4302-a241-5f26fb480a3a︠ solve(x^2-x-10==10,x); ︡c5888616-8363-4644-98fe-0c6bf759b7d4︡︡ ︠665e4f44-a730-4467-b4b6-81899b4b7e17i︠ %htmlIf you specify just a function, Sage assumes you want to set it equal to zero and solve.
︡ed5bd0ff-b0f2-4e30-86d0-f0a8186db13d︡{"html": "If you specify just a function, Sage assumes you want to set it equal to zero and solve.\n
"}︡ ︠8e6f929e-da90-41c1-b630-bee45089f402︠ solutions=solve(g(x),x); solutions ︡693857ee-3f93-45be-97ce-19ca8178c31b︡︡ ︠b84ab650-cb4f-4191-ba96-3cbe2ba4c3dci︠ %htmlEven when Sage can solve the equation exactly, you may want to see numerical approximations. You can use the n function on each solution, or with a bit of programming do them all at once. First we generate the solutions in a different form:
︡2012ce39-5a18-4186-be93-d0a50dfc0d4f︡{"html": "Even when Sage can solve the equation exactly, you may want to see numerical approximations. You can\nuse the n function on each solution, or with a bit of programming do them all at once. First we generate\nthe solutions in a different form:\n
"}︡ ︠bebdddb2-b574-4af2-b101-e42d38ff84bb︠ solutions=solve(g(x),x,solution_dict=True); solutions; ︡bce311bc-2a3c-4a0a-9758-533edb6bc8b7︡︡ ︠58bf95e6-e020-4787-997b-a059b2e15309i︠ %htmlThen we can extract just the numerical values:
︡8b3aa374-d445-413f-a934-317fbe4a33fb︡{"html": "Then we can extract just the numerical values:\n
"}︡ ︠33d78e35-e141-4a06-84d5-14f2755a4014︠ newsolutions = [ s[x] for s in solutions]; newsolutions ︡ee5c15bd-5834-402e-a52a-04be20993924︡︡ ︠b61d0b9e-73ac-41dd-a990-0dbfcd57b156i︠ %htmlThen use the map function to apply n to each number on the list:
︡3fcad7ef-5fda-4931-bd02-e5c1d0db116c︡{"html": "Then use the map function to apply n to each number on the list:\n
"}︡ ︠90da66c8-5b30-41d7-8eee-655291f2e162︠ map(n,newsolutions) ︡b5438415-158b-44b5-8aec-2a80802e8d60︡︡ ︠facb4706-8ac9-4146-8bf2-8b902e18c153i︠ %htmlOr we could combine the last two steps:
︡efd930a1-60ab-4a7f-8037-c77ea77eb09d︡{"html": "Or we could combine the last two steps:\n
"}︡ ︠9a0a8dc6-8d15-4e61-9fa2-a204e7911be2︠ [ n(s[x]) for s in solutions] ︡74e0c1a1-2816-430c-a2bb-e30c13a47fdf︡︡ ︠95a25560-260d-4f5b-9e4e-81e1379c1690i︠ %htmlIf Sage can’t solve an equation it will simply reprint the equation. You can approximate a solution, but you have to limit the search to a range, which you might discover by graphing the function or by substituting some values into the function. For example, using $f(x) = {x}^{5} + 4{x}^{3} − 3{x}^{2} + 10$, you might see that $f(0) = 10$ and $f(−2) = −66$, so there must be a root between $0$ and $ − 2$.
︡36367dc9-4c74-46f9-86f6-7daeda21ecde︡{"html": "If Sage can’t solve an equation it will simply reprint the equation. You can approximate\na solution, but you have to limit the search to a range, which you might discover by\ngraphing the function or by substituting some values into the function. For example, using\n$f(x) = {x}^{5} + 4{x}^{3} − 3{x}^{2} + 10$, you might\nsee that $f(0) = 10$ and\n$f(−2) = −66$, so there must be\na root between $0$\nand $ − 2$.\n
"}︡ ︠e579b5f8-a4de-433e-8e1d-507d3560281e︠ solve(x^5+4*x^3-3*x^2+10,x); find_root(x^5+4*x^3-3*x^2+10,-2,0) ︡d5cd4d0b-761c-4ed0-afec-6b674eeb43b1︡︡ ︠2780cab4-56d9-4561-9861-1b64e62729ed︠ find_root(tan(x)==x+1,0,pi/2); ︡b12eff89-283e-4c27-b903-52c07b260418︡︡ ︠65f1e484-d9cc-46a3-96ad-033690f9eb89i︠ %htmlSage will also solve systems of equations; note the square brackets forming a list of equations.
︡b3504f0e-4c9a-4028-a9ee-f15655d3be14︡{"html": "Sage will also solve systems of equations; note the square brackets forming a list of equations.\n
"}︡ ︠442bc022-ab4b-4ed1-a668-0127b007abb8︠ y=var("y"); solve([3*x+5*y==6,4*x-6*y==-8],x,y) ︡4b446249-80aa-4347-914c-0dd87a7d5f64︡︡ ︠ea06f80b-5bc4-4b8a-be49-95d5b6dbb435i︠ %htmlA bit more involved:
︡0c913aea-9524-4d0f-a898-1f5a7538ef32︡{"html": "A bit more involved:\n
"}︡ ︠4ac97619-b1c7-4628-bf85-d86e66f8ec78︠ h1=3*x-6*y-5; h2=-4*x*y+7; solve([h1,h2],x,y); jsmath(_) ︡54bf6fb1-bf33-4da9-82ce-7e45e6c9e0c9︡︡ ︠028424e0-2f7e-4e84-8bec-edbf2eeb2767i︠ %html
Sage can do two and three dimensional graphing. There are many ways to adjust the plots that Sage produces; we’ll cover just the basics here.
It’s easy to plot ordinary one-variable functions.
︡0aa579a7-053e-4d73-8d48-55fdfb435e46︡{"html": "\n
\n
Sage can do two and three dimensional graphing. There are many ways to adjust the plots that Sage\nproduces; we’ll cover just the basics here.\n
It’s easy to plot ordinary one-variable functions.\n
"}︡ ︠5c0b8ca9-e217-40af-98ae-92f4a8184079︠ plot(g,-5,5); ︡aef56263-b531-401d-ba5e-c7a6b50a9ee3︡︡ ︠f2e1b77e-09b0-4b88-a011-305c38101e9ei︠ %htmlThe vertical scale makes it hard to see what’s going on in that graph; you can limit the vertical scale for a better look, using “ymin” and “ymax”.
︡7d6378b9-3e09-4022-8883-a6804b3eec7f︡{"html": "The vertical scale makes it hard to see what’s going on in that graph; you can limit the vertical scale for a\nbetter look, using “ymin” and “ymax”.\n
"}︡ ︠44438f86-df80-434b-819a-b18cdc4450d6︠ plot(g,-5,5,ymax=10); ︡35ff8bce-3acd-40cc-a87f-4793307a9ac7︡︡ ︠29dfb936-f70d-4de8-b2dd-db2f03d76785i︠ %htmlSome functions have vertical asymptotes, but Sage will just connect the dots:
︡517c2758-7905-4d98-9ab7-5e9e341fd4bd︡{"html": "Some functions have vertical asymptotes, but Sage will just connect the dots:\n
"}︡ ︠ece7b26c-a7a0-4001-a25f-914fc1e6fb36︠ plot(1/(x-1),-5,5,ymin=-10,ymax=10); ︡85a95e6b-80c7-4fb6-8cfd-3814eb5ae84c︡︡ ︠4e27e188-5004-4c9b-97a1-b8f1c7492c1di︠ %htmlYou can get rid of the spurious bit in the middle:
︡3636fe53-f890-46ab-8908-8fe2a4d30ea4︡{"html": "You can get rid of the spurious bit in the middle:\n
"}︡ ︠8295fbca-6b7d-4f13-bb99-804740434a4e︠ plot(1/(x-1),-5,5,ymin=-10,ymax=10,exclude=[1]); ︡dfff6e21-96b4-41a5-88f7-985dc1ac1c88︡︡ ︠f920c29c-31c0-4a97-aea4-bcc81ca55108i︠ %htmlYou can also put a list of excluded values in the brackets; try plotting $f(x) = 1∕({x}^{2} − 1)$ between $ − 5$ and $5$.
If you right-click on a plot you can download it as a png image.
You can put multiple plots on the same axes:
︡a98ee8bd-5a9b-4523-a653-099fa82753a5︡{"html": "You can also put a list of excluded values in the brackets; try plotting\n$f(x) = 1∕({x}^{2} − 1)$ between\n$ − 5$ and\n$5$.\n \n \n
If you right-click on a plot you can download it as a png image.\n
You can put multiple plots on the same axes:\n
"}︡ ︠9e8773bb-9a23-4c72-9c59-a0ab7d10fdcd︠ plot([g,1/(x-1)],-5,5,ymin=-110,ymax=20,exclude=[1]); ︡52c89729-fc85-42a1-b99a-975534a05781︡︡ ︠62bc90b5-5791-4ba6-ae1f-6d3f16b389f2i︠ %htmlIt’s often better to do the plots separately but display them together:
︡5fe565f3-bf07-454f-a1fd-a993da289e42︡{"html": "It’s often better to do the plots separately but display them together:\n
"}︡ ︠9b68f3e4-4ec4-4186-976d-1fbeb4e5e330︠ p1=plot(g,-5,5,ymin=-110,ymax=20,color='red') p2=plot(1/(x-1),-5,5,ymin=-110,ymax=20,exclude=[1]) p1+p2 ︡386cd9a6-d768-4003-9cef-115f2c7735d7︡︡ ︠40c65986-2f6c-4176-8742-b2b4bd6eccd5i︠ %htmlSage normally uses different scales on the two axes; you can force it to use the same scales to see the “true shape”.
︡d0a5105c-dc51-41ac-80fa-a61b2617a706︡{"html": "Sage normally uses different scales on the two axes; you can force it to use the same scales to see the “true\nshape”.\n
"}︡ ︠ea41044e-796c-489e-a833-7798b0bd2758︠ (p1+p2).show(aspect_ratio=1) ︡fd7c91c5-d28c-438a-a30d-761be4adde25︡︡ ︠905ca20e-fec9-4c20-93dd-b7b4da8819c6i︠ %htmlHere’s a better example: the line doesn’t look like it has slope 1 in the first graph.
︡6ce80343-eca5-46d7-8794-cc5f5ece8bac︡{"html": "Here’s a better example: the line doesn’t look like it has slope 1 in the first graph.\n
"}︡ ︠cdebcb15-3adb-4d66-9ea1-3d342cad3b4d︠ p1=plot(x+1,-5,5); p1; p1.show(aspect_ratio=1) ︡478e1541-e060-4165-9476-f974a2cfff81︡︡ ︠fe941673-6d77-4f3c-b3c4-a952bd5b1769i︠ %html
Sage will plot functions of two variables in 3D. You can rotate the resulting graph with the mouse: click and hold, then drag. You can change the appearance from a menu that appears when you right-click on the graph. Note especially the stereographic option—try the cross-eyed version. Click on the “Get Image” link for a view that you can download.
︡1d2dafe4-14fb-4eeb-bbd4-77a9239ac202︡{"html": "\n
Sage will plot functions of two variables in 3D. You can rotate the resulting graph with the mouse: click\nand hold, then drag. You can change the appearance from a menu that appears when you right-click on\nthe graph. Note especially the stereographic option—try the cross-eyed version. Click on the “Get Image”\nlink for a view that you can download.\n
"}︡ ︠cd3d11b4-c8f2-4e6b-96e1-7c020b95e801︠ y=var("y"); r=sqrt(x^2+y^2); f=sin(r)/r plot3d(f,(x,-10,10),(y,-10,10)) ︡859fe7ea-219a-47a3-a4dd-ed31cc753524︡︡ ︠d5c4930a-3e90-4edd-b979-f7eb5dd4c93fi︠ %html
You can do plots in polar coordinates.
︡1fbc922d-6bf0-401a-a0c3-2e957b8bac4f︡{"html": "\n
You can do plots in polar coordinates.\n
"}︡ ︠b4757185-d249-465e-87e9-fa76372c7f36︠ polar_plot(1+2*sin(x),-pi,pi); ︡8bc16841-c808-4a82-8572-d0eddc2858fc︡︡ ︠10a65340-00c0-4d16-b8b9-e3b714745287i︠ %htmlSage will do parametric plots in two or three dimensions.
︡a35cb926-74e4-497e-b2ac-60bf755e8ec8︡{"html": "Sage will do parametric plots in two or three dimensions.\n
"}︡ ︠c53a86d6-99ee-4514-a596-7eae0466e44b︠ parametric_plot3d([cos(x),sin(x),cos(6*x)],(x,0,2*pi)) ︡c0b53e51-71ec-4e08-ab02-edd35322a1fc︡︡ ︠feef11d3-67d0-4cca-a623-70d721b6391fi︠ %htmlPlots in polar coordinates are really special examples of parametric plots.
︡cafe4de3-725f-4d78-abf1-7b39b79dcdd9︡{"html": "Plots in polar coordinates are really special examples of parametric plots.\n
"}︡ ︠69c39b12-f05c-468e-93ba-19226e427d68︠ polar_plot(1+cos(x),0,2*pi) ︡77e8f07b-9ca9-49bf-9847-d0785ff540a0︡︡ ︠801bdb38-dad2-4000-a7a7-4985cf0f07cc︠ parametric_plot([cos(x)*(1+cos(x)),sin(x)*(1+cos(x))],(x,0,2*pi)) ︡86e61474-7a4b-468f-8ae1-b3ffc50a115e︡︡ ︠994f0fe1-a56a-478b-9966-4feae140ee91i︠ %htmlYou can also do parametric surface plots:
︡5fb30604-fd4b-49bb-9925-4c222175fa27︡{"html": "You can also do parametric surface plots:\n
"}︡ ︠d5c45c8c-2af6-4bf5-a482-cb778cc48644︠ (u,v)=var("u v") parametric_plot3d([v*cos(2*u),v*sin(2*u),u],(u,0,2*pi),(v,0,1)) ︡b1a6495e-8e55-483e-ac34-e0dca917f036︡︡ ︠cc13a36c-15d1-4b64-aebd-6433226a4ef7i︠ %htmlYou may notice that the edges of this surface appear more polygonal than round; you can change the number of points in either direction on the plot. The $u$ direction is the one we want to increase; the $v$ direction is along radial lines, so a very small value is fine.
︡f965bdd9-6678-4bbe-9c0e-3605840bc1d1︡{"html": "You may notice that the edges of this surface appear more polygonal than\nround; you can change the number of points in either direction on the plot. The\n$u$ direction is the one we\nwant to increase; the $v$\ndirection is along radial lines, so a very small value is fine.\n
"}︡ ︠ad0ac423-d84c-4745-8468-3977fa559fe6︠ (u,v)=var("u v") parametric_plot3d([v*cos(2*u),v*sin(2*u),u],(u,0,2*pi),(v,0,1),plot_points=[200,5]) ︡c38f5454-f664-4c01-bfcf-6d9ea88828bd︡︡ ︠549afba8-b5fd-4f3f-afe6-e8b5afb13560i︠ %htmlHere’s a fancier plot: a sphere inside a cylinder, and the cylinder is partially transparent.
︡995d98f6-e79b-48b9-8965-4baf2b0fb60c︡{"html": "Here’s a fancier plot: a sphere inside a cylinder, and the cylinder is partially transparent.\n
"}︡ ︠b3482639-3f41-4746-882b-66f9af113186︠ (u,v)=var("u v") s=parametric_plot3d([sin(v)*cos(u),sin(v)*sin(u),cos(v)],(u,0,2*pi),(v,0,pi),color='red',aspect_ratio=1) c=parametric_plot3d([v,cos(u),sin(u)],(u,0,2*pi),(v,-1,2),opacity=0.6) s+c ︡6286c74a-2c80-4618-bf0d-56f93cb847cb︡︡ ︠f3de39f7-6ab6-4052-bb45-d8560d25d820i︠ %htmlNote that Sage has a bit of trouble where the cylinder and the sphere meet. You can fix this by cheating a little: make the cylinder just slightly bigger.
︡36fda9f9-e2f3-487e-9482-1303acb050f1︡{"html": "Note that Sage has a bit of trouble where the cylinder and the sphere meet. You can fix this by cheating a\nlittle: make the cylinder just slightly bigger.\n
"}︡ ︠68b6e2b5-1124-4890-a07a-229beeab1c4b︠ (u,v)=var("u v") s=parametric_plot3d([sin(v)*cos(u),sin(v)*sin(u),cos(v)],(u,0,2*pi),(v,0,pi),color='red',aspect_ratio=1) c=parametric_plot3d([v,1.02*cos(u),1.02*sin(u)],(u,0,2*pi),(v,-1,2),opacity=0.6) s+c ︡28e37cb8-9a60-4c2c-ae76-4606663b5e98︡︡ ︠f9e83479-4c4d-4912-923e-1fc955513b1ai︠ %htmlYou can plot quite complicated surfaces using multiple parametric plots together. The intersection of three cylinders of the same size at right angles to one another forms a solid. Note that we have plotted each color as four surfaces when in fact one would do; try plotting just the red surface with a single plot, using the range $(u, 0, 2π)$ and see what happens; can you explain what has gone wrong? You might try adding the original cylinders to this plot, colored appropriately, and partially transparent. First we set up some useful functions.
︡7a57b676-1cca-4021-9f11-c346dd24085c︡{"html": "You can plot quite complicated surfaces using multiple parametric plots together. The intersection of three\ncylinders of the same size at right angles to one another forms a solid. Note that we have plotted each color as\nfour surfaces when in fact one would do; try plotting just the red surface with a single plot, using the\nrange $(u, 0, 2π)$\nand see what happens; can you explain what has gone wrong? You might try adding the original\ncylinders to this plot, colored appropriately, and partially transparent. First we set up some useful\nfunctions.\n
"}︡ ︠3d1070dd-5ad0-4193-968c-43c1ec89faad︠ (x,y,u,t,a,b)=var("x y u t a b") minimum(a,b)=((a+b)-abs(b-a))/2 x=cos(u); y=sin(u) v=t*minimum(sqrt(1-x^2),sqrt(1-y^2)) ︡c2435962-8ab2-44da-aa69-3a1fa5db6a7a︡︡ ︠6a3d4dc3-db9b-462d-b45e-d1adce41df60i︠ %htmlNow notice that each of the colors is essentially the same, with the coordinates plotted against different axes for the different colors.
︡3f0b1489-c954-4967-8b7e-d8ac32058c88︡{"html": "Now notice that each of the colors is essentially the same, with the coordinates plotted against different\naxes for the different colors.\n
"}︡ ︠5fe15e33-c887-4178-bf2d-c6f8671c38f0︠ redsurf1=parametric_plot3d([x,v,y],(u,0,pi/2),(t,-1,1),color='red',aspect_ratio=(1,1,1)) redsurf2=parametric_plot3d([x,v,y],(u,pi/2,pi),(t,-1,1),color='red',aspect_ratio=(1,1,1)) redsurf3=parametric_plot3d([x,v,y],(u,pi,3*pi/2),(t,-1,1),color='red',aspect_ratio=(1,1,1)) redsurf4=parametric_plot3d([x,v,y],(u,3*pi/2,2*pi),(t,-1,1),color='red',aspect_ratio=(1,1,1)) bluesurf1=parametric_plot3d([x,y,v],(u,0,pi/2),(t,-1,1),color='blue',aspect_ratio=(1,1,1)) bluesurf2=parametric_plot3d([x,y,v],(u,pi/2,pi),(t,-1,1),color='blue',aspect_ratio=(1,1,1)) bluesurf3=parametric_plot3d([x,y,v],(u,pi,3*pi/2),(t,-1,1),color='blue',aspect_ratio=(1,1,1)) bluesurf4=parametric_plot3d([x,y,v],(u,3*pi/2,2*pi),(t,-1,1),color='blue',aspect_ratio=(1,1,1)) yellowsurf1=parametric_plot3d([v,x,y],(u,0,pi/2),(t,-1,1),color='yellow',aspect_ratio=(1,1,1)) yellowsurf2=parametric_plot3d([v,x,y],(u,pi/2,pi),(t,-1,1),color='yellow',aspect_ratio=(1,1,1)) yellowsurf3=parametric_plot3d([v,x,y],(u,pi,3*pi/2),(t,-1,1),color='yellow',aspect_ratio=(1,1,1)) yellowsurf4=parametric_plot3d([v,x,y],(u,3*pi/2,2*pi),(t,-1,1),color='yellow',aspect_ratio=(1,1,1)) redsurf1+redsurf2+redsurf3+redsurf4+bluesurf1+bluesurf2+bluesurf3+bluesurf4+yellowsurf1+yellowsurf2+yellowsurf3+yellowsurf4 ︡f27d8a17-56b3-4715-9927-9d9e4da300fd︡︡ ︠e2aa5bf2-89df-40c1-9cc9-7475236e2b70i︠ %html
Sage can compute many typical limits as encountered in calculus. Here’s an easy one, for a continuous function.
︡2f1cb95f-d02e-46f0-add5-613dd6ccdc61︡{"html": "\n
\n
Sage can compute many typical limits as encountered in calculus. Here’s an easy one, for a continuous\nfunction.\n
"}︡ ︠e810cd89-e8d0-46f4-9ea4-fa9758d0fe3c︠ f(x)=x^2+4*x+30 limit(f,x=3); f(3) ︡0156bf70-f94e-4e60-8d9c-16157415cd2b︡︡ ︠0cd9638f-94f8-4f72-901e-0b5c3bcd4cffi︠ %htmlAnd everyone’s favorite non-trivial limit:
︡c9ec9471-308a-420c-8e7e-8e4c6a54cabd︡{"html": "And everyone’s favorite non-trivial limit:\n
"}︡ ︠89ed6810-a878-427b-b478-cbc7488c37c7︠ g(x)=sin(x)/x limit(g,x=0); limit(g,x=infinity) ︡2d6713ed-bae8-41d5-b571-6b66e57d7de1︡︡ ︠f69fa48c-5c96-482d-9d3c-62934a83d571i︠ %htmlYou can specify one-sided limits in two ways.
︡8bf6cc1a-e4d7-403f-98b3-136713b9621f︡{"html": "You can specify one-sided limits in two ways.\n
"}︡ ︠dd4ff007-beab-456d-a169-a3d44c2124e4︠ g(x)=x/abs(x) limit(g,x=0); limit(g,x=0,dir='-'); limit(g,x=0,dir='right') ︡32330b4b-cce0-4420-90c0-3bc5bca5e1eb︡︡ ︠e68b486f-66eb-4ab2-a7b4-2c8e1b4ef2a4i︠ %html
Here’s a typical easy calculus problem: find a derivative, find critical values, find the $y$-coordinates for each.
︡8531a522-7af0-4cca-b385-4bd2c87e4883︡{"html": "\n
Here’s a typical easy calculus problem: find a derivative, find critical values, find the\n$y$-coordinates\nfor each.\n
"}︡ ︠38e6e657-b469-4d97-8a1f-ccdc50c5e135︠ f(x)=x^3+4*x^2+3*x+4 fp=diff(f) critvals=solve(fp,x,solution_dict=True) f; fp; critvals; jsmath([expand(f(s[x])) for s in critvals]) ︡8ece0736-f535-41a0-bfe6-954f7d9750f5︡︡ ︠7dd3e91e-a824-4bfe-b39d-1036a89b0257i︠ %html
Sage has no built-in implicit differentiation command, but we can do it using differentiation, in essentially the way we do it by hand. We tell Sage that $y$ is a function of $x$, then proceed essentially as usual. Here is the standard example computing $y' = −x∕y$ for $y$ defined by ${x}^{2} + {y}^{2} = 1$. Note that we convert this to ${x}^{2} + {y}^{2} − 1 = 0$, which guarantees that the derivative of the right side is zero. (In this case the derivative of the right side, 1, was already zero, but in general it might be more complicated.)
︡bcc8a0a5-667b-4804-a17a-8a52f373176b︡{"html": "\n
Sage has no built-in implicit differentiation command, but we can do it using\ndifferentiation, in essentially the way we do it by hand. We tell Sage that\n$y$ is a\nfunction of $x$,\nthen proceed essentially as usual. Here is the standard example computing\n$y' = −x∕y$ for\n$y$ defined by\n${x}^{2} + {y}^{2} = 1$. Note that we\nconvert this to ${x}^{2} + {y}^{2} − 1 = 0$,\nwhich guarantees that the derivative of the right side is zero. (In this case the derivative of the right side,\n1, was already zero, but in general it might be more complicated.)\n
"}︡ ︠798f215a-bf30-4370-815f-4409b583a607︠ y=function('y',x) temp=diff(x^2+y^2-1) solve (temp,diff(y)) ︡034155f8-fd02-4186-b5cd-e32b3acbb32d︡︡ ︠6c945cd7-42ef-49ce-a058-57c7c3fced2ei︠ %html
The “integral” command computes an antiderivative. Here, we take the derivative to check the antiderivative.
︡00f6ffba-dd06-49a7-98fc-9899cb8872fc︡{"html": "\n
The “integral” command computes an antiderivative. Here, we take the derivative to check the\nantiderivative.\n
"}︡ ︠c9879e34-6875-43f2-a92f-39825c20ef83︠ f(x)=(2*x-3)*sqrt(x-3) g(x)=integral(f,x) g; diff(g); factor(_) ︡f5ef584b-aefd-4a49-bbf9-ef29a96378c8︡︡ ︠b8a494f8-e29d-47e8-93df-d34c9131708fi︠ %htmlIf Sage can’t handle an integral, it does nothing.
︡3726d9bc-ea66-4156-a208-c75536a90632︡{"html": "If Sage can’t handle an integral, it does nothing.\n
"}︡ ︠5f2bdba0-1cbc-49bc-8343-69a6b1a742f6︠ integral(tan(x^2),x) ︡3b6f5484-fe3a-485f-b98d-d01a6ac09d25︡︡ ︠13d619c3-e780-4585-92be-bef25c9a2408i︠ %htmlWe could of course do definite integration by substituting and subtracting, but the integral command will also do it.
︡eef37010-5bac-4b68-bf22-18afdd29aa17︡{"html": "We could of course do definite integration by substituting and subtracting, but the integral command\nwill also do it.\n
"}︡ ︠f25bd5f8-362e-4ee3-9b1e-8ccccd7d0573︠ integral(f(x),x,5,10); g(10)-g(5) ︡ed9250ab-2111-4f5d-af03-0560c7d6e591︡︡ ︠9098bd9c-d270-40b3-9899-cd02f841d1c0i︠ %htmlSage can do some improper integrals.
︡fe7bc736-8261-48cc-917c-c800673af9f8︡{"html": "Sage can do some improper integrals.\n
"}︡ ︠1ce5c6b7-0ba0-455d-b8cd-23adf7ec9d58︠ f(x)=1/sqrt(x); integral(f(x),x,0,1); integral(f(x),x,1,infinity) ︡8fab4f38-7b2e-4302-b9a5-6b74423a153a︡︡ ︠3f890c63-7486-46d4-bdfb-c970483904d3︠ f(x)=1/x^2; integral(f(x),x,1,infinity) ︡8a2464fd-293f-4ca9-ad39-df6696b18fdf︡︡ ︠0f103547-f502-4aca-b8d7-e8967d544214i︠ %htmlThe function ${e}^{−{x}^{2}}$ doesn’t have a “nice” antiderivative, though it can be expressed in terms of the “erf” function. For most values of $x$, erf(x) can only be approximated, but an improper integral turns out to be quite nice. (The function ${e}^{−{x}^{2}}$ is a Gaussian function, a “bell curve”.)
︡4464566c-963b-491b-bfec-085a02cd8c82︡{"html": "The function ${e}^{−{x}^{2}}$\ndoesn’t have a “nice” antiderivative, though it can be expressed in terms of the “erf” function. For most values\nof $x$,\nerf(x) can only be approximated, but an improper integral turns out to be quite nice. (The function\n${e}^{−{x}^{2}}$ is a\nGaussian function, a “bell curve”.)\n
"}︡ ︠7eb6e498-acc2-47c3-8ae9-25b1b5dfcae3︠ f(x)=exp(-x^2); integral(f,x); integral(f(x),x,0,1); integral(f(x),x,-infinity,infinity) ︡d1a1bc82-11e8-4c83-80a6-a5c5eff5d504︡︡ ︠a786f513-abcc-41eb-8e1e-4535290bd206i︠ %htmlSometimes the result is mysterious.
︡eeb0831f-9bd3-4f9d-a648-37dfac783c0d︡{"html": "Sometimes the result is mysterious.\n
"}︡ ︠3ab99342-dc34-47cb-a98e-4b4cc9fb117f︠ f(x)=sin(x); integral(0,infinity) ︡b71353e0-322c-4e5c-abd0-3a62c8e588c9︡︡ ︠6558e613-108f-4b07-8ed5-b26691347c45i︠ %htmlSage can’t find antiderivatives of some functions. In such cases you can approximate the value of a definite integral using the $n$ function.
︡4487c861-6abc-40ad-acc2-fa834e545594︡{"html": "Sage can’t find antiderivatives of some functions. In such cases you can approximate the value of a definite integral\nusing the $n$\nfunction.\n
"}︡ ︠864846ba-a5fb-4bc4-b340-cb89aa8852c5︠ integral(tan(x^2),x,0,1); n(_) ︡9da7ab47-1864-420e-a930-b1ee7dc37163︡︡ ︠d091afc9-d272-4d70-a40d-bba86652941bi︠ %html
If you click on “Help” at the top of the Sage window, you will find a number of options. There is a tutorial that is longer and more complete than this introduction, and there is a comprehensive reference manual. If you know the command you want help with you can enter “commandname?” in a command box and execute it. Google can also find helpful pages; generally you should search for “sagemath” plus some description of the topic you’re interested in.
︡9b6f4934-4e3e-4a8f-aa2e-7e7413660edd︡{"html": "\n \n \n
If you click on “Help” at the top of the Sage window, you will find a number of options. There is a tutorial\nthat is longer and more complete than this introduction, and there is a comprehensive reference manual. If\nyou know the command you want help with you can enter “commandname?” in a command box and\nexecute it. Google can also find helpful pages; generally you should search for “sagemath” plus some\ndescription of the topic you’re interested in.\n
"}︡ ︠9b4f81bc-bbae-408b-9526-4ff562f5371c︠ plot3d? ︡8c7f525b-25ff-4211-9850-ac57d35977fc︡︡