>>  Lectures >>  Matlab 6

 Navigator

## 6.3 Assignment Solutions - Lecture 6

Solution m-files:

 assignment_plot.m
 assignment_mesh.m

### 6.3.1 Part A

The key to this exercise is relating the unit weight of a battery to the amount of power it supplies, which is proportional to the travel time and thus distance travelled.

We begin by creating a new m-file, and we include exercise_batterypower on the first line.

Next, we define the range of weights for the batteries as [1:3000]:

mnew batteries = [1:3000]

A unit battery is of weight 1kg. We can easily compute the amount of Energy in a unit battery by dividing the total Energy in a 9kg battery (from exercise 1) by the weight of the battery (9):

Eunit batteries = Ebatteries total / mbatteries

We can now compute the amount of energy for the range of battery weights by multiplying the range vector by the unit battery weight:

Enew batteries = mnew batteries * Eunit batteries

The total weight for the Segway is the range of battery weights added to the bare weight of the Segway:

msegway = msegway nobat + mnew batteries

At this point, we will re-evaluate equations , , and , which we have used in exercise_batterypower.m. We merely need to copy and paste them into this m-file.

Using equation we can now compute the total time travelled for the Energy in the range of battery weights

ttravelled = Enew batteries / Pfrom batteries

We now convert the range of ttravelled to distance travelled in km:

disttravelled = ttravelled * vkmh2msec(vconst) disttravelled km = disttravelled / 1000

Finally, we plot the result vector disttravelled km over the range of battery weights mnew batteries:

plot(mnew batteries, disttravelled km), xlabel('Weight of Batteries in kg'), ylabel('Distance travelled in km'), title('Weight of batteries vs. distance travelled at constant velocity of 20km/h'), grid

The graph suggests that for an equal amount of additional battery power, the additional distance travelled decreases over time.

### 6.3.2 Part B

In this part of the assignment, we are expanding on what has been computed in Part A, by adding another dimension of variability.

We begin by creating a new m-file, and we include exercise_batterypower on the first line.

Next, we define the range of weights for the batteries and velocities:

mnew batteries = [1:20:3000] vvar = [1:2:100]

Next, we again define a unit battery of 1kg:

Eunit batteries = Ebatteries total / mbatteries

We initialize the result matrix disttravelled km to an empty matrix:

disttravelled km = [ ]

Similar to exercise_mesh, we place the computation for one of the ranges, vvar, in a for loop:

for v=1:length(vvar)

end

We first compute the total weight of the Segway and range of battery weights.

msegway = msegway nobat + mnew batteries

At this point, we will re-evaluate equations 5.3, 5.4, and 5.5, which we have used in exercise 1. We merely need to copy and paste them into this m-file.

Using equation we can now compute the total time travelled for the Energy in the range of battery weights

ttravelled = Enew batteries / Pfrom batteries

We now convert the range of ttravelled to distance travelled in km and store the resulting vector in the matrix.

disttravelled = ttravelled * vkmh2msec(vconst) disttravelled km(v,:) = disttravelled / 1000