Question

I'm trying to model the velocity over time of a given time interval in python, but...

I'm trying to model the velocity over time of a given time interval in python, but my code won't work. I need to solve the problem using the Euler method.

import numpy as np
from matplotlib import pyplot as plt


def car(x0, v0, Cd, p, A, m, facc, T, dt):
    n = 0
    t = np.arange(0, T, dt)
    x = np.array([x0])
    v = np.array([v0])

    while x[n] > 0:
        x = np.append(x, x[n]+v[n]*dt)
        v = np.append(v, v[n]+(facc/m-(1/(2*m))*Cd*A*p*v[n])*dt)
        t = np.append(t, t[n]+dt)
        n += 0
    return x, v, t
0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

Note: Brother sometimes while uploading on HomeworkLib the indentations change. So, I request you to verify it with screenshot once. This is the link where I have saved the code too

https://onlinegdb.com/r1jFFqC9V

import numpy as np
def car(x0, v0, Cd, p, A, m, facc, T, dt):
n = 0
t = np.arange(0, T, dt)
x = np.array([x0])
v = np.array([v0])

while x[n] > 0:
x = np.append(x, x[n]-v[n]*dt)
v = np.append(v, v[n]+(facc/m-(1/(2*m))*Cd*A*p*v[n])*dt)
t = np.append(t, t[n]+dt)
n += 1
return x, v, t
car(1,12,0.8,5,10,5,76,7,0.01)

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
I'm trying to model the velocity over time of a given time interval in python, but...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN PYTHON 3 GIVING THIS CODE %matplotlib inline import numpy as np import matplotlib.pyplot as plt...

    IN PYTHON 3 GIVING THIS CODE %matplotlib inline import numpy as np import matplotlib.pyplot as plt from sklearn import datasets N_samples = 2000 X = np.array(datasets.make_circles(n_samples=N_samples, noise=0.05, factor=0.3)[0]) plt.scatter(X[:,0], X[:,1], alpha=0.8, s=64, edgecolors='white'); Use Spectral Clustering to cluster the points and visualize your result

  • Python, I need help with glob. I have a lot of data text files and want...

    Python, I need help with glob. I have a lot of data text files and want to order them. However glob makes it in the wrong order. Have: data00120.txt data00022.txt data00045.txt etc Want: data00000.txt data00001.txt data00002.txt etc Code piece: def last_9chars(x):     return(x[-9:]) files = sorted(glob.glob('data*.txt'),key = last_9chars) whole code: import numpy as np import matplotlib.pyplot as plt import glob import sys import re from prettytable import PrettyTable def last_9chars(x):     return(x[-9:]) files = sorted(glob.glob('data*.txt'),key = last_9chars) x = PrettyTable() x.field_names =...

  • This is a python matplotlib question. So it would be great if you could show me...

    This is a python matplotlib question. So it would be great if you could show me in python method. I have this loadtxt that asked to plot histogram of wind gusts(column 3) that lie in direction angle(column 2) from min angle to max angle inclusively. I don't know how to include min_angle and max_angle into my codes. Histogram of wind gust speeds As before the file akaroawindgusts.txt contains hourly maximum wind gusts speeds at the Akaroa Electronic weather station (EW)...

  • Python, given a code in class i just need help with the third bullet point ; using a and n (defin...

    Python, given a code in class i just need help with the third bullet point ; using a and n (defined in the second picture of python code) find the first digit for k! for k =1,...,n. you dont have to type in all this code just help me write the code in the first picture where it says: def benford(a): b = [0 for d in range(1,10)] #Do everthything in here return b 2.2 Generating data In this assignment...

  • UPDATED: Hi, I have a problem in PYTHON I've been trying to solve. I'm given two csv files containing data in th...

    UPDATED: Hi, I have a problem in PYTHON I've been trying to solve. I'm given two csv files containing data in the following format of a micro car that moves around: Action, time, speed. (e.g. N,t,s= Move North for t seconds with speed s meters per second) One list is the expected results, the second list is the actual (recorded) results. The car can move N,S,E,W. The data entry will look like this: (CSV files) Expected: Actual: I am trying...

  • I'm trying to use the odeint function or the quad function to integrate my integrand in my calc_H...

    I'm trying to use the odeint function or the quad function to integrate my integrand in my calc_Hmatrix function. however I am not sure what my y0 or my t would need to be in order to get the code to run properly. please help, if more information is needed I can update this post Project1(1) (1) (1) x S ㄨ scipyintegrate.odeint--Sc | + jupyter Project1(1) ()(1r File Edit View Insert Cell Kernel Widgets Help +x4r,수+H.CCode Trusted Python 3 O...

  • Python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt....

    python 1 import matplotlib.pyplot as plt 2 import numpy as np 3 4 abscissa = np.arange(20) 5 plt.gca().set_prop_cycle( ’ color ’ , [ ’ red ’ , ’ green ’ , ’ blue ’ , ’ black ’ ]) 6 7 class MyLine: 8 9 def __init__(self, * args, ** options): 10 #TO DO: IMPLEMENT FUNCTION 11 pass 12 13 def draw(self): 14 plt.plot(abscissa,self.line(abscissa)) 15 16 def get_line(self): 17 return "y = {0:.2f}x + {1:.2f}".format(self.slope, self.intercept) 18 19 def __str__(self):...

  • PLEASE PLEASE PLEASE Explain each part of the solution process. I'm trying to learn this and...

    PLEASE PLEASE PLEASE Explain each part of the solution process. I'm trying to learn this and not just get an answer. I appreciate the help!! A new speedboat with mass m is traveling at v0 at some zero time when its engine is shut off. The magnitude of the frictional force fk between the boat and water is proportional to the speed v of the boat. As an equation, the magnitude of fk is equal to v, where v is...

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

  • python / visual studio Problem 1: Random Walk A random walk is a stochastic process. A...

    python / visual studio Problem 1: Random Walk A random walk is a stochastic process. A stochastic process is a series of values that are not determined functionally, but probabilistically. The random walk is supposed to describe an inebriated person who, starting from the bar, intends to walk home, but because of intoxication instead randomly takes single steps either forward or backward, left or right. The person has no memory of any steps taken, so theoretically, the person shouldn't move...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT