Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Write a script, named lightning.m, that determines the distance in miles to a

ID: 2268008 • Letter: 1

Question

1. Write a script, named lightning.m, that determines the distance in miles to a lightning strike based on the time elapsed between the flash and the sound of thunder.

The speed of sound is approximately 1100 ft/sec and 1 mile is 5280 ft. If your first thought is to go to MATLAB and start coding, think again.

a) Understand the Problem b) Make a Plan c) Execute the Plan coding happens here, AFTER understanding and planning d) Evaluate the Solution

2. One possible reason to write a script in MATLAB would be to facilitate a computation that you have to repeat on a regular basis. For example, suppose you work for a manufacturer that produces cylindrical fuel tanks. The design engineers typically tell you the dimensions in meters. Sometimes your construction engineers want to know the capacity of the tank in gallons. Now, it’s your turn.

Write a script named tank_capacity.m that a. asks for diameter and length of the tank in meters, and b. outputs the capacity in gallons.

Test your script for different values of diameter and length. The only output to the screen should be the requests for input and the final answer.

Explanation / Answer

Hello,
          Please find the answer attached as under. Please give a thumbs up rating if you find the answer useful! Have a rocking day ahead!
I have answered your first question. All plans, execution and assumption details are explained in the code itself

**** Matlab Code***

%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Lightning.m evaluates distance to lightning

%%%%%Plan : Velocity of sound is known.
%%%%Thus, given the elapsed time, distance is calculated as distance = velocity*time
%%%% Assumption: Lightning is visualised without any delay

%%%%% Execution of the plan is given below%%%%%

elapsed_time = 3 ;              % time elapsed in secs between sighting and hearing of thunder
vel_sound = 1100/5280;          % velocity of sound in air in miles per sec
dist = vel_sound * elapsed_time;    % distance to lightning = velocity * time

fprintf(' Given elapsed time = %f secs, distance = %f miles', elapsed_time,dist)

**** End of Code ***

Output:

Given elapsed time = 3.000000 secs, distance = 0.625000 miles