Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Polynomial Solver API

A full-stack project that analyzes and solves polynomial equations using a FastAPI backend and a simple interactive frontend.


📌 Features

  • ✅ Accepts polynomial input in two formats:

    • Polynomial string (e.g., x^2 - 5x + 6)
    • Coefficient list (e.g., [1, -5, 6])
  • ✅ Detects:

    • Coefficients
    • Degree
    • Polynomial type (linear, quadratic, cubic, etc.)
  • ✅ Computes:

    • Real roots
    • Complex roots (with real & imaginary parts)
  • ✅ Handles user-friendly input:

    • Supports ^ and converts to **
    • Supports 5x → converts to 5*x
  • ✅ Clean frontend UI for easy interaction


🛠️ Tech Stack

  • Backend: FastAPI
  • Numerical Computation: NumPy
  • Symbolic Parsing: SymPy
  • Frontend: HTML, CSS, JavaScript

📁 Project Structure

poly-api/
│
├── main.py
├── solver/
│   ├── __init__.py
│   └── polynomial.py
│
├── index.html
├── requirements.txt
└── README.md

⚙️ Setup & Installation

1. Clone the repository

git clone <your-repo-link>
cd poly-api

2. Create virtual environment

python -m venv venv

Activate:

  • Windows:
.\venv\Scripts\Activate.ps1
  • Mac/Linux:
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

▶️ Running the Project

Start the backend server

python -m uvicorn main:app --reload

Server will run at:

http://127.0.0.1:8000

Open API Docs

http://127.0.0.1:8000/docs

Run Frontend

Simply open:

index.html

in your browser.


📡 API Endpoints

🔹 POST /analyze

Analyzes polynomial structure.

Input:

{
  "polynomial": "x^2 - 5x + 6"
}

Output:

{
  "coefficients": [1, -5, 6],
  "degree": 2,
  "type": "quadratic"
}

🔹 POST /solve

Solves polynomial and returns roots.

Input:

{
  "polynomial": "x^2 - 5x + 6"
}

Output:

{
  "coefficients": [1, -5, 6],
  "degree": 2,
  "type": "quadratic",
  "roots": [2.0, 3.0]
}

⚠️ Edge Cases Handled

  • Invalid polynomial string
  • Missing input
  • Leading zeros in coefficients
  • Constant polynomials
  • Complex roots

🧠 Key Concepts Used

  • REST API design
  • Input preprocessing & normalization
  • Numerical vs symbolic computation
  • Floating-point precision handling

🎯 Future Scope

  • Graph visualization of polynomial
  • Deployment (Render / Railway)
  • Enhanced UI/UX
  • Authentication (JWT)

👨‍💻 Author

Himanshu Gupta B.E. Computer Science Engineering Chandigarh University


⭐ Acknowledgement

This project demonstrates practical backend development using FastAPI combined with mathematical computation and a simple frontend interface.


About

FastAPI-based REST API to analyze and solve polynomial equations with real and complex roots.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages