How to solve an equation in Sympy

This recipe helps you solve an equation in Sympy

Recipe Objective - How to solve an equation in Sympy?

Sympy provides solve() function, which can be used to solve an equation.

For more related projects -

https://www.projectpro.io/projects/data-science-projects/tensorflow-projects
https://www.projectpro.io/projects/data-science-projects/keras-deep-learning-projects

Example:

# Example 1:

# Importing libraries
from sympy import pprint, solve
from sympy.abc import p,q

# Defining some expression
exp1 = (2*(p**2)-8)

# Printing both expression
pprint(exp1)

# Finding the value of p using solve function.
print("Values of p => ",solve(exp1,p))

Output - 
   2    
2.p  - 8
Values of p =>  [-2, 2]

# Example 2:

# Importing libraries
from sympy import pprint, solve
from sympy.abc import p,q

# Defining some expression
exp1 = (p**2)-(4*p)+1

# Printing both expression
pprint(exp1)

# Finding the value of p using solve function.
print("Values of p => ",solve(exp1,p))

Output - 
 2          
p  - 4.p + 1
Values of p =>  [2 - sqrt(3), sqrt(3) + 2]

In this way, we can solve an equation in sympy.

What Users are saying..

profile image

Anand Kumpatla

Sr Data Scientist @ Doubleslash Software Solutions Pvt Ltd
linkedin profile url

ProjectPro is a unique platform and helps many people in the industry to solve real-life problems with a step-by-step walkthrough of projects. A platform with some fantastic resources to gain... Read More

Relevant Projects

Deploy Transformer-BART Model on Paperspace Cloud
In this MLOps Project you will learn how to deploy a Tranaformer BART Model for Abstractive Text Summarization on Paperspace Private Cloud

Build a Multi Class Image Classification Model Python using CNN
This project explains How to build a Sequential Model that can perform Multi Class Image Classification in Python using CNN

Multi-Class Text Classification with Deep Learning using BERT
In this deep learning project, you will implement one of the most popular state of the art Transformer models, BERT for Multi-Class Text Classification

Machine Learning Project to Forecast Rossmann Store Sales
In this machine learning project you will work on creating a robust prediction model of Rossmann's daily sales using store, promotion, and competitor data.

Learn to Build a Polynomial Regression Model from Scratch
In this Machine Learning Regression project, you will learn to build a polynomial regression model to predict points scored by the sports team.

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

AWS MLOps Project to Deploy Multiple Linear Regression Model
Build and Deploy a Multiple Linear Regression Model in Python on AWS

Build Regression (Linear,Ridge,Lasso) Models in NumPy Python
In this machine learning regression project, you will learn to build NumPy Regression Models (Linear Regression, Ridge Regression, Lasso Regression) from Scratch.

Learn to Build an End-to-End Machine Learning Pipeline - Part 1
In this Machine Learning Project, you will learn how to build an end-to-end machine learning pipeline for predicting truck delays, addressing a major challenge in the logistics industry.