z_transform
Compute the Z-transform of a discrete-time function to analyze signals and systems in the frequency domain by specifying the function, time variable, and Z-transform variable.
Instructions
Calculate the Z-transform of a function
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Function of discrete time | |
| limit | No | Upper limit for summation (default: 100) | |
| timeVar | Yes | Discrete time variable | |
| zVar | Yes | Z-transform variable |
Implementation Reference
- index.js:422-438 (handler)The zTransform function implements the core logic for calculating the Z-transform of a discrete-time function using a finite series approximation up to the specified limit.const zTransform = (expr, n, z, limit = 100) => { try { const node = math.parse(expr); let result = math.complex(0, 0); for (let k = 0; k <= limit; k++) { const scope = { [n]: k }; const fn = math.evaluate(node, scope); const zTerm = math.pow(z, -k); result = math.add(result, math.multiply(fn, zTerm)); } return result.toString(); } catch (e) { return `Error: ${e.message}`; } };
- index.js:473-488 (registration)Registers the 'z_transform' tool using ai.defineTool, specifying name, description, input and output schemas, and an async handler that invokes the zTransform function.ai.defineTool( { name: 'z_transform', description: 'Calculate the Z-transform of a function', inputSchema: z.object({ expression: z.string().describe('Function of discrete time'), timeVar: z.string().describe('Discrete time variable'), zVar: z.string().describe('Z-transform variable'), limit: z.number().optional().describe('Upper limit for summation (default: 100)') }), outputSchema: z.string(), }, async ({ expression, timeVar, zVar, limit = 100 }) => { return zTransform(expression, timeVar, zVar, limit); } );
- index.js:477-483 (schema)Zod schema definition for the z_transform tool inputs (expression, timeVar, zVar, optional limit) and string output.inputSchema: z.object({ expression: z.string().describe('Function of discrete time'), timeVar: z.string().describe('Discrete time variable'), zVar: z.string().describe('Z-transform variable'), limit: z.number().optional().describe('Upper limit for summation (default: 100)') }), outputSchema: z.string(),