-
-
Notifications
You must be signed in to change notification settings - Fork 197
Solving DC circuits using numpy #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you, @a-elhag ! I'll take a look as soon as possible, please let me know if you have any questions in the meantime. |
So I updated it with I kept the older one for reference (can easily remove it though). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @a-elhag! Thank you for writing this, I think this is a nice tutorial for someone looking to get started, especially if they have such a technical background. I have left a number of comments; please don't be discouraged - most of them are pretty small and simple :) In many cases, I'm using the conventions we have been using for the other tutorials, because this helps keep the content consistent across the repo and makes it easier for users to know what to expect from each document.
Some specific comments:
- I LOVE Pikachu, but I'm not sure if we should include the pictures here. As far as I know, these are copyrighted and even if it could be argued that this is fair use, I think it's safer to drop it.
- In general, we tend to avoid the
admonition
role. It may clutter the page, so we should leave that for really important points that the reader can't miss. Some of my suggestions were moving the content in the admonitions to the main text. - I added a bunch of reference links. Can you check that I added the appropriate ones?
- I'm suggesting we move the proposed exercises to the "on your own" section - I think that's more appropriate and makes the tutorial flow better because the user doesn't feel like they need to stop and do the exercises in the middle of it.
- I suggested this in a few comments but there is a last example where I didn't: whenever you choose specific values to run an example, make it clear to the user that they were chosen arbitrarily. This helps the user understand that they can play with those values and get different results without changing the main point of the analysis.
I think that's everything. Again, thank you for working on this and for considering these suggestions. If you have any questions or comments, let me know. Cheers!
EDIT: just realized that I reviewed the first file - I don't think that's super different from the other one so the comments should be just the same. Sorry about that!
Hey @melissawm, Thanks for taking the time to look through it! I'm here to learn and the more comments the better :) I'm going through the suggestions now, will post an update when I'm done. |
I believe that I addressed each of the concerns, but do let me know if I missed anything. A summary of what was updated:
PS: |
Hey Al, I have a suggestion- what do you think about updating your hand-drawn circuit diagrams? I have an example below of your first diagram. Not a big difference for the first circuit, but I can help with the legibility and layout of the last few diagrams too. I used a combination of an online circuit diagram maker and Photoshop. I could update the rest too. Let me know if you would like this. :) |
Yeah, thanks a lot @MarsBarLee! If you have any questions do let me know. |
@MarsBarLee these look amazing! If you want to you can merge them in to this PR (is that possible?) or I can just do it myself. Thanks for these, mine looked like chicken scratch 😄 |
I looked up how to modify other people's PR (looks like creator would have to check 'Allow edits from maintainers' and I would need to push an edit?), but I think it would be easier for both of us if you did. And no problem, happy to help! |
Co-authored-by: Melissa Weber Mendonça <[email protected]>
@melissawm I rebased the commits and updated the figures. Do let me know if there is anything more that I need to do. And @MarsBarLee, yeah I didn't know if the process was simple or hard. |
Hi @a-elhag ! Finally getting around to this - thanks for your patience! Before doing a thorough review, I think we can get rid of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! You'll probably have to change the links to the images as well because of the folder structure and markdown format. To test if your document renders successfully, go to the site
folder and run make html
(you will have to have sphinx installed and maybe some other dependencies, you can check for those at the requirements.txt
file.) You should also add this entry to the TOC at site/index.md
for sphinx to find it.
Thanks again, @a-elhag !
|
||
### What you'll need | ||
* A "can-do" attitude | ||
* Basic electrical knowledge (Ohm's Law, KCL, KVL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Basic electrical knowledge (Ohm's Law, KCL, KVL) | |
* Basic electrical knowledge (Ohm's Law, [Kirchhoff's Circuit Laws](https://en.wikipedia.org/wiki/Kirchhoff%27s_circuit_laws)) |
Solving for $I$ in *Figure 1* is a pretty trivial matter, it can be done in a | ||
few lines of code. Using `R` to denote the resistance, `V` to denote the | ||
voltage and `I` to denote the current, we have the following: | ||
```python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the way we are converting from ipynb to md, this should be:
```python | |
```{code-cell} ipython3 |
for every cell to be executed in the final notebook. (I won't note the others but I'd do it for every one of them)
The code above is **inefficient**. You generally want to avoid running *for loops* in Python | ||
since they are statically typed and interpreted. In this simple example it won't make much of a difference | ||
but with larger and more complex code it will noticably run worse. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think justifying that loops are since they are statically typed and interpreted. is not correct. I would rather point to an existing resource such as
The code above is **inefficient**. You generally want to avoid running *for loops* in Python | |
since they are statically typed and interpreted. In this simple example it won't make much of a difference | |
but with larger and more complex code it will noticably run worse. | |
The code above is **inefficient**. In scientific applications, you may want to use NumPy's [n-dimensional arrays](https://numpy.org/doc/stable/reference/arrays.ndarray.html), for which [many operations are performed in compiled code for performance](https://numpy.org/doc/stable/user/whatisnumpy.html). In this simple example it won't make much of a difference | |
but with larger and more complex code it will noticably run worse. |
states that maximum power transfer will occur when the resistance of the load (Rload) | ||
equals the resistance of the source (Rth). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put Rload
and Rth
in backticks to make them stand out against the text, but this is just a suggestion.
states that maximum power transfer will occur when the resistance of the load (Rload) | |
equals the resistance of the source (Rth). | |
states that maximum power transfer will occur when the resistance of the load (`Rload`) | |
equals the resistance of the source (`Rth`). |
\begin{equation*} | ||
I_1 (R_1 + R_2) + I_2(-R_2) = V_1 \\ | ||
I_1 (-R_2) + I_2(R_2 + R_3) = V_2 | ||
\end{equation*} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think MyST-NB doesn't understand this LaTeX syntax - I only got it to show successfully with
\begin{equation*} | |
I_1 (R_1 + R_2) + I_2(-R_2) = V_1 \\ | |
I_1 (-R_2) + I_2(R_2 + R_3) = V_2 | |
\end{equation*} | |
$$I_1 (R_1 + R_2) + I_2(-R_2) = V_1 \\ | |
I_1 (-R_2) + I_2(R_2 + R_3) = V_2$$ |
|
||
\begin{equation*} | ||
\begin{bmatrix} R1+R2 & -R2 \\ -R2 & R2+R3 \end{bmatrix} | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use *
for matrix multiplication, use \cdot
instead (please check the other equations)
```python | ||
# x = np.linalg.solve(A, b) | ||
# print(x) | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```python | |
# x = np.linalg.solve(A, b) | |
# print(x) | |
``` | |
Now, | |
```{code-cell} ipython3 | |
--- | |
tags: [raises-exception] | |
--- | |
x = np.linalg.solve(A, b) | |
print(x) |
This tag in the code-cell makes the exception show up in the final document, but doesn't cause errors in the build - which is exactly what we want. Now, you can remove the pasted exception below from the text.
This can be easily confirmed by taking the determinant of $A$: | ||
|
||
``` | ||
Det = np.linalg.det(A) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Det = np.linalg.det(A) | |
np.linalg.det(A) |
inside a code-cell so we can see that the result it 0.0
* In Part 2a Try using voltage division to calculate `Pload` directly | ||
(ie without needing to calculate `Iload`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* In Part 2a Try using voltage division to calculate `Pload` directly | |
(ie without needing to calculate `Iload`) | |
* In Part 2a, try using [voltage division](https://en.wikipedia.org/wiki/Voltage_divider) to calculate `Pload` directly | |
(i. e. without needing to calculate `Iload`) |
@@ -0,0 +1,452 @@ | |||
--- | |||
jupyter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why this line is here, it doesn't show up for the other tutorials. Please check that this header is the same as for the other documents, so we don't have problems with jupytext and mystnb/sphinx.
Hi @a-elhag - do you have any plans to continue work on this PR? |
@a-elhag hello! If you don't have plans to update this tutorial I might take this over just to get the finishing touches and merge. Please let me know what you prefer. Cheers! |
First off I want to thank @melissawm and the numpy team for all the encouragement and motivation!
Reason for writing tutorial:
If you google
how to solve circuits using matlab
, a plethora of results show up. At a cursory glance I counted: 3 books written on the topic, numerous youtube videos and countless articles. On the other hand, googlinghow to solve circuits using numpy
I found only one webpage on the matter. In it they presented a grand total of 3 lines of code and in it they used the soon-to-be deprecatedmatrix
class andinverted
the matrix to solve it:Numpy modules used in the tutorial:
np.array
,np.linspace
,np.argmax
,np.linalg.inv
,np.matmul
,np.linalg.solve
,np.linalg.det
Issues I faced:
MyST
and compiled perfectly withsphinx
, but I had difficulties converting it to.ipynb
.Pikachu
Added a couple of pictures of the lovable Pokemon but I don't know if it is suitable:
It's a very simple fix to remove, so do let me know to that regard.