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

Ray han

Tech Leader | Stanford / Yale University
linkedin profile url

I think that they are fantastic. I attended Yale and Stanford and have worked at Honeywell,Oracle, and Arthur Andersen(Accenture) in the US. I have taken Big Data and Hadoop,NoSQL, Spark, Hadoop... Read More

Relevant Projects

Build Classification Algorithms for Digital Transformation[Banking]
Implement a machine learning approach using various classification techniques in Python to examine the digitalisation process of bank customers.

Time Series Forecasting with LSTM Neural Network Python
Deep Learning Project- Learn to apply deep learning paradigm to forecast univariate time series data.

End-to-End Speech Emotion Recognition Project using ANN
Speech Emotion Recognition using RAVDESS Audio Dataset - Build an Artificial Neural Network Model to Classify Audio Data into various Emotions like Sad, Happy, Angry, and Neutral

Model Deployment on GCP using Streamlit for Resume Parsing
Perform model deployment on GCP for resume parsing model using Streamlit App.

Deep Learning Project for Text Detection in Images using Python
CV2 Text Detection Code for Images using Python -Build a CRNN deep learning model to predict the single-line text in a given image.

Medical Image Segmentation Deep Learning Project
In this deep learning project, you will learn to implement Unet++ models for medical image segmentation to detect and classify colorectal polyps.

NLP Project for Multi Class Text Classification using BERT Model
In this NLP Project, you will learn how to build a multi-class text classification model using using the pre-trained BERT model.

MLOps Project to Deploy Resume Parser Model on Paperspace
In this MLOps project, you will learn how to deploy a Resume Parser Streamlit Application on Paperspace Private Cloud.

Build a Autoregressive and Moving Average Time Series Model
In this time series project, you will learn to build Autoregressive and Moving Average Time Series Models to forecast future readings, optimize performance, and harness the power of predictive analytics for sensor data.

Llama2 Project for MetaData Generation using FAISS and RAGs
In this LLM Llama2 Project, you will automate metadata generation using Llama2, RAGs, and AWS to reduce manual efforts.