Powertrain Data

The following MATLAB codes define the engine, motor, and battery used in an earlier version of Prius. You will only need the engine data code for problem 1. For problem 2, you will need all data for powertrain components. The entire power management code can be found here. Please be cautious about the units!

Engine data

This function does two things. First, it takes in the engine speed (Weng, rad/s) and engine torque (Teng, Nm), and outputs the fuel consumption (gram per second). Second, it computes the max torque (Tlimit) for a given engine speed (Weng).

function FC = PoP_engine(Weng, Teng)
    rps2rpm = 30/pi;
    deisel_density = 840;   % Diesel fuen density [g/L];
    L2gallon = 0.2642;      % liter->gallon
    eng_description='Prius_jpn 1.5L (43kW) from FA model and ANL test data';
    % Engine Parameters
    y1_fc = [0 0 0.554 0.228 0.138 0.132 0.157 0.19 0.223 0.253 0.281 0.307 0.335 0.365 0.401 0.445 0.499 0.565 0.646 0.742 0.857;% zero engine speed
             0 0 0.654 0.328 0.238 0.232 0.257 0.29 0.323 0.353 0.381 0.407 0.435 0.465 0.501 0.545 0.599 0.665 0.746 0.842 0.957;% idle speed
             0 0 0.667 0.342 0.253 0.249 0.275 0.309 0.343 0.375 0.404 0.432 0.46 0.492 0.53 0.575 0.63 0.697 0.779 0.877 0.993;
             0 0 0.679 0.355 0.268 0.265 0.292 0.327 0.363 0.396 0.426 0.455 0.485 0.518 0.557 0.603 0.659 0.728 0.811 0.91 1.03;
             0 0 0.691 0.368 0.282 0.28 0.308 0.345 0.382 0.416 0.447 0.477 0.509 0.543 0.583 0.63 0.688 0.758 0.842 0.942 1.06;
             0 0 0.701 0.38 0.295 0.294 0.324 0.362 0.4 0.435 0.468 0.499 0.531 0.567 0.608 0.657 0.716 0.787 0.872 0.974 1.09;
             0 0 0.711 0.391 0.307 0.308 0.342 0.38 0.418 0.451 0.483 0.515 0.554 0.59 0.632 0.682 0.742 0.815 0.901 1 1.12;
             0 0 0.721 0.402 0.32 0.321 0.359 0.397 0.436 0.474 0.506 0.538 0.58 0.622 0.656 0.707 0.769 0.842 0.93 1.03 1.16;
             0 0 0.731 0.413 0.331 0.334 0.371 0.413 0.453 0.492 0.528 0.559 0.598 0.649 0.68 0.732 0.794 0.869 0.958 1.06 1.19;
             0 0 0.74 0.423 0.343 0.347 0.383 0.425 0.466 0.508 0.548 0.579 0.617 0.668 0.717 0.756 0.82 0.895 0.985 1.09 1.22;
             0 0 0.749 0.433 0.354 0.359 0.395 0.437 0.478 0.52 0.561 0.597 0.636 0.687 0.738 0.78 0.844 0.921 1.01 1.12 1.25;
             0 0 0.758 0.443 0.366 0.372 0.407 0.448 0.49 0.532 0.577 0.611 0.656 0.708 0.76 0.803 0.869 0.947 1.04 1.15 1.27;
             0 0 0.767 0.453 0.377 0.384 0.419 0.46 0.502 0.546 0.594 0.628 0.676 0.728 0.781 0.832 0.893 0.972 1.07 1.18 1.3;
             0 0 0.776 0.464 0.388 0.396 0.43 0.472 0.516 0.563 0.611 0.648 0.697 0.747 0.8 0.852 0.917 0.997 1.09 1.2 1.33;
             0 0 0.785 0.474 0.399 0.409 0.442 0.485 0.533 0.581 0.628 0.669 0.718 0.767 0.819 0.87 0.941 1.02 1.12 1.23 1.36;
             0 0 0.795 0.484 0.411 0.421 0.455 0.503 0.55 0.598 0.645 0.69 0.738 0.787 0.838 0.89 0.97 1.05 1.14 1.26 1.39;
             0 0 0.804 0.495 0.422 0.424 0.472 0.52 0.567 0.615 0.663 0.712 0.763 0.813 0.864 0.918 0.982 1.07 1.17 1.28 1.41;
             0 0 0.814 0.506 0.434 0.446 0.492 0.54 0.588 0.635 0.684 0.738 0.793 0.847 0.901 0.952 1.02 1.1 1.19 1.31 1.44;
             0 0 0.824 0.517 0.446 0.459 0.523 0.56 0.608 0.655 0.705 0.759 0.813 0.868 0.922 0.978 1.05 1.14 1.22 1.34 1.47;
             0 0 0.834 0.528 0.458 0.473 0.568 0.582 0.628 0.676 0.725 0.78 0.834 0.888 0.945 1 1.07 1.16 1.25 1.36 1.5;
             0 0 0.845 0.54 0.471 0.486 0.532 0.624 0.648 0.696 0.746 0.8 0.855 0.911 0.969 1.03 1.09 1.18 1.27 1.39 1.52;
             0 0 0.856 0.552 0.484 0.5 0.546 0.667 0.682 0.716 0.767 0.821 0.878 0.936 0.994 1.05 1.11 1.2 1.3 1.42 1.55;
             0 0 0.868 0.564 0.497 0.514 0.561 0.721 0.725 0.74 0.787 0.845 0.903 0.961 1.02 1.08 1.13 1.22 1.32 1.44 1.58;
             0 0 0.88 0.577 0.511 0.529 0.577 0.633 0.768 0.783 0.81 0.869 0.927 0.985 1.04 1.1 1.16 1.25 1.35 1.47 1.61;
             0 0 0.892 0.59 0.525 0.544 0.592 0.65 0.81 0.826 0.844 0.89 0.949 1.01 1.07 1.13 1.18 1.27 1.38 1.5 1.64;
             0 0 0.905 0.603 0.539 0.559 0.609 0.667 0.873 0.868 0.884 0.924 0.969 1.03 1.09 1.15 1.21 1.29 1.4 1.52 1.66;
             0 0 0.918 0.618 0.554 0.575 0.625 0.684 0.743 0.911 0.927 0.96 1 1.05 1.11 1.17 1.23 1.31 1.43 1.55 1.69;
             0 0 0.932 0.632 0.569 0.591 0.642 0.702 0.762 0.954 0.969 0.993 1.04 1.08 1.13 1.19 1.26 1.35 1.45 1.58 1.72;
             0 0 0.946 0.647 0.585 0.607 0.66 0.72 0.781 1.02 1.01 1.03 1.08 1.12 1.15 1.21 1.3 1.39 1.47 1.61 1.75;
             0 0 0.961 0.663 0.602 0.625 0.678 0.739 0.8 0.859 1.05 1.07 1.11 1.16 1.19 1.24 1.33 1.42 1.5 1.63 1.78;
             0 0 0.976 0.679 0.619 0.642 0.696 0.758 0.82 0.88 1.1 1.11 1.14 1.19 1.23 1.27 1.35 1.44 1.53 1.66 1.81;
             0 0 0.992 0.696 0.636 0.66 0.715 0.778 0.841 0.901 1.18 1.16 1.18 1.23 1.27 1.31 1.37 1.46 1.56 1.69 1.83;
             0 0 1.01 0.713 0.654 0.679 0.734 0.798 0.861 0.923 0.981 1.2 1.21 1.26 1.31 1.35 1.4 1.48 1.59 1.72 1.86;
             0 0 1.03 0.731 0.673 0.698 0.754 0.818 0.883 0.945 1 1.24 1.26 1.29 1.34 1.39 1.43 1.51 1.62 1.75 1.89;
             0 0 1.04 0.749 0.692 0.718 0.775 0.84 0.905 0.967 1.03 1.33 1.3 1.33 1.38 1.42 1.47 1.53 1.65 1.78 1.92;
             0 0 1.06 0.768 0.711 0.738 0.796 0.861 0.927 0.99 1.05 1.11 1.34 1.36 1.41 1.46 1.5 1.56 1.68 1.81 1.95;
             0 0 1.08 0.788 0.732 0.759 0.817 0.883 0.95 1.01 1.07 1.13 1.39 1.4 1.44 1.49 1.54 1.58 1.72 1.84 1.98;
             0 0 1.1 0.808 0.753 0.781 0.839 0.906 0.973 1.04 1.1 1.16 1.48 1.44 1.47 1.52 1.57 1.62 1.75 1.87 2.01;
             0 0 1.12 0.829 0.774 0.803 0.862 0.93 0.997 1.06 1.12 1.19 1.25 1.49 1.51 1.56 1.61 1.65 1.78 1.9 2.05;
             0 0 1.14 0.851 0.796 0.826 0.885 0.953 1.02 1.09 1.15 1.21 1.27 1.54 1.54 1.59 1.64 1.69 1.81 1.93 2.08;
             0 0 1.16 0.873 0.819 0.849 0.909 0.978 1.05 1.11 1.18 1.24 1.3 1.63 1.59 1.62 1.67 1.72 1.84 1.96 2.11;
             0 0 1.19 0.896 0.842 0.873 0.934 1 1.07 1.14 1.2 1.27 1.33 1.73 1.63 1.66 1.7 1.76 1.87 1.99 2.14;
             0 0 1.21 0.919 0.867 0.898 0.959 1.03 1.1 1.17 1.23 1.29 1.36 1.42 1.69 1.69 1.74 1.79 1.91 2.02 2.17;
             0 0 1.23 0.944 0.891 0.923 0.985 1.05 1.13 1.19 1.26 1.32 1.39 1.45 1.79 1.73 1.77 1.82 1.93 2.07 2.21;
             0 0 1.26 0.969 0.917 0.949 1.01 1.08 1.15 1.22 1.29 1.35 1.42 1.48 1.88 1.77 1.81 1.85 1.96 2.1 2.24;
             0 0 1.28 0.994 0.943 0.976 1.04 1.11 1.18 1.25 1.32 1.38 1.45 1.51 1.59 1.84 1.84 1.89 1.99 2.13 2.27;
             0 0 1.31 1.02 0.97 1 1.07 1.14 1.21 1.28 1.34 1.41 1.48 1.55 1.62 1.94 1.87 1.92 2.02 2.17 2.31;
             0 0 1.34 1.05 0.997 1.03 1.09 1.17 1.24 1.31 1.37 1.44 1.51 1.58 1.65 2.03 1.92 1.96 2.05 2.2 2.34;
             0 0 1.36 1.08 1.03 1.06 1.12 1.2 1.27 1.34 1.41 1.47 1.54 1.61 1.68 1.77 2 1.99 2.09 2.23 2.38;
             0 0 1.39 1.1 1.05 1.09 1.15 1.23 1.3 1.37 1.44 1.5 1.57 1.64 1.72 1.8 2.09 2.02 2.13 2.26 2.41;
             0 0 1.42 1.13 1.08 1.12 1.18 1.26 1.33 1.4 1.47 1.54 1.6 1.67 1.75 1.83 2.19 2.06 2.16 2.3 2.45;
             0 0 1.45 1.16 1.11 1.15 1.21 1.29 1.36 1.43 1.5 1.57 1.64 1.71 1.78 1.87 1.96 2.15 2.2 2.34 2.48;
             0 0 1.48 1.19 1.15 1.18 1.25 1.32 1.39 1.47 1.53 1.6 1.67 1.74 1.82 1.9 2 2.24 2.24 2.37 2.52;
             0 0 1.51 1.23 1.18 1.21 1.28 1.35 1.43 1.5 1.57 1.64 1.7 1.78 1.85 1.94 2.03 2.34 2.27 2.41 2.56;
             0 0 1.54 1.26 1.21 1.25 1.31 1.39 1.46 1.53 1.6 1.67 1.74 1.81 1.89 1.97 2.07 2.18 2.31 2.45 2.59;
             0 0 1.58 1.29 1.24 1.28 1.35 1.42 1.5 1.57 1.64 1.71 1.77 1.85 1.92 2.01 2.11 2.21 2.39 2.49 2.63;
             0 0 1.61 1.32 1.28 1.31 1.38 1.45 1.53 1.6 1.67 1.74 1.81 1.88 1.96 2.05 2.14 2.25 2.49 2.52 2.67;
             0 0 1.64 1.36 1.31 1.35 1.42 1.49 1.57 1.64 1.71 1.78 1.85 1.92 2 2.09 2.18 2.29 2.41 2.56 2.71;
             0 0 1.68 1.39 1.35 1.38 1.45 1.53 1.6 1.68 1.75 1.81 1.88 1.96 2.04 2.12 2.22 2.33 2.45 2.6 2.75;
             0 0 1.71 1.43 1.38 1.42 1.49 1.56 1.64 1.71 1.78 1.85 1.92 2 2.07 2.16 2.26 2.37 2.49 2.64 2.79;
             0 0 1.75 1.47 1.42 1.46 1.53 1.6 1.68 1.75 1.82 1.89 1.96 2.03 2.11 2.2 2.3 2.41 2.53 2.67 2.83;
             0 0 1.79 1.5 1.46 1.5 1.56 1.64 1.72 1.79 1.86 1.93 2 2.07 2.15 2.24 2.34 2.45 2.57 2.71 2.87]; %Fuel consumption map [g/s]
     
    x1_w =[0 104.7 110 115.2 120.4 125.7 130.9 136.1 141.4 ...
           146.6 151.8 157.1 162.3 167.6 172.8 178 183.3 188.5 193.7 199 ...
           204.2 209.4 214.7 219.9 225.1 230.4 235.6 240.9 246.1 251.3 256.6 ...
           261.8 267 272.3 277.5 282.7 288 293.2 298.5 303.7 308.9 314.2 ...
           319.4 324.6 329.9 335.1 340.3 345.6 350.8 356 361.3 366.5 371.8 ...
           377 382.2 387.5 392.7 397.9 403.2 408.4 413.6 418.9];                    % Speed values for the FC map [rad/s]
    x1_t = [-6 0 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100];        % Torque values for the FC map
    y2_tlimit = [75 77.33 78.2 79.07 79.94 80.81 81.68 82.35 82.85 83.35 83.85 ...
                84.35 84.83 85.2 85.58 85.95 86.32 86.7 87.13 87.6 88.08 88.55 ...
                89.02 89.47 89.79 90.11 90.43 90.76 91.08 91.4 91.73 92.05 92.38 ...
                92.7 93.03 93.35 93.67 93.99 94.32 94.64 94.96 95.29 95.61 95.93 ...
                96.26 96.58 96.9 97.22 97.55 97.87 98.19 98.52 98.84 99.17 99.49 ...
                99.81 100.2 100.5 100.9 101.3 101.7 102];                           % Engine torque limit map [Nm] 
    x2_w = [0 104.7 110 115.2 120.4 125.7 130.9 136.1 141.4 ...
                146.6 151.8 157.1 162.3 167.6 172.8 178 183.3 188.5 193.7 199 ...
                204.2 209.4 214.7 219.9 225.1 230.4 235.6 240.9 246.1 251.3 256.6 ...
                261.8 267 272.3 277.5 282.7 288 293.2 298.5 303.7 308.9 314.2 ...
                319.4 324.6 329.9 335.1 340.3 345.6 350.8 356 361.3 366.5 371.8 ...
                377 382.2 387.5 392.7 397.9 403.2 408.4 413.6 418.9];               % Speed values for the torque limit map [rad/s]

    % Internal variables
    Tlimit = interp1(x2_w, y2_tlimit, Weng/rps2rpm);                               % Torque limit [Nm]

    feas = (Teng<=Tlimit);
    FC = interp2(x1_t, x1_w, y1_fc, Teng, Weng/rps2rpm);                     % Fuel consumption [g/s]
    FC(FC<0.1) = 0.1; 
    FC(~feas) = NaN;
end

Motor data

The following code takes in the motor torque, speed, and voltage and outputs the current.

function [Imotor] = PoP_motor(Tmotor, Wmotor, Vmotor)
rps2rpm = 30/pi;
Jmotor = 0.0226;
Mmotor = 56.75;
Mgen = 32.70;
motor_description='PRIUS_JPN 50-kW permanent magnet motor/controller';
motor_eff = 0.95*[...
    0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000,0.2000;...
    0.4600,0.5400,0.5800,0.6000,0.6000,0.6000,0.6100,0.6350,0.6500,0.6600,0.6800,0.6950,0.7000,0.7100,0.7200,0.7200,0.7200,0.7100,0.6800,0.6000,0.4000,0.6000,0.6800,0.7100,0.7200,0.7200,0.7200,0.7100,0.7000,0.6950,0.6800,0.6600,0.6500,0.6350,0.6100,0.6000,0.6000,0.6000,0.5800,0.5400,0.4600;...
    0.6500,0.6600,0.7000,0.7200,0.7420,0.7500,0.7650,0.7800,0.7860,0.8000,0.8040,0.8200,0.8250,0.8270,0.8270,0.8250,0.8220,0.8150,0.7850,0.7200,0.5000,0.7200,0.7850,0.8150,0.8220,0.8250,0.8270,0.8270,0.8250,0.8200,0.8040,0.8000,0.7860,0.7800,0.7650,0.7500,0.7420,0.7200,0.7000,0.6600,0.6500;...
    0.7350,0.7400,0.7690,0.7800,0.7980,0.8090,0.8210,0.8270,0.8400,0.8430,0.8500,0.8550,0.8540,0.8630,0.8650,0.8640,0.8580,0.8480,0.8200,0.7680,0.5300,0.7680,0.8200,0.8480,0.8580,0.8640,0.8650,0.8630,0.8540,0.8550,0.8500,0.8430,0.8400,0.8270,0.8210,0.8090,0.7980,0.7800,0.7690,0.7400,0.7350;...
    0.7940,0.7940,0.8110,0.8200,0.8400,0.8500,0.8690,0.8670,0.8770,0.8780,0.8820,0.8830,0.8810,0.8870,0.8880,0.8860,0.8820,0.8720,0.8590,0.8000,0.6200,0.8000,0.8590,0.8720,0.8820,0.8860,0.8880,0.8870,0.8810,0.8830,0.8820,0.8780,0.8770,0.8670,0.8690,0.8500,0.8400,0.8200,0.8110,0.7940,0.7940;...
    0.8460,0.8460,0.8500,0.8560,0.8680,0.8760,0.8830,0.8880,0.8940,0.8970,0.9010,0.9040,0.9020,0.9070,0.9060,0.9040,0.8960,0.8830,0.8610,0.8100,0.6400,0.8100,0.8610,0.8830,0.8960,0.9040,0.9060,0.9070,0.9020,0.9040,0.9010,0.8970,0.8940,0.8880,0.8830,0.8760,0.8680,0.8560,0.8500,0.8460,0.8460;...
    0.8860,0.8860,0.8860,0.8860,0.8920,0.8970,0.9010,0.9070,0.9080,0.9140,0.9170,0.9200,0.9230,0.9210,0.9180,0.9150,0.9080,0.8970,0.8720,0.8220,0.7000,0.8220,0.8720,0.8970,0.9080,0.9150,0.9180,0.9210,0.9230,0.9200,0.9170,0.9140,0.9080,0.9070,0.9010,0.8970,0.8920,0.8860,0.8860,0.8860,0.8860;...
    0.9130,0.9130,0.9130,0.9130,0.9130,0.9130,0.9120,0.9170,0.9210,0.9270,0.9300,0.9310,0.9310,0.9300,0.9270,0.9240,0.9160,0.9050,0.8800,0.8400,0.7200,0.8400,0.8800,0.9050,0.9160,0.9240,0.9270,0.9300,0.9310,0.9310,0.9300,0.9270,0.9210,0.9170,0.9120,0.9130,0.9130,0.9130,0.9130,0.9130,0.9130;...
    0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9260,0.9320,0.9350,0.9400,0.9400,0.9400,0.9380,0.9360,0.9320,0.9250,0.9120,0.8860,0.8420,0.7500,0.8420,0.8860,0.9120,0.9250,0.9320,0.9360,0.9380,0.9400,0.9400,0.9400,0.9350,0.9320,0.9260,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220;...
    0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9410,0.9440,0.9460,0.9470,0.9480,0.9460,0.9430,0.9360,0.9210,0.9000,0.8590,0.6800,0.8590,0.9000,0.9210,0.9360,0.9430,0.9460,0.9480,0.9470,0.9460,0.9440,0.9410,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380;...
    0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9480,0.9510,0.9520,0.9510,0.9500,0.9470,0.9310,0.9090,0.8520,0.5800,0.8520,0.9090,0.9310,0.9470,0.9500,0.9510,0.9520,0.9510,0.9480,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460,0.9460;...
    0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9450,0.9510,0.9520,0.9480,0.9380,0.9100,0.8600,0.5700,0.8600,0.9100,0.9380,0.9480,0.9520,0.9510,0.9450,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400;...
    0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9450,0.9510,0.9530,0.9480,0.9400,0.9100,0.8500,0.5400,0.8500,0.9100,0.9400,0.9480,0.9530,0.9510,0.9450,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380,0.9380;...
    0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9470,0.9530,0.9500,0.9410,0.9200,0.8700,0.5800,0.8700,0.9200,0.9410,0.9500,0.9530,0.9470,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430,0.9430;...
    0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9500,0.9500,0.9430,0.9250,0.8820,0.6000,0.8820,0.9250,0.9430,0.9500,0.9500,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450;...
    0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9460,0.9400,0.9210,0.8820,0.5600,0.8820,0.9210,0.9400,0.9460,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450,0.9450;...
    0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9430,0.9380,0.9200,0.8800,0.5400,0.8800,0.9200,0.9380,0.9430,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400,0.9400;...
    0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9390,0.9340,0.9170,0.8800,0.5400,0.8800,0.9170,0.9340,0.9390,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370,0.9370;...
    0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9360,0.9320,0.9140,0.8800,0.5600,0.8800,0.9140,0.9320,0.9360,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350;...
    0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9330,0.9200,0.8820,0.6400,0.8820,0.9200,0.9330,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350,0.9350;...
    0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9330,0.9210,0.8830,0.7000,0.8830,0.9210,0.9330,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300,0.9300;...
    0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9290,0.9190,0.8800,0.7200,0.8800,0.9190,0.9290,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270,0.9270;...
    0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9160,0.8700,0.7000,0.8700,0.9160,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260,0.9260;...
    0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9100,0.8640,0.6800,0.8640,0.9100,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230,0.9230;...
    0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9000,0.8400,0.6400,0.8400,0.9000,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220,0.9220];
% % Motor Data Files
y1_tmax = [200,200,200,200,200,194,186,161,142,122,103,90,77.5,70,63.5,58,52,49,45,43,40,37.5,34.3,32.9,31.8];
y2_tmin = -y1_tmax;
% y1_tmax = [319.325555855000,317.805555855000,317.785555855000,317.765555855000,317.745555855000,317.725555855000,317.705555855000,317.685555854000,317.665555855000,317.645555854000,317.625555855000,317.605555855000,317.585555854000,314.146157170000,305.749612370000,295.235193292000,283.964708260000,272.628995200000,261.582240610000,251.000630455000,240.963190182000,231.495095569000,222.591726337000,214.232365136000,206.388124625000,199.026566191000,192.114381515000,185.618922363000,179.509038687000,173.755499909000,168.331165721000,163.211008333000,158.372049125000,153.793248276000,149.455371651000,145.340849212000,141.433634036000,137.719066741000,134.183748191000,130.815421679000,127.602865170000,124.535793041000,121.604767435000,118.801117907000,116.116869515000,113.544677745000,111.077770249000,108.709894454000,106.435270459000,104.248548750000,102.144772023000,100.119341032000,98.1679836001000,96.2867268220000,94.4718718960000,92.7199714130000,91.0278087573000,89.3923794892000,87.8108744493000,86.2806644007000,84.7992861332000,83.3644296708000,81.9739267800000,80.6257403664000,79.3179548964000,78.0487674655000,76.8164798467000,75.6194910662000,74.4562905692000,73.3254520138000,72.2256275114000,71.1555424473000,70.1139905396000,69.0998293681000,68.1119762381000,67.1494043547000];
% y2_tmin = [-319.325555855000,-320.845555855000,-320.865555855000,-320.885555855000,-320.905555854000,-320.925555855000,-320.945555855000,-320.965555855000,-320.985555854000,-321.005555854000,-321.025555855000,-321.045555854000,-321.048422682000,-316.979715389000,-308.954701496000,-299.070374032000,-288.442909904000,-277.682017996000,-267.121812408000,-256.941075746000,-247.229042852000,-238.022717431000,-229.328626777000,-221.135761453000,-213.423378294000,-206.165740909000,-199.335001370000,-192.902937660000,-186.841979947000,-181.125792224000,-175.729575666000,-170.630198621000,-165.806220007000,-161.237848575000,-156.906865345000,-152.796526733000,-148.891459160000,-145.177552143000,-141.641854047000,-138.272472948000,-135.058483682000,-131.989842014000,-129.057305689000,-126.252362412000,-123.567164260000,-120.994468111000,-118.527581986000,-116.160316127000,-113.886938974000,-111.702137410000,-109.600980719000,-107.578887900000,-105.631598493000,-103.755145587000,-101.945831961000,-100.200207918000,-98.5150516454000,-96.8873510225000,-95.3142872063000,-93.7932197690000,-92.3216730234000,-90.8973236253000,-89.5179892182000,-88.1816181514000,-86.8862798749000,-85.6301564285000,-84.4115342804000,-83.2287971767000,-82.0804194149000,-80.9649596144000,-79.8810550590000,-78.8274165126000,-77.8028233178000,-76.8061189405000,-75.8362069775000,-74.8920471877000];
% y3_loss = [1.3611	1.1517	0.9423	0.7329	0.5235	0.3141	0.2094	0.1047	0	0.05	0.1	0.15	0.25	0.36	0.47	0.57	0.65
% 2.04165	1.72755	1.41345	1.09935	0.78525	0.47115	0.3141	0.15705	0	0.15705	0.3141	0.47115	0.78525	1.09935	1.41345	1.72755	2.04165
% 20.4204	17.2788	14.1372	10.9956	7.854	4.7124	3.1416	1.5708	2.0944	1.5708	3.1416	4.7124	7.854	10.9956	14.1372	17.2788	20.4204
% 1041.44	881.217	720.996	560.775	400.553	240.332	160.221	80.1107	106.814	80.1107	160.221	240.332	400.553	560.775	720.996	881.217	1041.44
% 2062.46	1745.16	1427.85	1110.55	793.253	475.952	317.301	158.65	211.534	158.65	317.301	475.952	793.253	1110.55	1427.85	1745.16	2062.46
% 3083.47	2609.09	2134.71	1660.33	1185.95	711.571	474.38	237.19	316.254	237.19	474.38	711.571	1185.95	1660.33	2134.71	2609.09	3083.47
% 4104.49	3473.03	2841.57	2210.11	1578.65	947.19	631.46	315.73	420.973	315.73	631.46	947.19	1578.65	2210.11	2841.57	3473.03	4104.49
% 5125.51	4336.97	3548.43	2759.89	1971.35	1182.81	788.54	394.27	525.693	394.27	788.54	1182.81	1971.35	2759.89	3548.43	4336.97	5125.51
% 6146.53	5200.91	4255.29	3309.67	2364.05	1418.43	945.62	472.81	630.413	472.81	945.62	1418.43	2364.05	3309.67	4255.29	5200.91	6146.53
% 7167.54	6064.84	4962.15	3859.45	2756.75	1654.05	1102.7	551.349	735.133	551.349	1102.7	1654.05	2756.75	3859.45	4962.15	6064.84	7167.54
% 8188.56	6928.78	5669	4409.23	3149.45	1889.67	1259.78	629.889	839.852	629.889	1259.78	1889.67	3149.45	4409.23	5669	6928.78	8188.56
% 9209.58	7792.72	6375.86	4959	3542.15	2125.29	1416.86	708.429	944.572	708.429	1416.86	2125.29	3542.15	4959	6375.86	7792.72	9209.58
% 10230.6	8656.66	7082.72	5508.78	3934.84	2360.91	1573.94	786.969	1049.29	786.969	1573.94	2360.91	3934.84	5508.78	7082.72	8656.66	10230.6
% 11251.6	9520.6	7789.58	6058.56	4327.54	2596.53	1731.02	865.509	1154.01	865.509	1731.02	2596.53	4327.54	6058.56	7789.58	9520.6	11251.6
% 12272.6	10384.5	8496.44	6608.34	4720.24	2832.15	1888.1	944.049	1258.73	944.049	1888.1	2832.15	4720.24	6608.34	8496.44	10384.5	12272.6
% 13293.6	11248.5	9203.3	7158.12	5112.94	3067.77	2045.18	1022.59	1363.45	1022.59	2045.18	3067.77	5112.94	7158.12	9203.3	11248.5	13293.6
% 14334	12130	9924	7718	5514	3308	2206	1102	1470	1102	2206	3308	5514	7718	9924	12130	14334
% 16376	13858	11338	8818	6298	3780	2520	1260	1680	1260	2520	3780	6298	8818	11338	13858	16376
% 18420	15586	12752	9918	7084	4250	2834	1416	1888	1416	2834	4250	7084	9918	12752	15586	18420];
x1_w = 0:500:12000;
x2_w = x1_w;
x3_w = x1_w;
x3_t = -200:10:200;
% y3_loss = (1-motor_eff).*(x3_w'*x3_t)/rps2rpm;
% Internal Variables
Tmax = interp1(x1_w, y1_tmax, abs(Wmotor), 'linear', 'extrap');
Tmin = interp1(x2_w, y2_tmin, abs(Wmotor), 'linear', 'extrap');

Eff = zeros(1,length(Wmotor))*NaN;
% Loss(Wmotor<=7500) = interpextrap2(x3_t,x3_w,y3_loss, Tmotor, Wmotor);
% Imotor = zeros(1,length(Wmotor))*NaN;
feas = (Tmotor<=Tmax)&(Tmotor>=Tmin)&(abs(Wmotor)<=12000);
% Tmotor = Tmotor.*(Tmotor<Tmax&Tmotor>Tmin) + Tmax.*(Tmotor>=Tmax) + Tmin.*(Tmotor<=Tmin);

Eff(feas) = interp2(x3_t,x3_w,motor_eff, Tmotor(feas), abs(Wmotor(feas)), 'linear', 0.1);

Loss_m = (1./Eff - 1).*Tmotor.*Wmotor/rps2rpm;
Loss_g = (Eff-1).*Tmotor.*Wmotor/rps2rpm;
Pmot = Tmotor.*Wmotor;

Loss = Loss_m.*(Pmot>0)+Loss_g.*(Pmot<=0);

% Imotor(feas) = -(Tmotor(feas).*Wmotor(feas)/rps2rpm+Loss(feas))/Vmotor;
Imotor = -(Tmotor.*Wmotor/rps2rpm+Loss)/Vmotor;
% % % % if (Tmotor<=Tmax && Tmotor >=Tmin) && (Wmotor <=9000)
% % % %     % Output Calculations
% % % %     Loss = interpextrap2(x3_t,x3_w,y3_loss, Tmotor, Wmotor);   
% % % %     Imotor = -(Tmotor*Wmotor/rps2rpm+Loss)/Vmotor;
% % % % else
% % % %     Imotor = NaN;
% % % % end
end

Battery code

The following code computes the battery power for the given battery voltage and current.

function [Pbatt] = PoP_battery(Vbatt, Ibatt)
% % Battery Parameters
% Sbank = 6;              % # of banks in series 
% Ncell = 40;             % # of cell in series
% Pbank = 1;              % # of banks in parallel
% Rcell = 0.00051;
% Rint = Rcell*Ncell*Sbank/Pbank;
eta_batt = 0.92;
Pbatt = (Ibatt*Vbatt.*eta_batt.^(-sign(Ibatt)));
% Pbatt = Vbatt*Ibatt+Ibatt.^2*Rint;
end