Lilly B.

asked • 02/05/23

How do u code this I’m having a really hard time understanding when to use if, else if and else statements?

Write a program that that computes and plots the acceleration profile of racecar. The racecar's acceleration can be approximated as piecewise linear.


a(t)=kt+c


where t is time in seconds, k is the slope of the acceleration profile, and c is the y-intercept of the acceleration profile. The constants change depending on how the accelerator or brake of the vehicle are pressed. They are defined by Equations 2 and 3, with the specified time intervals.


k={ 6m/s^2 0s<=t<=3s

0m/s^2. 3s<=t<=5s

10m/s^2. 5s<=t<=7s

-3.1m/s^2 7s<=t<=10s}


c={ 0m/s^2 0s<=t<=3s

6m/s^2. 3s<=t<=5s

0m/s^2. 5s<=t<=7s

-10.8m/s^2 7s<=t<=10s}



Using the given information, write a script that specifically: Uses a for-loop to compute the time variable and the acceleration variable. Uses an if-elseif-else statement nested inside the for-loop to control which constants are used for the acceleration function. Uses an increment of delta t =- 0.125 seconds between successive points in the time array. • Plots the acceleration profile of the racecar versus tune with a fully documented plot.


Output must be:


An array called "t" for time An array called "A" for acceleration.

1 Expert Answer

By:

Ibrahim M. answered • 03/28/23

Tutor
5 (52)

PhD in Mechanical Engineering with 8 Years of MATLAB coding experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.