import numpy as np
Write code to print the numbers 0 to 4 on each line below.
i
can be any variable, not just "i"For the ideal gas law, pressure is given by $$P = nRT/V$$
For V = 2, 3, 4, 5, ... 20, use a loop to find and print the values of P for each V.
Add all the numbers from 0 to 100
for
loop. Even another loop.for i in range(3):
print(f"i={i}")
for j in range(4):
print(f" j={j}")
we can use Newton's method to find $x$ for $f(x)=0$.
Excel | Python |
---|---|
cell for guess | ?? |
Newton equation in terms of x cell A2 - (A2^2-3)/(2*A2) |
?? |
repeat: fill down | ?? |
i
is not being used, it is just for convenience in creating the loop.x
is used on both sides of the equation. It is reused.Excel | Python |
---|---|
cell for guess | variable for x |
Newton equation in terms of x cell A2 - (A2^2-3)/(2*A2) |
Newton equation in terms of x x = x - (x**2-3)/(2*x) |
repeat: fill down | repeat: wrap in loop |
# step 1:
# step 2:
# step 3:
# step 4:
Redo Solution 1 using functions for $f(x)$ and $f^\prime(x)$.
Modify the code above to do just the right number of iterations.