>>  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]

 Figure 6.34 Click image to enlarge, or click here to open
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

 Figure 6.35 Click image to enlarge, or click here to open
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

 Figure 6.36 Click image to enlarge, or click here to open
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

 Figure 6.37 Click image to enlarge, or click here to open
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.

 Figure 6.38 Click image to enlarge, or click here to open
Using equation we can now compute the total time travelled for the Energy in the range of battery weights

ttravelled = Enew batteries / Pfrom batteries

 Figure 6.39 Click image to enlarge, or click here to open
We now convert the range of ttravelled to distance travelled in km:

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

 Figure 6.40 Click image to enlarge, or click here to open
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

 Figure 6.41 Click image to enlarge, or click here to open
The graph suggests that for an equal amount of additional battery power, the additional distance travelled decreases over time.

 Figure 6.42 Click image to enlarge, or click here to open

### 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.

 Figure 6.43 Click image to enlarge, or click here to open
Next, we define the range of weights for the batteries and velocities:

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

 Figure 6.44 Click image to enlarge, or click here to open
Next, we again define a unit battery of 1kg:

Eunit batteries = Ebatteries total / mbatteries

 Figure 6.45 Click image to enlarge, or click here to open
We initialize the result matrix disttravelled km to an empty matrix:

disttravelled km = [ ]

 Figure 6.46 Click image to enlarge, or click here to open
Similar to exercise_mesh, we place the computation for one of the ranges, vvar, in a for loop:

for v=1:length(vvar)

end

 Figure 6.47 Click image to enlarge, or click here to open
We first compute the total weight of the Segway and range of battery weights.

msegway = msegway nobat + mnew batteries

 Figure 6.48 Click image to enlarge, or click here to open
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.

 Figure 6.49 Click image to enlarge, or click here to open
Using equation we can now compute the total time travelled for the Energy in the range of battery weights

ttravelled = Enew batteries / Pfrom batteries

 Figure 6.50 Click image to enlarge, or click here to open
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

 Figure 6.51 Click image to enlarge, or click here to open
Finally, we plot the resulting matrix disttravelled km over the range of battery weights mnew batteries and velocities vvar:

mesh(mnew batteries, vvar, disttravelled km), xlabel('Weight of batteries in kg'), ylabel('Velocity in km/h'), zlabel('Distance travelled in km');

 Figure 6.52 Click image to enlarge, or click here to open
The resulting graph suggests that with increasing weight of the batteries, the marginal additional distance travelled decreases. This suggests that there is some value (given the problem setup) for which battery weight is most efficient.

 Figure 6.53 Click image to enlarge, or click here to open
On the other hand, the graph also suggests that the lower the velocity at which the Segway travels, the higher the possible total distance travelled. This makes sense, as the lower the velocity, the lower the force required to move the vehicle.

 Figure 6.54 Click image to enlarge, or click here to open