Spaces:
Runtime error
Runtime error
File size: 1,526 Bytes
5543e04 95151f6 5543e04 95151f6 db31576 95151f6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import sympy
import gradio as gr
def integral_polynomial(coefficients, c=0):
"""
Calculate the indefinite integral of a polynomial function.
Args:
coefficients (list): List of coefficients from highest to lowest degree
c (float): Integration constant
Returns:
list: Coefficients of the integral polynomial including constant term
"""
result = []
for i, coef in enumerate(coefficients):
power = len(coefficients) - i
result.append(coef / power)
result.append(c) # Add integration constant
return result
integral_interface = gr.Interface(
fn=lambda coefficients, c: integral_polynomial([float(x) for x in coefficients.split(',')], float(c)),
inputs=[
gr.Textbox(label="Polynomial Coefficients (comma-separated, highest degree first)"),
gr.Number(label="Integration Constant (c)", value=0)
],
outputs="json",
title="Polynomial Integration",
description="Find the indefinite integral of a polynomial function.\n\n**Description:**\nThis tool computes the indefinite integral of a polynomial given its coefficients (highest degree first) and an optional constant.\n\n**Examples:**\n- Input: 3,2,1 (represents 3x^2 + 2x + 1), c=0 → Output: [1.0, 1.0, 1.0, 0.0] (represents x^3 + x^2 + x)\n- Input: 4,0,-2, c=5 → Output: [1.333..., 0.0, -2.0, 5.0] (represents (4/3)x^3 - 2x + 5)\n- Input: 7, c=2 → Output: [7.0, 2.0] (represents 7x + 2)",
examples=[["3,2,1",0],["4,0,-2",5],["7",2]],
)
|