Aug-12-2018, 12:59 PM
(This post was last modified: Aug-12-2018, 01:14 PM by MrHendrixen.)
Hello Python-forums!
Im new to python and programming. Literally no experiences before so please bear with me.
For a textbook exercise the task goes as follow:
Exercise 1.4: Volumes of three cubes
We are interested in the volume V of a cube with length L: V D L3, computed for
three different values of L.
a) Use the linspace function to compute three values of L, equally spaced on the
interval Œ1; 3.
b) Carry out by hand the computation V D L3 if L is an array with three elements.
That is, compute V for each value of L.
c) In a program, write out the result V of V = L**3 when L is an array with three
elements as computed by linspace in a). Compare the resulting volumes with
your hand calculations.
d) Make a plot of V versus L.
Now...given the past examples, i think I am to use matplotlib as a module for plotting the function of V with respect of the variable V [1,3]. My attempt goes as follows:
Not sure I fully comprehend the actual exercise either...
In advance; thanks
Update:
Fixing my own mathematical mistakes and replacing variable L = 'number' with 'linspace(0,3,10) gives a chart, but I dont understand how, why or IF i fixed my own code.
New code:
Im new to python and programming. Literally no experiences before so please bear with me.
For a textbook exercise the task goes as follow:
Exercise 1.4: Volumes of three cubes
We are interested in the volume V of a cube with length L: V D L3, computed for
three different values of L.
a) Use the linspace function to compute three values of L, equally spaced on the
interval Œ1; 3.
b) Carry out by hand the computation V D L3 if L is an array with three elements.
That is, compute V for each value of L.
c) In a program, write out the result V of V = L**3 when L is an array with three
elements as computed by linspace in a). Compare the resulting volumes with
your hand calculations.
d) Make a plot of V versus L.
Now...given the past examples, i think I am to use matplotlib as a module for plotting the function of V with respect of the variable V [1,3]. My attempt goes as follows:
from numpy import * import matplotlib.pyplot as plt L = 3 t = linspace(0, 30, 100) V = L**3 + L plt.plot(V, L) plt.xlabel('L') plt.ylabel('V(L)') plt.show()BTW im using spyder for writing and plotting this. For some reason it plots (V,L), xlabel and ylabel, but the graph doesnt show up. I tried changing the graphics backend to automatic in preferences. Any clue?
Not sure I fully comprehend the actual exercise either...
In advance; thanks
Update:
Fixing my own mathematical mistakes and replacing variable L = 'number' with 'linspace(0,3,10) gives a chart, but I dont understand how, why or IF i fixed my own code.
New code:
from numpy import * import matplotlib.pyplot as plt L =linspace(0, 3, 4) V = L**3 plt.plot(V, L) plt.xlabel('L') plt.ylabel('V(L)') plt.show()