Solving Systems Of Equations Using Sympy And Numpy (Python)

  Рет қаралды 76,969

Andrew Dotson

Andrew Dotson

6 жыл бұрын

In this video I go over two methods of solving systems of linear equations in python. One method uses the sympy library, and the other uses Numpy.

Пікірлер: 94
@vtrandal
@vtrandal Жыл бұрын
With gratitude, I thank you for making this video. You are a trailblazer. Following you is a blessing.
@TymeToTry
@TymeToTry 6 жыл бұрын
You've made a typo in your first system of equations. You wrote: eq2 = Eq(3*x-1,-2) It should be: eq2 = Eq(3*x - y, -2) The first system yields x = -1/3 (3x = -1 => x = -1/3) and thus y = 11/3 The second system yields x = 2 and y = 8. Hope that helps!
@stormbrakerable
@stormbrakerable 5 жыл бұрын
Thanks so much! This has been a great help! My uni also uses python for physics programming so thanks again and do more python videos, please :)
@BiancaAguglia
@BiancaAguglia 5 жыл бұрын
0:00 "What's going on, smart people!" - There. That's where you lost me. 😀 Just kidding. Nice video. I didn't know about the latex trick. Thank you for sharing.
@jingyiwang4931
@jingyiwang4931 5 жыл бұрын
Really helpful. BTW, I like your hair style~!!LOL
@davidsanjenis2778
@davidsanjenis2778 3 жыл бұрын
Great tutorial! Your channel is easily becoming my favorite! :D
@rahulkumarjha5125
@rahulkumarjha5125 3 жыл бұрын
Andrew you just made my day . I was on rank 7 in code chef contest and used this method to solve the equation of degree 4 and got the 4th rank. Love you bro ❤
@methorogood
@methorogood 7 ай бұрын
This is an excellent video. It helped me a ton!!! Thank you.
@monicapym8948
@monicapym8948 2 жыл бұрын
Great video!! I definitely enjoyed it and learned a couple of things!!
@gustavagerbo3236
@gustavagerbo3236 6 жыл бұрын
This is so helpful. Thanks.
@oldelkhot
@oldelkhot 5 жыл бұрын
Thanks for the video. I was looking for an easy way to find the initial guess for a poly nomial in order to solve the equation by fsolve from scipy.optimize and importing numpy!
@cradleofrelaxation6473
@cradleofrelaxation6473 Жыл бұрын
Nice! I love it!!
@admiralhyperspace0015
@admiralhyperspace0015 3 жыл бұрын
Woah, I didn't know you used to make these videos too. Awesome make more, Thanks.
@interiorarttv8449
@interiorarttv8449 3 жыл бұрын
Thank You! that was so helpful
@MathPhysicsFunwithGus
@MathPhysicsFunwithGus 3 жыл бұрын
Great video!!!! Thank you!
@googacct
@googacct 4 жыл бұрын
Nice video. Since this video is over a year old, you may have figured this out by now. Using control-Enter is the same as having to move your mouse to click on run.Use that for about 10 minutes and it will become instinct. The little bit of time saved can add up over a long coding session.
@merryjoy48
@merryjoy48 5 жыл бұрын
You look like Ryan Reynolds. Very informative vid.
@kamehamehaDdragon
@kamehamehaDdragon 6 жыл бұрын
I did a Java program that solves matrices using Gauss-Jordan, can't wait to learn python, muh friendlier language for math.
@nikhilnambiar454
@nikhilnambiar454 5 жыл бұрын
Hey can you integrate (3x^2 + 1) using this library to get output as x^3 + x? If so, can you explain the procedure for this? Needed help for this asap
@AzriRich88
@AzriRich88 5 жыл бұрын
cool done watch until end.
@advaittrivedi5905
@advaittrivedi5905 4 жыл бұрын
Awesome bro
@0mon0zz
@0mon0zz 3 жыл бұрын
What are the main advantages and disadvantages of using either sympy or numpy? Great video btw!
@abdelrhmandameen2215
@abdelrhmandameen2215 3 жыл бұрын
Great stuff, i''m just wondering why you didnt use numpy.array when solving the equ with numby?
@philiperiskallaleal6010
@philiperiskallaleal6010 4 жыл бұрын
Dear Andrew Dotson, Thank you for your video. Most helpful. I was wondering if, perhaps, you could post some tips/techniques for evaluating the stability of ODE using Python. Recently, there has been great development in that field using Python. One example is the LMFIT Python's library, which is most straitfoward for modelling linear and non-linear syatems. Nevertheless, we still lack a proper method for evaluating stability in an ODE system.
@atrumluminarium
@atrumluminarium 4 жыл бұрын
It's easy to figure out most of the time. The equilibrium points are wherever the vector *y'* = *0* which for ODEs quadratic in *y* can be solved similarly to the method shown here. Then for stability if I remember correctly you linearise the system around the equilibrium points to obtain an equation *y'* = *Ay* And then you find det *A* , Tr *A* and follow this diagram: en.m.wikipedia.org/wiki/Stability_theory#/media/File%3AStability_Diagram.png
@x17exeventien79
@x17exeventien79 6 жыл бұрын
Have you tried the "Successive Over-Relaxation" method? It's an iterative method with a convergence parameter, it solves large matrices MUCH faster than Gauss-Jordan does. When you get to doing Finite Difference Methods with grids in the millions, that performance matters!
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
I've heard of it but never used it! I'll have to think of some ways to try it out!
@andrewrezendes
@andrewrezendes 6 жыл бұрын
I refuse to pronouce Numpy anything but Noom-pee. If I can't say Noom-pee, I don't wanna play.
@hotamohit
@hotamohit 5 жыл бұрын
num as in number, py as in python
@aminoffline
@aminoffline 5 жыл бұрын
thx for video i need to solve problem it look easy but it isn't i wanna use sympy or numpy honestly it dosn't matter any thing that solves it my equation has one variable but one is one side and the other is on other side and it wont come to other side easily cause it buried under 4 or 5 heavy Denominator so is there a way i can solve this ? if u know how plz help me ps: i will bookmark this page to look for your answers
@weigengpeng105
@weigengpeng105 6 жыл бұрын
what do you think i should learn first cpp or py if i want to study physics in the future? and why? thank you love your videos!
@zoltankurti
@zoltankurti 6 жыл бұрын
weigeng peng I would say learn the basics of cpp, and than you can move on quickly. If you don't know much about programming, python is like black magic, I don't think one could understand what's going on behind the scenes. However, in cpp you can see all the steps.
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
I agree with Zoltan. C++ taught me what exactly was going on behind the scenes, and python taught me that maybe I don't need to specify every little semi colon to know what I'm doing.
@frodobaggins3974
@frodobaggins3974 4 жыл бұрын
cpp - you will learn a lot about computers, and how they work under the hood. However, you will also discover that even simple things take a long time to code, and the learning curve will be quite steep. Python is a beginner friendly language, which allows you to focus on the logic of your program, and does many things in the background that you don't need to worry about, which makes code development fast, much faster than C. If you have no programming experience, I would recommend Python first, and then - if you still need to dive deeper - you could always learn cpp. C libraries can be imported into Python as modules, so it is possible to 'combine' both languages - Python for high-level abstraction and cpp for code execution speed. It's not uncommon these days to write a prototype of a programme in Python, test the logic, see how it works, debug, and then rewrite the final version in cpp. Anyway, if you think seriously about studying physics, make sure you learn maths first - this is the ultimate foundation of physics and IT!
@MagnusAnand
@MagnusAnand 4 жыл бұрын
Good video
@selimcanpolat8664
@selimcanpolat8664 3 жыл бұрын
blue looks really good on you
@Mark00747
@Mark00747 5 жыл бұрын
how can I assign the values to the variables?
@rickandelon9374
@rickandelon9374 5 жыл бұрын
Yup!! Cheers!
@yazadjabbarc
@yazadjabbarc 4 жыл бұрын
Can we solve set of ODE numerically using python if we have supporting data in an Excel sheet, then would you please teach!!
@chrislee4531
@chrislee4531 4 жыл бұрын
Would help if you had the code written out so we don't have to re-invent the wheel and type it all out?
@rose_z_m
@rose_z_m 5 жыл бұрын
thanks
@davikbl
@davikbl 5 жыл бұрын
Great learn it from a super Saiyajin!
@ashutoshsharma1640
@ashutoshsharma1640 4 жыл бұрын
what is the error in attribution for printing.int_printing(use_latex=True)
@moss3828
@moss3828 3 жыл бұрын
he said whats up smart people... that immediately told me this wasnt the place for me lmao
@MagnusAnand
@MagnusAnand 5 жыл бұрын
Is it possible to solve this with a step by step solution? Like Wolfram Alpha does?
@Troglodyte2021
@Troglodyte2021 3 жыл бұрын
Can we do Gaussian Elimination with Sympy and/or Numpy?
@LucasDimoveo
@LucasDimoveo 4 жыл бұрын
Do you know of any good tutorials on how to get Sympy and Numpy into Jupyter Notebooks?
@ABSP5766
@ABSP5766 3 жыл бұрын
if you have Anaconda installed there is nothing you need to do. Both Numpy and Sympy (and many oyher packages) are already preinstalled. Just open your jupyter notebook and import them as in this tutorial.
@ianmcpherson5435
@ianmcpherson5435 5 жыл бұрын
print Statement must be surrounded in(" parenthesis") for upto date working!!
@0mon0zz
@0mon0zz 3 жыл бұрын
Thank you!
@MianAffanAli
@MianAffanAli 3 жыл бұрын
Love from *_Pakistan_* !
@piyomaru479
@piyomaru479 4 жыл бұрын
Hello Andrew Dotson!😇 I've been struggling with running codes in python? After I watched your video, maybe you can help me to complete my homework which is all about Systems of Nonlinear Equation? I wish you would notice me. 😊 Godbless you and your youtube channel. More power to you.😇💯
@atrumluminarium
@atrumluminarium 4 жыл бұрын
What's your python version and what's the error? Do you have the libraries (sympy and numpy) installed?
@detroit1988
@detroit1988 3 жыл бұрын
Do You know the trick to add space between variables in latex if I use it? Example "a, b = sp.symbols('a b'); a*b; will give "ab". So I prefer "a b". I have a solution : "a, b = sp.symbols('a~ b~'); but do You know something better ?
@jeremycornish-ford2435
@jeremycornish-ford2435 2 жыл бұрын
Saw your hair all messy, instantly knew the person of the video is smart. Thanks bro. lol jk
@Hunar1997
@Hunar1997 5 жыл бұрын
Why not just: display(sp.Matrix([[2,-1,-4],[3,-1,-2]]).rref())
@captainlongtree6827
@captainlongtree6827 4 жыл бұрын
How would you code this if you wanted to do everything from scratch?
@tonynguyen8166
@tonynguyen8166 4 жыл бұрын
Depends u can use pprint but that doesn't show ur equation in latex. Reason sympy package is use is to show ur equations readable as latex.
@linachka123
@linachka123 4 жыл бұрын
hi good stuff can you please take for example lorentz or duffing nonliner system thanks
@frodobaggins3974
@frodobaggins3974 4 жыл бұрын
SymPy nsolve will bulldozer through non-linear systems using the Newton-Raphson method (as long as you provide realistic starting points...)
@kevinja2436
@kevinja2436 3 жыл бұрын
What’s does sp.function() I removed it and it still worked 😅
@belaidabdelhadi
@belaidabdelhadi 3 жыл бұрын
The second row be : [3 . 0 . -1]
@linachka123
@linachka123 4 жыл бұрын
I want to see how you do it with sympy thank in advance
@Krath1988
@Krath1988 3 жыл бұрын
Can you please tell me how I can solve something like this: A = 12911 eq1 = Eq(A+y-x, 12912) eq2 = Eq(eq1+y1-x1, 12333 )
@prasoonpandey1184
@prasoonpandey1184 6 жыл бұрын
Can you make the font size a little bigger?
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
I'll keep that in mind next time. I wasn't thinking about someone not using fullscreen when I made the video, but of course people wouldn't be using full screen.
@prasoonpandey1184
@prasoonpandey1184 6 жыл бұрын
Thanks for the reply, Andrew. Actually, I watch your videos on my phone and thus even when I go full screen, I have to look closely. I thought that there may be other people like me who have small sized mobile devices. So, I thought to mention that once.
@surajshukla4031
@surajshukla4031 5 жыл бұрын
When I import sympy it gives error ..That no moduled named sympy....Why??
@gustavom8726
@gustavom8726 4 жыл бұрын
go to CMD type pip install sympy
@MarcoACto
@MarcoACto 6 жыл бұрын
Have you ever tried Matlab or Scilab or Octave?
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
Yeah I've used matlab. I prefer python. Never tried the others
@andrewrezendes
@andrewrezendes 6 жыл бұрын
Sage and Python are pretty sweet. Matlab and Mathematica def. have uses though.
@MarcoACto
@MarcoACto 6 жыл бұрын
Sure it all comes down to personal preference and the situation in the end. I use matlab, python and javascript for different things
@bigh8438
@bigh8438 Жыл бұрын
great vid. looks slow after you run it though ngl
@leonardocabrera9253
@leonardocabrera9253 2 жыл бұрын
Hey someone know how to put initial conditions to calculate 𝐶1 and 𝐶2, and how to plot results, from sympy.interactive import printing printing.init_printing(use_latex=True) from sympy import * import sympy as sp x = sp.symbols('x') f = sp.Function('f')(x) diffeq = Eq(f.diff(x,x) -5*f,x) # initial condition f0 = 5 # time points x = np.linspace(0,20) display(diffeq) dsolve(diffeq,f)
@jacktorrance2336
@jacktorrance2336 Жыл бұрын
I didn't know Ryan Reynolds knew Sympy
@frodobaggins3974
@frodobaggins3974 4 жыл бұрын
Hm... Can we really say that SymPy and NumPy are equivalent when it comes to solving equations? One is based on symbolic algebra and the other one does calculations on raw numbers. Simple equations, where we already know the solution algorithm, can be solved with NumPy. Non-linear systems, where no variable or constant matrices may be easily defined, rely on SymPy. Also, SymPy non-linear solvers (numeric methods) are much more refined than NumPy. I would suggest using NumPy for complex math and array operations (also consider that NumPy is compatible with Numba - and may run with machine code speed), and relying on SymPy to solve equations where necessary.
@martinhopaour5744
@martinhopaour5744 6 жыл бұрын
this dude has like one dislike per 5 videos
@AndrewDotsonvideos
@AndrewDotsonvideos 6 жыл бұрын
Oh don't worry it will come
@mazenhazem5427
@mazenhazem5427 3 жыл бұрын
x=3 y=-1 g=Matrix([[x],[y]]) for i in range(len(g)): for k in range(0,3): d=g[[x],[y]] - j_inv[[x],[y]]*F[[x],[y]] g[[x],[y]]=d[[x],[y]] print(d) ################################### Hello there, i need to fill the equation in the for loop with the ( [x and y values] of the matrix g at each iteration) at the second loop iteration the value of the equation of d(which should became a matrix after the first loop result) needed to replace the values(3,-1) of g. Finally, i need to do this process 3 times and print a schedule of x and y values at each iteration how do i do it
@TheHackysack
@TheHackysack 4 жыл бұрын
Shut up, Ryan Reynolds. I can't focus on the math. (EDIT: Ah, well, I should have known I wasn't going to be the only person to say that. Still, though. You could pass as his more serious cousin, Bryan Reynolds.)
@codeWithBatta
@codeWithBatta 4 жыл бұрын
what if this does not have any solution
@frodobaggins3974
@frodobaggins3974 4 жыл бұрын
You get an empty list.
@KattarJ
@KattarJ 5 жыл бұрын
Graph it out bro.
@AAAAAAAAAAAAAAAAAAAAHH
@AAAAAAAAAAAAAAAAAAAAHH 4 жыл бұрын
the sp.Function lines are unnecessary
@sayanjitb
@sayanjitb 3 жыл бұрын
please share your code here!
@goldenpheasant5973
@goldenpheasant5973 4 жыл бұрын
I got wrong result
4 жыл бұрын
guy you are genius, but your face does not convey any sort of code to us, plz reduce your face and increase the code detail, have a good day sir
@Me-og5iy
@Me-og5iy 3 жыл бұрын
I see why there are so many females in the comment section
@skordemaskin
@skordemaskin 4 жыл бұрын
useless, looking for trigonometric system of equations, not a simple linear one which can be found all over the internet. Really no need for a dragged out 15 minute video on it
@AndrewDotsonvideos
@AndrewDotsonvideos 4 жыл бұрын
If you already know how to solve the linear systems, then you wouldn't look up the video in the first place. To others it's not dragged out, it's thorough. Sorry it wasn't what you were looking for.
@skordemaskin
@skordemaskin 4 жыл бұрын
@@AndrewDotsonvideos I didnt look up how to solve linear equations, I searched for trigonometric ones and your video came up first as your title is called "Systems of Equations" which can mean both linear and complex ones, I had no Idea until I watched it you was just using generic 'linear' examples. Im needing to solve for x and y in the equations, tan(x) - y = 0 cos(x) - 3sin(y) = 0 Also youre videos aren't useless, ive watched many in the past, that was just spur of the moment frustration as i've been trying to crack this question for serveral hours now and no luck. Not sure if im missing something or what.
@selimcanpolat8664
@selimcanpolat8664 3 жыл бұрын
blue looks really good on you
@leonardocabrera9253
@leonardocabrera9253 2 жыл бұрын
Hey someone know how to put initial conditions to calculate 𝐶1 and 𝐶2, and how to plot results, from sympy.interactive import printing printing.init_printing(use_latex=True) from sympy import * import sympy as sp x = sp.symbols('x') f = sp.Function('f')(x) diffeq = Eq(f.diff(x,x) -5*f,x) # initial condition f0 = 5 # time points x = np.linspace(0,20) display(diffeq) dsolve(diffeq,f)
NumPy vs SciPy
7:56
IBM Technology
Рет қаралды 33 М.
Solving Equations Symbolically And Using LaTeX In Python!
9:49
Andrew Dotson
Рет қаралды 68 М.
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 110 МЛН
تجربة أغرب توصيلة شحن ضد القطع تماما
00:56
صدام العزي
Рет қаралды 39 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 139 МЛН
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 41 МЛН
Monte Carlo Integration In Python For Noobs
15:32
Andrew Dotson
Рет қаралды 149 М.
21. 4 ways to solve systems of nonlinear equations in python
11:38
Taylor Sparks
Рет қаралды 19 М.
1st Year Calculus, But in PYTHON
32:13
Mr. P Solver
Рет қаралды 121 М.
SymPy is REVOLUTIONARY For Mathematical Tasks
25:15
NeuralNine
Рет қаралды 67 М.
SymPy Tutorial (2022): For Physicists, Engineers, and Mathematicians
1:07:59
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 730 М.
Derivatives In PYTHON (Symbolic AND Numeric)
17:37
Mr. P Solver
Рет қаралды 46 М.
Curve Fitting in Python (2022)
24:50
Mr. P Solver
Рет қаралды 89 М.
Python Symbolic and Numeric Solutions
16:15
APMonitor.com
Рет қаралды 16 М.
Оказался НЕНУЖНЫМ и Его БРОСИЛИ🐶💀
0:38
ИССЛЕДОВАТЕЛЬ
Рет қаралды 4,7 МЛН
ЧТО НАМ ПОПАЛОСЬ?😜😜😜
0:12
Chapitosiki
Рет қаралды 1,1 МЛН
МЛАДШАЯ СЕСТРА И МОРОЖЕНОЕ ИЗ АРБУЗА
0:41
ОЛЯ ПЕРЧИК
Рет қаралды 2,5 МЛН
How is it possible? 😅 #behindthescenes? #vfx
0:19
The Quinetto's
Рет қаралды 43 МЛН