create_vector_field
Generate vector fields in a specified coordinate system by defining x, y, and z components, aiding in symbolic mathematics and computational algebra workflows.
Instructions
Creates a vector field in the specified coordinate system.
Args:
coord_sys_name: The name of the coordinate system to use.
component_x: String expression for the x-component of the vector field.
component_y: String expression for the y-component of the vector field.
component_z: String expression for the z-component of the vector field.
Example:
# First create a coordinate system
create_coordinate_system("R")
# Create a vector field F = (y, -x, z)
vector_field = create_vector_field("R", "R_y", "-R_x", "R_z")
Returns:
A key for the vector field expression.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| component_x | Yes | ||
| component_y | Yes | ||
| component_z | Yes | ||
| coord_sys_name | Yes |
Implementation Reference
- server.py:1133-1184 (handler)The core handler function for the 'create_vector_field' MCP tool. It parses string expressions for vector components using SymPy, constructs the vector field in the given coordinate system by scaling base vectors, stores it in the global expressions dictionary with a generated key, and returns the key. The @mcp.tool() decorator registers it as an MCP tool, implicitly defining the input schema via type hints.@mcp.tool() def create_vector_field( coord_sys_name: str, component_x: str, component_y: str, component_z: str ) -> str: """Creates a vector field in the specified coordinate system. Args: coord_sys_name: The name of the coordinate system to use. component_x: String expression for the x-component of the vector field. component_y: String expression for the y-component of the vector field. component_z: String expression for the z-component of the vector field. Example: # First create a coordinate system create_coordinate_system("R") # Create a vector field F = (y, -x, z) vector_field = create_vector_field("R", "R_y", "-R_x", "R_z") Returns: A key for the vector field expression. """ global expression_counter if coord_sys_name not in coordinate_systems: return f"Error: Coordinate system '{coord_sys_name}' not found. Create it first using create_coordinate_system." try: cs = coordinate_systems[coord_sys_name] # Parse the component expressions parse_dict = {**local_vars, **functions, coord_sys_name: cs} x_comp = parse_expr(component_x, local_dict=parse_dict) y_comp = parse_expr(component_y, local_dict=parse_dict) z_comp = parse_expr(component_z, local_dict=parse_dict) # Create the vector field vector_field = ( x_comp * cs.base_vectors()[0] + y_comp * cs.base_vectors()[1] + z_comp * cs.base_vectors()[2] ) # Store the vector field result_key = f"vector_{expression_counter}" expressions[result_key] = vector_field expression_counter += 1 return result_key except Exception as e: return f"Error creating vector field: {str(e)}"