volume
Calculate the volume of revolution around the x-axis for a given mathematical expression between specified start and end points.
Instructions
Calculate the volume of revolution around x-axis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | ||
| start | Yes | ||
| end | Yes |
Implementation Reference
- index.js:159-172 (handler)The handler function implements the volume of revolution calculation around the x-axis using the disk method. It approximates the integral numerically with 1000 steps, evaluating the given expression at each point to compute pi * y^2 * dx.async ({ expression, start, end }) => { // Volume of revolution using disk method const steps = 1000; const dx = (end - start) / steps; let volume = 0; for (let i = 0; i < steps; i++) { const x = start + i * dx; const y = eval(expression.replace(/x/g, `(${x})`)); volume += Math.PI * y * y * dx; } return volume; }
- index.js:152-157 (schema)Defines the input schema requiring a mathematical expression (string), start and end x-values (numbers), and output schema as a number representing the computed volume.inputSchema: z.object({ expression: z.string(), start: z.number(), end: z.number() }), outputSchema: z.number(),
- index.js:148-173 (registration)Registers the 'volume' tool using ai.defineTool, including its name, description, schema, and handler function.ai.defineTool( { name: 'volume', description: 'Calculate the volume of revolution around x-axis', inputSchema: z.object({ expression: z.string(), start: z.number(), end: z.number() }), outputSchema: z.number(), }, async ({ expression, start, end }) => { // Volume of revolution using disk method const steps = 1000; const dx = (end - start) / steps; let volume = 0; for (let i = 0; i < steps; i++) { const x = start + i * dx; const y = eval(expression.replace(/x/g, `(${x})`)); volume += Math.PI * y * y * dx; } return volume; } );