calculate_hookes_law
Calculate spring force and elastic potential energy using Hooke's Law. Input spring constant and displacement to get restoring force and stored energy.
Instructions
Calculate spring force using Hooke's Law: F = -kx.
The restoring force is proportional to displacement from equilibrium.
Fundamental for springs, elastic materials, and simple harmonic motion.
Args:
spring_constant: Spring constant k in N/m (stiffness)
displacement: Displacement from equilibrium in meters
Returns:
Dict containing:
- force: Restoring force magnitude in Newtons
- potential_energy: Elastic potential energy in Joules
Tips for LLMs:
- Stiffer spring → larger k → more force for same displacement
- Potential energy stored in spring: PE = (1/2)kx²
- Negative sign in F = -kx means force opposes displacement
Example - Compressing a car spring:
result = await calculate_hookes_law(
spring_constant=10000, # N/m (stiff car spring)
displacement=0.05 # 5cm compression
)
# Force = 500 N, PE = 12.5 J
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| spring_constant | Yes | ||
| displacement | Yes |
Implementation Reference
- MCP tool wrapper for calculate_hookes_law. Decorated with @tool, accepts spring_constant and displacement as float parameters, delegates to the core calculation function via the 'from ..oscillations import' path.
@tool # type: ignore[arg-type] async def calculate_hookes_law( spring_constant: float, displacement: float, ) -> dict: """Calculate spring force using Hooke's Law: F = -kx. The restoring force is proportional to displacement from equilibrium. Fundamental for springs, elastic materials, and simple harmonic motion. Args: spring_constant: Spring constant k in N/m (stiffness) displacement: Displacement from equilibrium in meters Returns: Dict containing: - force: Restoring force magnitude in Newtons - potential_energy: Elastic potential energy in Joules Tips for LLMs: - Stiffer spring → larger k → more force for same displacement - Potential energy stored in spring: PE = (1/2)kx² - Negative sign in F = -kx means force opposes displacement Example - Compressing a car spring: result = await calculate_hookes_law( spring_constant=10000, # N/m (stiff car spring) displacement=0.05 # 5cm compression ) # Force = 500 N, PE = 12.5 J """ from ..oscillations import HookesLawRequest, calculate_hookes_law as calc_hookes request = HookesLawRequest( spring_constant=spring_constant, displacement=displacement, ) response = calc_hookes(request) return response.model_dump()