volume
Calculate the volume of revolution around the x-axis by providing a mathematical expression and specifying the start and end points for integration.
Instructions
Calculate the volume of revolution around x-axis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| end | Yes | ||
| expression | Yes | ||
| start | Yes |
Implementation Reference
- index.js:159-172 (handler)The handler function implements the disk method for volume of revolution around the x-axis using numerical approximation with 1000 steps and eval for y-value computation.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:149-157 (schema)Schema definition including input parameters (expression, start, end) and output as number.{ 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(),
- index.js:148-173 (registration)The tool 'volume' is registered using ai.defineTool with schema and handler.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; } );